3.0.0 • Published 6 years ago
@jf/prop-sep v3.0.0
@jf/prop-sep
Check, get, set and remove properties from nested objects using any separator.
const propSep = require('@jf/prop-sep');
const obj = {};
propSep.set(obj, 'a.b.c', 5);
console.log(obj); // { a : { b : { c : 5 } } }
Also, you can attach and detach this methods to objects and classes.
As instance methods:
const propSep = require('@jf/prop-sep');
class Class {}
propSep.attach(Class);
const obj = new Class();
obj.set('a.b.c', 5);
console.log(obj); // { a : { b : { c : 5 } } }
As class methods:
const propSep = require('@jf/prop-sep');
class Class {}
class Other extends Class {}
propSep.attach(Class, false);
const obj = {};
Class.set(obj, 'a.b.c', 5);
console.log(obj); // { a : { b : { c : 5 } } }
Other.set(obj, 'b', 1);
console.log(obj); // { a : { b : { c : 5 } }, b : 1 }
See test file for examples.
3.0.0
6 years ago