1.1.0 • Published 6 years ago
twz v1.1.0
Twz
🧙 Magic templates
Features
- Tiny at just 23 loc
- Based on template strings
Install
$ npm install twz
Usage
const twz = require('twz');
twz('<h1>${ emoji }</h1>')({ emoji: '🧙' });
Examples
List
const twz = require('twz');
const listTemplate = '<ul>${ list.map(n => `<li>${n}</li>`).join('')</ul>';
twz(listTemplate)({ list: [ '1', '2', '3' ] });
// => <ul><li>1</li><li>2</li><li>3</li></ul>
Heading
const twz = require('twz');
twz('<h1>${ name }</h1>')({ name: 'my name' });
API
twz(input)(data)
Returns the rendered template string
.
input
Type: string
A twz string.
data
Type: object
An object representing the template's data.
twz.file(path)(data)
Returns a promise
path
Type: string
The template's path.
data
Type: object
An object representing the template's data.
twz.fileSync(path)(data)
Returns the rendered template string
.
path
Type: string
The template's path.
data
Type: object
An object representing the template's data.
License
MIT © Tobias Herber