0.2.0 • Published 10 years ago

supplant v0.2.0

Weekly downloads
18
License
MIT
Repository
github
Last release
10 years ago

Supplant

Build Status

Variable substitution on the string.

It scans through the string looking for expressions enclosed in {{ }} braces. If an expression is found, use it as a key on the object, and if the key has a string value or number value, it is substituted for the bracket expression and it repeats.

Installation

with component:

$ component install bredele/supplant

with nodejs:

$ npm install supplant

API

var Supplant = require('supplant');
var subs = new Supplant();

supplant.text(str, obj)

return the interpolation of a string with an object.

subs.text('my name is {{ name }}', {
  name : 'Olivier',
});

//my name is Olivier

supplant.props(str)

return uniq identifiers

subs.props('hello {{ name }} and {{other}}'');
//['name', 'other']

Advanced

Expressions

subs.text('{{ company.toUpperCase() }}', {
  company : 'github'
});

//GITHUB

supplant supports grouping, binary operators, identifiers, comparators and ternary operators (see test).

Filters

subs.filter('hello', function(str) {
  return 'hello ' + str;
});
subs.text('{{ company} | hello}', {
  company : 'github'
});

//hello github 

License

MIT

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago