node-d
v0.2.3
Published
Simple interpolation
Downloads
1
Readme
D
Simple interpolation module. Inspired by AngularJS handlebars implementation.
Examples
Create an instance:
var D = require('node-d'); // Factory
var d = D({ name: 'Alibaster' }); // d instance
Use it:
d('Hello, {{name}}!') // => Hello, Alabaster!
Add more data:
d.$extend({ hobby: 'alcoholism' });
d('Hello, {{name}}, we see you love {{hobby}}!') // => Hello, Alabaster, we see you love alcoholism!
Delete a key:
d.$delete('hobby');
d('{{name}} enjoys {{hobby}}!'); // => Alabaster enjoys !
Properties are getters:
console.log(d.name); // => "Alabaster"
Not setters (use $extend
to overwrite):
d.name = 'Quartz';
console.log(d.name); // => "Alabaster"
Works w/ nested properties
d.$extend({ a: { b: { c: 'd' }}});
d('/a/b/c/{{a.b.c}}');
// => '/a/b/c/d'
Why D
?
Originally this was for directory interpolation for build tasks and I wanted it to be as compact as possible, since JS doesn't have string interpolation. It has nothing directory-oriented in its implementation, but D
is still small. I dunno.
Ironically, this module is written in ES6, which does have string interpolation. Hopefully, this dies sooner rather than later.
License
MIT