Skip to content

herber/twz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twz Build Status codecov

🧙 Magic templates

Features

  • Tiny at just 23 loc
  • Based on tagged template literals

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

Releases

No releases published

Packages

No packages published