Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
754 bytes
|
Line | |
---|
1 | var 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 | */
|
---|
22 | function 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 |
|
---|
29 | module.exports = replace;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.