source: node_modules/ramda-adjunct/es/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';
2import isFunction from './isFunction';
3import ponyfill from './internal/ponyfills/String.replaceAll';
4export var replaceAllPonyfill = curryN(3, ponyfill);
5export 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 */
28var replaceAll = isFunction(String.prototype.replaceAll) ? replaceAllInvoker : replaceAllPonyfill;
29export default replaceAll;
Note: See TracBrowser for help on using the repository browser.