node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »

getsetdeep

Get Set Deep

Build Status NPM version Flattr this project

Get and set nested variables of an object, includes support for Backbone Models

Install

Backend

  1. Install Node.js
  2. npm install --save getsetdeep

Frontend

  1. See Browserify

Usage

Example

// Import 
var getsetdeep = require('getsetdeep');
 
// Prepare 
var obj = {
    a: {
        b: {
            c: 3
        }
    }
};
 
// Get 
console.log(getsetdeep.getDeep(obj, 'a.b.c'));     // 3 
console.log(getsetdeep.setDeep(obj, 'a.b.c', 4));  // 4 
console.log(getsetdeep.getDeep(obj, 'a.b.c'));     // 4 

Notes

  • setDeep also has a fourth argument opts for options, currently we support the options:
    • onlyIfEmpty defaults to false, if specified to true then setDeep will only set the value if the current value is null or undefined
  • We also work with getters get(key) and setters set(attrs,opts), enabling support for Backbone.js models as well as others

History

You can discover the history inside the History.md file

License

Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd
Copyright © 2011-2012 Benjamin Arthur Lupton