Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/herber/twz
🧙 Magic templates
https://github.com/herber/twz
magic template template-engine
Last synced: 2 days ago
JSON representation
🧙 Magic templates
- Host: GitHub
- URL: https://github.com/herber/twz
- Owner: herber
- License: mit
- Created: 2018-01-28T13:55:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-02-25T09:23:06.000Z (over 6 years ago)
- Last Synced: 2024-08-31T14:39:09.312Z (about 1 month ago)
- Topics: magic, template, template-engine
- Language: JavaScript
- Size: 7.81 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Twz [![Build Status](https://travis-ci.org/herber/twz.svg?branch=master)](https://travis-ci.org/herber/twz) [![codecov](https://codecov.io/gh/herber/twz/badge.svg?branch=master)](https://codecov.io/gh/herber/twz?branch=master)
> 🧙 Magic templates
## Features
- Tiny at just 23 loc
- Based on tagged template literals## Install
```
$ npm install twz
```## Usage
```js
const twz = require('twz');twz('
${ emoji }
')({ emoji: '🧙' });
```## Examples
### List
```js
const twz = require('twz');const listTemplate = '
- ${ list.map(n => `
- ${n} `).join('')
twz(listTemplate)({ list: [ '1', '2', '3' ] });
// =>
- 1
- 2
- 3
```
### Heading
```js
const twz = require('twz');
twz('
${ name }
')({ 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](http://tobihrbr.com)