1.1.3 • Published 4 years ago

ut-function.interpolate v1.1.3

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
4 years ago

ut-function.interpolate

function signature:

interpolate(what, params, inline, matcher)

  • what required - what to be interpolated string, object or array
  • params required - interpolation data source
  • inline optional (default true) - whether the interpolation to be inline or not. E.g. {x} with params {x: true} will become "true" if inline or true otherwise
  • matcher 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}}]