3.0.0 • Published 6 years ago

@jf/prop-sep v3.0.0

Weekly downloads
36
License
MIT
Repository
github
Last release
6 years ago

@jf/prop-sep stable

npm install @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.