Skip to content

Utility for setting/getting/manipulating deeply nested attributes of an object.

Notifications You must be signed in to change notification settings

DanielOchoa/objectify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Objectify Build Status

This node library allows you to set, get or check for the predicate of deep 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('node-objectify');

var src = {};

Check for the existence of a nested property:

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);
}

Get a nested property:

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

Set a nested property:

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

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

About

Utility for setting/getting/manipulating deeply nested attributes of an object.

Resources

Stars

Watchers

Forks

Packages

No packages published