0.0.0 • Published 1 year ago

template-conv v0.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

template-conv

Convert simple templates.

import convertTemplate from "template-conv";
const result = "hello world!";
const tests = [
  ["hello $0!", "world"],
  ["hello $0$1", ["world", "!"]],
  [
    "$111 $1$11",
    {
      $111: "hello",
      $1: "world",
      $11: "!",
    },
  ],
  [
    (a) => {
      const world = a.$0 === "hello" ? "world" : "";
      return `$0 ${world}!`;
    },
    "hello",
  ],
];
tests.map(([template, args]) => {
  console.assert(convertTemplate(template, args) === result);
});