setobj
v1.0.3
Published
Object property setting utility
Downloads
1
Readme
setobj
Object property setting utility.
Installation
$ npm install setobj
Usage
const setobj = require("setobj");
var obj = {};
setobj(obj, ({set, unenumerable, unconfigurable, readonly}) => {
set("prop1", 5); // Equivalent to: obj.prop1 = 5;
set(Symbol("prop2"), 6) // Symbols work too
set("prop3", 2, unenumerable); // Unenumerable property
set("prop4", 9, unenumerable | unconfigurable | readonly); // Unenumerable, unconfigurable, and read-only property
set(0, "test"); // Numerical keys
});
For getters/setters:
setobj(obj, ({set, getset}) => {
set("prop", {get: ..., set: ...}, getset | ...)
});
setobj also has support for nested set
s:
var obj = {
nested1: {
nested2: {
a: 1,
b: 2,
c: 3
}
}
}
setobj(obj, ({setobj}) => {
setobj("nested1", ({setobj}) => {
setobj("nested2", ({setobj}) => {
set("d", 4);
set("e", 5);
// ...
});
});
});
License
MIT