node package manager


String variable substitution


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.

with component:

$ component install bredele/supplant

with nodejs:

$ npm install supplant
var Supplant = require('supplant');
var subs = new Supplant();

return the interpolation of a string with an object.

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

return uniq identifiers

subs.props('hello {{ name }} and {{other}}'');
subs.text('{{ company.toUpperCase() }}', {
  company : 'github'

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

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