1 | import { curryN, invoker } from 'ramda';
|
---|
2 | import isFunction from './isFunction';
|
---|
3 | import ponyfill from './internal/ponyfills/String.replaceAll';
|
---|
4 | export var replaceAllPonyfill = curryN(3, ponyfill);
|
---|
5 | export var replaceAllInvoker = invoker(2, 'replaceAll');
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Replaces all substring matches in a string with a replacement.
|
---|
9 | *
|
---|
10 | * @func replaceAll
|
---|
11 | * @memberOf RA
|
---|
12 | * @since {@link https://char0n.github.io/ramda-adjunct/2.17.0|v2.17.0}
|
---|
13 | * @category String
|
---|
14 | * @sig String -> String -> String -> String
|
---|
15 | * @param {string} searchValue The substring or a global RegExp to match
|
---|
16 | * @param {string} replaceValue The string to replace the matches with
|
---|
17 | * @param {string} str The String to do the search and replacement in
|
---|
18 | * @return {string} A new string containing all the `searchValue` replaced with the `replaceValue`
|
---|
19 | * @throws {TypeError} When invalid arguments provided
|
---|
20 | * @see {@link http://ramdajs.com/docs/#replace|R.replace}, {@link https://github.com/tc39/proposal-string-replaceall|TC39 proposal}
|
---|
21 | * @example
|
---|
22 | *
|
---|
23 | * RA.replaceAll('ac', 'ef', 'ac ab ac ab'); //=> 'ef ab ef ab'
|
---|
24 | * RA.replaceAll('', '_', 'xxx'); //=> '_x_x_x_'
|
---|
25 | * RA.replaceAll(/x/g, 'v', 'xxx'); //=> 'vvv'
|
---|
26 | * RA.replaceAll(/x/, 'v', 'xxx'); //=> TypeError
|
---|
27 | */
|
---|
28 | var replaceAll = isFunction(String.prototype.replaceAll) ? replaceAllInvoker : replaceAllPonyfill;
|
---|
29 | export default replaceAll; |
---|