ramda-adjunct
Version:
Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
42 lines (35 loc) • 1.79 kB
JavaScript
exports.__esModule = true;
exports["default"] = exports.replaceAllInvoker = exports.replaceAllPolyfill = void 0;
var _ramda = require("ramda");
var _isFunction = _interopRequireDefault(require("./isFunction"));
var _String = _interopRequireDefault(require("./internal/polyfills/String.replaceAll"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var replaceAllPolyfill = (0, _ramda.curryN)(3, _String["default"]);
exports.replaceAllPolyfill = replaceAllPolyfill;
var replaceAllInvoker = (0, _ramda.invoker)(2, 'replaceAll');
/**
* Replaces all substring matches in a string with a replacement.
*
* @func replaceAll
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.17.0|v2.17.0}
* @category String
* @sig String -> String -> String -> String
* @param {string} searchValue The substring or a global RegExp to match
* @param {string} replaceValue The string to replace the matches with
* @param {string} str The String to do the search and replacement in
* @return {string} A new string containing all the `searchValue` replaced with the `replaceValue`
* @throws {TypeError} When invalid arguments provided
* @see {@link http://ramdajs.com/docs/#replace|R.replace}, {@link https://github.com/tc39/proposal-string-replaceall|TC39 proposal}
* @example
*
* RA.replaceAll('ac', 'ef', 'ac ab ac ab'); //=> 'ef ab ef ab'
* RA.replaceAll('', '_', 'xxx'); //=> '_x_x_x_'
* RA.replaceAll(/x/g, 'v', 'xxx'); //=> 'vvv'
* RA.replaceAll(/x/, 'v', 'xxx'); //=> TypeError
*/
exports.replaceAllInvoker = replaceAllInvoker;
var replaceAll = (0, _isFunction["default"])(String.prototype.replaceAll) ? replaceAllInvoker : replaceAllPolyfill;
var _default = replaceAll;
exports["default"] = _default;
;