String template and interpolation utility
npm install go-template-fnString template and interpolation utility
!codecov.io Code Coverage


* version: 1.1.0
* license: GNU LGPLv3
``javascript`
npm i go-template-fn
or
`javascript`
yarn add go-template-fn
`javascript
import template from 'go-template-fn'
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
`
`javascript
const template = require('go-template-fn');
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
`
`javascript
`
#### Table of Contents
* template
* Parameters
* Examples
Creates a compiled template function that can interpolate values into placeholders in the template.
#### Parameters
* strTemplate string The string template to compile.options
* Object? The compilation options.
* options.startTag string The start tag for a placeholder. (optional, default "${")options.endTag
* string The end tag for a placeholder. (optional, default "}")options.returnAsFragments
* boolean If true, returns the output as an array of fragments; if false, joins the fragments and returns as a concatenated string. (optional, default false)
#### Examples
`javascript
const greet = template("Hello, ${name}");
greet({ name: "John" }); // => Hello, John
`
Custom tags
`javascript
const greet = template("Hello, <%name%>", {startTag: "<%", endTag: "%>"});
greet({ name: "John" }); // => Hello, John
`
Returning the result as a fragments array
`javascript``
const greet = template("Hello, ${name}! You've turned ${age} today.", { returnAsFragments: true });
greet({ name: "John", age: 20 }); // => ["Hello, ", "John", "! You've turned ", 20, " today."]
Returns Function The compiled template function.
Meta
* since: 1.0.0