The Wayback Machine - https://web.archive.org/web/20170626182736/https://github.com/lodash/lodash/blob/master/replace.js
Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (23 sloc) 683 Bytes
/**
* Replaces matches for `pattern` in `string` with `replacement`.
*
* **Note:** This method is based on
* [`String#replace`](https://mdn.io/String/replace).
*
* @since 4.0.0
* @category String
* @param {string} [string=''] The string to modify.
* @param {RegExp|string} pattern The pattern to replace.
* @param {Function|string} replacement The match replacement.
* @returns {string} Returns the modified string.
* @see truncate, trim
* @example
*
* 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])
}
export default replace
You can't perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.