0.0.3 • Published 9 years ago

node-objectify v0.0.3

Weekly downloads
7
License
MIT
Repository
-
Last release
9 years ago

Objectify Build Status

This node library allows you to set, get or check for the predicate of a deeply nested objects.

It lets you avoid patterns such as:

if (myObj.options && myObj.options.site && myObj.options.site.url) {
  // do something with myObj.options.site.url
}

And it helps you avoid the popular undefined is not a function error.

Examples

var objectify = require('objectify');

var src = {};

Check for the existence of a nested attribute:

if (objectify(src).isSet('a.very.deeply.nested.attr')) {
  // true or false
  // do something with the nested attr here
  console.log(src.a.very.deeply.nested.attr);
}

Getting a long nested attribute:

src = {a: {very: {deeply: {nested: { attr: 1 }}}}};

objectify(src).get('a.very.deeply.nested.attr'); // returns 1

objectify(src).get('a.non.existant.attr'); // returns undefined

Setting a deep nested attribute:

objectify(src).set('a.different.nested.attribute', 2); // returns 2

console.log(src.a.different.nested.attribute) // 2