Giter Club home page Giter Club logo

node-deep-property's Introduction

deep-property

Enables deep property manipulation and inspection without worrying about exceptions.

Usage

npm install deep-property
var props = require('deep-property'),
    sample = { };

props.set(sample, 'name.first', 'John');
props.set(sample, 'name.middle', 'C');
props.set(sample, 'name.last', 'Reilly');
props.set(sample, 'job.title', 'Actor');

props.get(sample, 'name.first');     // John
props.get(sample, 'name.middle');    // C
props.get(sample, 'name.last');      // Reilly
props.get(sample, 'job.title');      // Actor

props.remove(sample, 'name.middle'); // True

props.has(sample, 'name.first');     // True
props.has(sample, 'name.title');     // False
props.has(sample, 'job.title');      // True
props.has(sample, 'job.salary');     // False
// Resulting object
{
  name: {
    first:  'John',
    last:   'Reilly'
  },
  job: {
    title:  'Actor'
  }
}

Paths

The path parameter of each function is dot-delimited string. Everything between the dots is considered a property name. Paths can be as long and complex as necessary, with the following constraints and assumptions:

  • Paths will not recognize array indexes. Using a path like 'path.to.items[4].type' will include a lookup for an element named items[4] (string) instead of an array element.
  • Calls using invalid paths will result in the following:
    • get: undefined
    • set: No values (including intermediates) set
    • has: false
    • remove: false
  • Paths with blank sections (path.to..nothing or path.to.nothing.) will be considered invalid.

node-deep-property's People

Contributors

jarofghosts avatar mikattack avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.