expands
v1.0.2
Published
Expands variable placeholders in objects.
Downloads
3
Readme
expands
Expands variable placeholders in objects.
Installation
This module can be installed easily with npm:
$ npm install expands
Usage
These examples show you how expands
works:
var assert = require('assert');
var expand = require('expands');
// Expands string
assert.deepEqual(expand({
message: 'Welcome {name}!',
name: 'intruder'
}), {
message: 'Welcome intruder!',
name: 'intruder'
});
// Expands array
assert.deepEqual(expand({
messages: [
'Welcome {name}!',
'You are {age} years old.',
12345
],
name: 'intruder',
age: 1000
}), {
messages: [
'Welcome intruder!',
'You are 1000 years old.',
12345
],
name: 'intruder',
age: 1000
});
// Expands deep path
assert.deepEqual(expand({
foo: {
bar: {
one: '1',
two: '2'
},
message: 'One is {foo.bar.one} and two is {foo.bar.two}.'
}
}), {
foo: {
bar: {
one: '1',
two: '2'
},
message: 'One is 1 and two is 2.'
}
});
// Expands circle dependency
assert.deepEqual(expand({
a: 'from {b}', // expanding is top-down so `a` will be expanded first
b: 'from {c}',
c: 'from {a}', // `a` is not expanded completely, resolved to 'from ',
}), {
a: 'from from from from ',
b: 'from from from ',
c: 'from from '
});
Contributing
Before create a pull request, make sure that you:
Followed coding convention as described in .editorconfig or .jshintrc file (more information can be found at editorconfig.org and www.jshint.com/docs, respectively).
Added tests for your code.
Passed all tests!
To execute all tests, simply run:
$ npm test
Contributors
- Author: Meo
License
This module is released under MIT license.