@ln-maf/filltemplate

1.0.8 • Public • Published

Fill template

Fills the template literals similar to how js would handle them. Allows use of template literal in a string. There are a couple of key differences with how they are processed by fillTemplate.

Installation

Install it with

npm i @ln-maf/filltemplate

Usage

var fillTemplate=require('fillTemplate')
fillTemplate.fillTemplate("Hello ${name}", { name: "World" })
var jsonObj={ hello: "${name}" }
fillTemplate.applyTemplateToJSON(jsonObj, { name: "World" })
console.log(jsonObj)

For example:

fillTemplate("Hello ${name}", { name: "World" })

Would return:

Hello world

Additionally supports the method applyTemplateToJSON This iterates through the entire json object applying filter to each of them.

For Example:

var jsonObj={ hello: "${name}" }
applyTemplateToJSON(jsonObj, { name: "World" })

Would apply:

{
  "hello" : "World"
}

to the jsonObj.

Differences

All "${JS_COMMAND_HERE}" are replaced with ${JSON.stringify(command)}. This automatically escapes some characters to prevent invalid json within json files.

The items are evaled on within each bracket. You can see some of the examples within the features subfolder of this project.

Readme

Keywords

none

Package Sidebar

Install

npm i @ln-maf/filltemplate

Weekly Downloads

0

Version

1.0.8

License

Apache-2.0

Unpacked Size

18.6 kB

Total Files

8

Last publish

Collaborators

  • martdo02
  • ejezisek