PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/replace.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 29 lines | 7 code | 3 blank | 19 comment | 0 complexity | 696742dc1ba713d818f5b87aa88966da MD5 | raw file
 1var toString = require('./toString');
 2
 3/**
 4 * Replaces matches for `pattern` in `string` with `replacement`.
 5 *
 6 * **Note:** This method is based on
 7 * [`String#replace`](https://mdn.io/String/replace).
 8 *
 9 * @static
10 * @memberOf _
11 * @since 4.0.0
12 * @category String
13 * @param {string} [string=''] The string to modify.
14 * @param {RegExp|string} pattern The pattern to replace.
15 * @param {Function|string} replacement The match replacement.
16 * @returns {string} Returns the modified string.
17 * @example
18 *
19 * _.replace('Hi Fred', 'Fred', 'Barney');
20 * // => 'Hi Barney'
21 */
22function replace() {
23  var args = arguments,
24      string = toString(args[0]);
25
26  return args.length < 3 ? string : string.replace(args[1], args[2]);
27}
28
29module.exports = replace;