UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

30 lines (29 loc) 790 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replace = void 0; /** * Replaces matches for `pattern` in `string` with `replacement`. * * **Note:** This method is based on * [`String#replace`](https://mdn.io/String/replace). * * @since 5.8.0 * @category String * @param string The string to modify. * @param pattern The pattern to replace. * @param replacement The match replacement. * @returns Returns the modified string. * @see [[truncate]], [[trim]] * @example * * ```js * replace('Hi Fred', 'Fred', 'Barney') * // => 'Hi Barney' * ``` */ function replace(...args) { const string = `${args[0]}`; return args.length < 3 ? string : string.replace(args[1], args[2]); } exports.replace = replace; exports.default = replace;