Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixcai/es6-template-string
Easy and small template engine for the browser and nodejs
https://github.com/pixcai/es6-template-string
Last synced: 26 days ago
JSON representation
Easy and small template engine for the browser and nodejs
- Host: GitHub
- URL: https://github.com/pixcai/es6-template-string
- Owner: pixcai
- License: mit
- Created: 2016-08-30T10:34:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-10T03:48:37.000Z (about 4 years ago)
- Last Synced: 2024-10-08T10:21:51.076Z (29 days ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# es6-template-string
Easy and small template engine for the browser and nodejs[![npm](https://img.shields.io/npm/v/es6-template-string.svg?style=flat-square)](https://www.npmjs.com/package/es6-template-string)
[![npm](https://img.shields.io/npm/dt/es6-template-string.svg?style=flat-square)](https://www.npmjs.com/package/es6-template-string)
[![npm](https://img.shields.io/npm/l/es6-template-string.svg?style=flat-square)](https://www.npmjs.com/package/es6-template-string)# Install
```shell
npm install --save es6-template-string
```# API
### render(str[, locals])
Render template `str` with variable `locals`Example:
```js
var template = require('es6-template-string');template.render('Node Version: ${ process.version }');
// It equals to
template('Node Version: ${ process.version }');
```### compile(str)
Compile `str` and return a function that accept one parameters: `locals`Example:
```js
var template = require('es6-template-string');var logNodeVersion = template.compile('Node Version: ${ process.version }');
logNodeVersion();
```# Usage
```js
var template = require('es6-template-string');// This is hello, world
template('This is ${vars}', {vars: 'hello, world'});// This is 3
template('This is ${m + n}', {m: 1, n: 2});
// or
var m = 1, n = 2;
template('This is ${m + n}');var plus = template.compile('This is ${m + n}');
// This is 5
plus({m: 1, n: 4});
```# License
MIT