Go Template
String template and interpolation utility
- version: 1.0.0
- license: GNU LGPLv3
Installation
npm i go-template-fn
or
yarn add go-template-fn
Usage
ES6
import template from 'go-template-fn'
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
Node
const template = require('go-template-fn');
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
Web browser
<script src="dist/go-template-fn.min.js"></script>
<script>
const greet = template("Hello, ${name}");
greet({name: "John"}); // => Hello, John
</script>
Documentation
Table of Contents
template
Creates a compiled template function that can interpolate values into placeholders in the template.
Parameters
Examples
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
- since: 1.0.0