1.0.0 • Published 4 years ago

tplv v1.0.0

Weekly downloads
5
License
MIT
Repository
-
Last release
4 years ago

TPLV

Nano(~170b), High performance string template library, based on ES6 String template syntax.

npm Version Build Status Coverage Status npm License

Install

$ npm i --save tplv

Usage

  • render template string
import { render } from 'tplv';

const template = '${ name }, ${value}(${percent} | Top ${array[2]})';

const data = {
  name: 'Hangzhou',
  value: 1200,
  percent: '13%',
  array: [1, 2, 3, 4]
};

render(template, data); // `Hangzhou, 1200(13% | Top 3)` will be got
  • compile mode

For 13x faster performance then render mode.

import { compile } from 'tplv';

const template = '${ name }, ${value}(${percent} | Top ${array[2]})';

const data = {
  name: 'Hangzhou',
  value: 1200,
  percent: '13%',
  array: [1, 2, 3, 4]
};

const fn = compile(template, ['name', 'value', 'percent', 'array']);

fn(data); // `Hangzhou, 1200(13% | Top 3)` will be got

Perf

Run performance test with rendering-test.

perf test

Dev

# install dependence
$ npm install

# run test cases
$ npm run test

# run performance for render / compile mode
$ npm run perf

# build package
$ npm run build

License

MIT@hustcc.

1.0.0

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.1-beta.1

4 years ago