@monstermann/fn
Version:
A utility library for TypeScript.
24 lines (22 loc) • 717 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/string/replaceAll.ts
/**
* `replaceAll(target, search, replace)`
*
* Replaces all occurrences of `search` string or regular expression in `target` string with `replace` string.
*
* ```ts
* replaceAll("hello world world", "world", "universe"); // "hello universe universe"
* replaceAll("hello world", /o/g, "0"); // "hell0 w0rld"
* ```
*
* ```ts
* pipe("hello world world", replaceAll("world", "universe")); // "hello universe universe"
* pipe("hello world", replaceAll(/o/g, "0")); // "hell0 w0rld"
* ```
*/
const replaceAll = dfdlT((target, search, replacement) => {
return target.replaceAll(search, replacement);
}, 3);
//#endregion
export { replaceAll };