Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / replace.js
1 var toString = require('./toString');
2
3 /**
4  * Replaces matches for `pattern` in `string` with `replacement`.
5  *
6  * **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace).
7  *
8  * @static
9  * @memberOf _
10  * @category String
11  * @param {string} [string=''] The string to modify.
12  * @param {RegExp|string} pattern The pattern to replace.
13  * @param {Function|string} replacement The match replacement.
14  * @returns {string} Returns the modified string.
15  * @example
16  *
17  * _.replace('Hi Fred', 'Fred', 'Barney');
18  * // => 'Hi Barney'
19  */
20 function replace() {
21   var args = arguments,
22       string = toString(args[0]);
23
24   return args.length < 3 ? string : string.replace(args[1], args[2]);
25 }
26
27 module.exports = replace;