A default string replace function with the default options.

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

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

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

Replacing ${key} using custom value lookup function

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

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

    • template: string

      the string template

    • Optionalvalues: 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.