Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
javascript-object-templates
Advanced tools
Templates for Javascript Objects
Create a template using a layout object describing the type and default value. If the default value is null, then the field can be of any type.
var JOT = require('JavascriptObjectTemplates');
// Create new template
var template = new JOT({
myString: 'myStringValue',
myNumber: 1234
multipleValues: null,
subObject: {
subNumber: 5678
}
});
Note: This will be foundation for all following examples.
Get a value from the template.
template.get('myString'); // 'myStringValue'
template.get('myNumber'); // 1234
template.get('subObject.subNumber'); // 5678
Set a value to the template.
Note: Only accepts same type unless it's default value was null.
template.set('myString', 'myNewStringValue'); // true
template.get('myString'); // 'myNewStringValue'
template.set('myString', 1234); // false (because the type is different)
template.get('myString'); // 'myNewStringValue'
template.set('myBoolean', true); // false (because the field isn't defined in layout)
Set multiple values from an object.
template.get('myString'); // 'myStringValue'
template.get('myNumber'); // 1234
template.merge({
myString: 'myObjectStringValue',
myNumber: 'example',
myBoolean: false,
subObject: {
subNumber: 0
}
});
template.get('myString'); // 'myObjectStringValue'
template.get('myNumber'); // 1234 (because the type is different)
template.get('myBoolean'); // undefined (because the field isn't defined in layout)
template.get('subObject.subNumber'); // 0
Get the template as object.
Can be used together with reset()
to allow the template to be used multiple times.
template.set('myString', 'myNewStringValue');
template.set('myNumber', 5678); // false (because the type is different)
template.getObject();
/*
{
myString: 'myNewStringValue',
myNumber: 5678
multipleValues: null,
subObject: {
subNumber: 5678
}
}
*/
Resets the template back to default values.
Can be used together with getObject()
to allow the template to be used multiple times.
template.set('myString', 'myNewStringValue');
template.set('myNumber', 5678); // false (because the type is different)
template.getObject();
/*
{
myString: 'myNewStringValue',
myNumber: 5678
multipleValues: null,
subObject: {
subNumber: 5678
}
}
*/
template.reset();
template.getObject();
/*
{
myString: 'myStringValue',
myNumber: 1234
multipleValues: null,
subObject: {
subNumber: 5678
}
}
*/
FAQs
Templates for Javascript Objects
The npm package javascript-object-templates receives a total of 0 weekly downloads. As such, javascript-object-templates popularity was classified as not popular.
We found that javascript-object-templates 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.