function signature:
interpolate(what, params, inline, matcher)
what
[required] - what to be interpolatedstring
,object
orarray
params
[required] - interpolation data sourceinline
[optional] (default true) - whether the interpolation to be inline or not. E.g.{x}
with params{x: true}
will become"true"
if inline ortrue
otherwisematcher
[optional] (default/{([^}]+)}/g
) - the interpolation matcher
Examples:
const result = interpolate("x {y} z", {"y":"y"});
// result = "x y z"
const result = interpolate("x {y} z", {});
// result = "x {y} z"
const result = interpolate("x {y.y} z", {"y":{"y":"y"}});
// result = "x y z"
const result = interpolate("x {{y}} z", {"y":"y"}, true, /{{([^}]+)}}/g);
// result = "x y z"
const result = interpolate("{x}", {"x":true}, false);
// result = true
const result = interpolate("{x}", {}, false);
// result = "{x}"
const result = interpolate("{x.y}", {"x":{"y":{"z":true}}}, false);
// result = {"z":true}
const result = interpolate({"x":{"y":"x {y} z"}}, {"y":"y"});
// result = {"x":{"y":"x y z"}}
const result = interpolate([{"x":{"y":"x {y} z"}}], {"y":"y"});
// result = [{"x":{"y":"x y z"}}]
const result = interpolate({"x":{"y":"{y}"}}, {"y":true}, false);
// result = {"x":{"y":true}}
const result = interpolate([{"x":{"y":"{y}"}}], {"y":true}, false);
// result = [{"x":{"y":true}}]