https://github.com/blond/detemplate
:bookmark: Parse string by template
https://github.com/blond/detemplate
Last synced: over 1 year ago
JSON representation
:bookmark: Parse string by template
- Host: GitHub
- URL: https://github.com/blond/detemplate
- Owner: blond
- License: mit
- Created: 2016-09-25T16:08:47.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-25T16:12:12.000Z (almost 10 years ago)
- Last Synced: 2025-02-14T21:31:20.633Z (over 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
detemplate
==========
[![NPM Status][npm-img]][npm]
[![Travis Status][test-img]][travis]
[![Coverage Status][coverage-img]][coveralls]
[![Dependency Status][david-img]][david]
[npm]: https://www.npmjs.org/package/detemplate
[npm-img]: https://img.shields.io/npm/v/detemplate.svg
[travis]: https://travis-ci.org/blond/detemplate
[test-img]: https://img.shields.io/travis/blond/detemplate.svg?label=tests
[coveralls]: https://coveralls.io/r/blond/detemplate
[coverage-img]: https://img.shields.io/coveralls/blond/detemplate.svg
[david]: https://david-dm.org/blond/detemplate
[david-img]: http://img.shields.io/david/blond/detemplate.svg?style=flat
Parse string by template.
Install
-------
```
$ npm install --save detemplate
```
Usage
-----
```js
const detemplate = require('detemplate');
const template = '${name} ${middlename} «${nickname}» ${surname}';
const parseNames = detemplate.compile(template);
parseNames('Bartholomew Jo-Jo «Bart» Simpson');
// Ay, caramba! Eat my shorts!
//
// ➜ {
// name: 'Bartholomew',
// surname: 'Simpson',
// middlename: 'Jo-Jo',
// nickname: 'Bart'
// }
```
API
---
### compile(template)
Creates a compiled function that can extract data properties from place holders (ES template literal delimiters).
### template
Type: `string`
The string that contains place holders (ES template literal delimiters). These are indicated by the Dollar sign and curly braces (`${placeHolder}`).
License
-------
MIT © [Andrew Abramov](https://github.com/blond)