https://github.com/bredele/supplant
Variable substitution on string
https://github.com/bredele/supplant
Last synced: 5 months ago
JSON representation
Variable substitution on string
- Host: GitHub
- URL: https://github.com/bredele/supplant
- Owner: bredele
- Created: 2013-08-25T21:07:36.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-04-18T03:35:00.000Z (over 12 years ago)
- Last Synced: 2026-02-27T21:42:07.123Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 402 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
Supplant
=============
[](https://travis-ci.org/bredele/supplant)
Variable substitution/interpolation on string. Look for expressions enclosed in {{ }} braces and substitutes its value with data.
Built for **[brick](http://github.com/bredele/brick)** and **[datastore](http://github.com/bredele/datastore)**. Supplant is agnostic and can be used as a standalone template engine on both client and server sides. For example, supplant is used by **[marc](http://github.com/bredele/marc)** to make markdown a dynamic template engine.
## Installation
with [component](http://github.com/component/component):
$ component install bredele/supplant
with [nodejs](http://nodejs.org):
$ npm install supplant
## API
```js
var Supplant = require('supplant');
var subs = new Supplant();
```
### supplant.text(str, obj)
return the interpolation of a string with an object.
```js
subs.text('my name is {{ name }}', {
name : 'Olivier',
});
// = > my name is Olivier
```
### supplant.props(str)
return uniq identifiers
```js
subs.props('hello {{ name }} and {{other}}');
// => ['name', 'other']
```
## Advanced
### Expressions
```js
subs.text('{{ company.toUpperCase() }}', {
company : 'github'
});
//GITHUB
```
`supplant` supports grouping, binary operators, identifiers, comparators and ternary operators (see [test](https://github.com/bredele/supplant/blob/master/test/supplant.js)).
### Filters
```js
subs.filter('hello', function(str) {
return 'hello ' + str;
});
subs.text('{{ company} | hello}', {
company : 'github'
});
// => hello github
```
## License
MIT