source: node_modules/ramda-adjunct/src/replaceAll.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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