String template and interpolation utility
npm i go-template-fn
or
yarn add go-template-fn
import template from 'go-template-fn'
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
const template = require('go-template-fn');
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
<script src="dist/go-template-fn.min.js"></script>
<script>
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
</script>
Creates a compiled template function that can interpolate values into placeholders in the template.
strTemplate
string The string template to compile.
options
Object? The compilation options.
options.startTag
string? The start tag for a placeholder.options.endTag
string? The end tag for a placeholder.var greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
Custom tags
var greet = template("Hello, <%name%>", {startTag: "<%", endTag: "%>"});
greet({name: "John"}); // => Hello, John
Returns Function The compiled template function.
Meta
Author: koyote130708
Source Code: https://github.com/koyote130708/go-template-fn
License: LGPL-3.0 license