UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

24 lines (22 loc) 665 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/string/replace.ts /** * `replace(target, search, replace)` * * Replaces the first occurrence of `search` string or regular expression in `target` string with `replace` string. * * ```ts * replace("hello world", "world", "universe"); // "hello universe" * replace("hello world", /o/g, "0"); // "hell0 w0rld" * ``` * * ```ts * pipe("hello world", replace("world", "universe")); // "hello universe" * pipe("hello world", replace(/o/g, "0")); // "hell0 w0rld" * ``` */ const replace = dfdlT((target, search, replacement) => { return target.replace(search, replacement); }, 3); //#endregion export { replace };