• A default string replace function with the default options.

    Parameters

    • template: string

      the string template

    • Optional values: Record<string, any> | ValueResolver

      record of values or a lookup function

    Returns string

    a string with all ${key} expressions replaced by matching values in valueLookup.

    Example

    Replace ${key} using object as key to value mapping

    import {replace} from "apprt-core/string-replace";

    let msg = replace("${name} says ${msg}", { msg: "hello" });
    msg === "${name} says hello"; // true

    Example

    Replacing ${key} using custom value lookup function

    import {replace} from "apprt-core/string-replace";

    let msg = replace("${name} says ${msg}", (key) => key === "msg" ? "hello" : "");
    msg === " says hello"; // true

Generated using TypeDoc