pnpm add -D templette
yarn add --dev templette
npx i -D templette
// es modules
import Templette from 'templette';
// commonjs
const Templette = require('templette');
const t = new Templette();
// or
const t = new Templette('Hello {{name}}!');
// when you've defined the template in the constructor
t.render({name: 'nberlette'});
// to define the template on the fly
t.compile('Hello {{name}}!', {name: 'nberlette'});
Templette.compile('Hello {{name}}!', {name: 'nberlette'});
Templette's main compile method, powered by JavaScript's powerful builtin RegExp engine.
Type: global function
Params
- template
Template
- the raw template string we want to compile - values
Values
- substitutions to make, either as a generic list (for numbered keys), or as a map-style object to replace named keys or deep (dot-notation) paths.
Returns: string
Templette.compile('Hello {{name}}!', {name: 'Nick'});
// Hello Nick!
Cleanup a template string and remove some inconsistencies.
Kind: global function Returns: string
- formatted and normalized template string Params
- template
string
- raw unformatted template string - [substitutions]
Record.<string, unknown>
- optional map of substitutions to make: each property name is the search pattern or string, and its value is the replacement string or function.
Templette's main compile method, powered by JavaScript's powerful builtin RegExp engine.
Type: global function
Params:
- template
Template
- the raw template string we want to compile - values
Values
- substitutions to make, either as a generic list (for numbered keys), or as a map-style object to replace named keys or deep (dot-notation) paths.
Templette.compile('Hello {{name}}!', {name: 'Nick'});
// Hello Nick!
Render the template with provided values.
Type: global function
Params:
- values
Values
- substitutions to make, either as a generic list (for numbered keys), or as a map-style object to replace named keys or deep (dot-notation) paths.
MIT © Nicholas Berlette · inspired by @lukeed/templite