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.
38 lines (32 loc) • 1.45 kB
JavaScript
;
exports.__esModule = true;
exports["default"] = void 0;
var _ramda = require("ramda");
var _isRegExp = _interopRequireDefault(require("./isRegExp"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* 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 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 {Error} When `searchValue` is RegExp
* @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'
*/
var replaceAll = (0, _ramda.curryN)(3, function (searchValue, replaceValue, str) {
if ((0, _isRegExp["default"])(searchValue)) {
throw new Error('searchValue must be a String, not a RegExp.');
}
return (0, _ramda.pipe)((0, _ramda.split)(String(searchValue)), (0, _ramda.join)(String(replaceValue)))(str);
});
var _default = replaceAll;
exports["default"] = _default;