Skip to content

kaelzhang/node-cobj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cobj NPM version Build Status Dependency Status

Utilities to manage cascading objects.

Install

$ npm install cobj --save

Usage

var cobj = require('cobj');

cobj.get(data, key)

var obj = {
  a: 1,
  b: {
    c: 2
  }
};

cobj.get(obj, 'a'); // 1
cobj.get(obj, 'b.c'); // 2
cobj.get(obj, 'd'); // undefined

Get a value, if not found, it will returns undefined.

cobj.set(data, key, value);

var obj = {};
cobj.set(obj, 'a', 1); // obj.a -> 1
cobj.set(obj, 'b.c', 2); // obj.b.c -> 2
cobj.set(obj, 'b.d', 3); // obj.b.c -> 2, obj.b.c -> 3

Set value.

cobj.remove(data, key);

var obj = {
  a: 1,
  b: {
    c: 2
  }
};
cobj.remove(obj, 'a'); // obj.a -> undefined
cobj.remove(obj, 'b.c'); // obj.b.c -> undefined, obj.b -> {}
cobj.remove(obj, 'd'); // do nothing

Remove a value by key if found.

License

MIT

About

Cascading objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published