Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
expander
Advanced tools
Readme
Expand template strings in declarative configurations.
Retrieve a value from the data object with all template strings resolved.
data
a configuration object
lookup
a dot-notated key
options
sent to _.template when resolving values.
Example:
var data = {
key: '<%= uppercase("foo") %>'
};
expander.get(data, 'key', {
imports: {
uppercase: function (str) {
return str.toUpperCase();
}
}
}); // FOO
Retrieve a literal value from the data object.
data
a configuration object
lookup
a dot-notated string representing a key in the configuration
Set a value in the data object.
data
a configuration object
lookup
a dot-notated string representing a key in the data
value
the value to set
Resolve any arbitrary template string.
data
a configuration object
lookup
any string value, typically a template string, e.g. "<%= key %>"
options
sent to _.template when resolving values.
Bind the above API to a provided data object so you can access it more succinctly.
data
a configuration object
options
sent to _.template automatically when resolving values.
Note: When using the interface API, passing options to get
or process
will perform a shallow merge over options
provided when the interface was instantiated.
Example:
var configRaw = {
key: 'value',
keyRef: '<%= key %>'
};
var config = expander.interface(config);
config('key'); // value
config.get('key'); // value
config('keyRef'); // value
config.get('keyRef'); // value
config('key', 'changed'); // changed
config('key'); // changed
var expander = require('expander');
var data = {
key: 'value',
keyRef: '<%= key %>',
recursiveKeyRef: '<%= keyRef %>',
arrayRef: ['test', '<%= key %>'],
recursiveArrayRef: ['test', '<%= arrayRef %>'],
obj: {
keyRef: '<%= key %>',
recursiveKeyRef: '<%= keyRef %>',
arrayRef: ['test', '<%= key %>'],
recursiveArrayRef: ['test', '<%= arrayRef %>']
},
dotRef: '<%= obj.keyRef %>',
objRef: '<%= obj %>',
interpolated: 'test <%= key %>',
interpolatedRecursiveRef: 'test <%= keyRef %>',
methodRef: expander.fn(function (config) {
// config is the entire config
return config.key;
}),
methodRefContext: expander.fn(function (config) {
// this is a reference to expander
return this.get(config, 'keyRef');
})
};
expander.get(data, 'keyRef'); // value
expander.get(data, 'recursiveKeyRef'); // value
expander.get(data, 'arrayRef'); // ['test', 'value']
expander.get(data, 'recursiveArrayRef'); // ['test', ['test', 'value']]
expander.get(data, 'obj'); // {
// keyRef: 'value',
// recursiveKeyRef: 'value',
// arrayRef: ['test', 'value'],
// recursiveArrayRef: ['test', ['test', 'value']]
// }
expander.get(data, 'objRef'); // {
// keyRef: 'value',
// recursiveKeyRef: 'value',
// arrayRef: ['test', 'value'],
// recursiveArrayRef: ['test', ['test', 'value']]
// }
expander.get(data, 'interpolated'); // test value
expander.get(data, 'interpolatedRecursiveRef'); // test value
expander.get(data, 'methodRef'); // value
expander.get(data, 'methodRefContext'); // value
// getter setter api
var config = expander.interface(data);
config('keyRef'); // value
config('recursiveKeyRef'); // value
config('arrayRef'); // ['test', 'value']
config('recursiveArrayRef'); // ['test', ['test', 'value']]
config('obj'); // {
// keyRef: 'value',
// recursiveKeyRef: 'value',
// arrayRef: ['test', 'value'],
// recursiveArrayRef: ['test', ['test', 'value']]
// }
config('objRef'); // {
// keyRef: 'value',
// recursiveKeyRef: 'value',
// arrayRef: ['test', 'value'],
// recursiveArrayRef: ['test', ['test', 'value']]
// }
config('interpolated'); // test value
config('interpolatedRecursiveRef'); // test value
config('methodRef'); // value
config('methodRefContext'); // value
FAQs
Expand template strings in declarative configurations.
We found that expander demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).