simple-recursive-string-slot-template-pmb

0.1.2 • Public • Published

simple-recursive-string-slot-template-pmb

In your template string, replace all slot (marked by a custom regexp) with string values from your dictionary object, even recursively, but avoiding loops.

API

This module exports one function:

simpleRecursiveTemplate(tpl, rgx, dict)

  • tpl is your initial template string.
  • rgx is a slot marker regexp. The slot name is what the regexp matches as group 1. If you want to match a different group, assign its number to the .slot property of your regexp. (You cannot use slot 0. Just add parens around your entire regexp.)
    • Usually you want your regexp to have the g flag.
    • The empty string is not a valid slot name.
  • dict is an object that maps slot names to string values. The latter may be partial templates, i.e. contain further slot markers.

Usage

see test/usage.mjs

Known issues

  • Needs more/better tests and docs.

 

License

ISC

Dependencies (0)

    Dev Dependencies (8)

    Package Sidebar

    Install

    npm i simple-recursive-string-slot-template-pmb

    Weekly Downloads

    2

    Version

    0.1.2

    License

    ISC

    Unpacked Size

    8.24 kB

    Total Files

    7

    Last publish

    Collaborators

    • mk-pmb