UNPKG

1.09 kBJavaScriptView Raw
1import _curry3 from "./internal/_curry3.js";
2/**
3 * Replace a substring or regex match in a string with a replacement.
4 *
5 * The first two parameters correspond to the parameters of the
6 * `String.prototype.replace()` function, so the second parameter can also be a
7 * function.
8 *
9 * @func
10 * @memberOf R
11 * @since v0.7.0
12 * @category String
13 * @sig RegExp|String -> String -> String -> String
14 * @param {RegExp|String} pattern A regular expression or a substring to match.
15 * @param {String} replacement The string to replace the matches with.
16 * @param {String} str The String to do the search and replacement in.
17 * @return {String} The result.
18 * @example
19 *
20 * R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
21 * R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'
22 *
23 * // Use the "g" (global) flag to replace all occurrences:
24 * R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'
25 */
26
27var replace =
28/*#__PURE__*/
29_curry3(function replace(regex, replacement, str) {
30 return str.replace(regex, replacement);
31});
32
33export default replace;
\No newline at end of file