GithubHelp home page GithubHelp logo

acstll / deep-get-set Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juliangruber/deep-access

23.0 2.0 12.0 25 KB

Set and get values on objects via dot-notation strings.

JavaScript 100.00%

deep-get-set's Introduction

deep-get-set

Set and get values on objects via dot-notation strings.

Example

var deep = require('deep-get-set');

var obj = {
  foo: {
    bar: 'baz',
    'bar.baz': 'qux'
  }
};

// Get
console.log(deep(obj, 'foo.bar'));
  // => "baz"

// Get with array
console.log(deep(obj, ['foo', 'bar.baz']));
  // => "qux"

// Set
deep(obj, 'foo.bar', 'hello');
console.log(obj.foo.bar);
  // => "hello"

// Set with array
deep(obj, ['foo', 'bar.baz'], 'goodbye');
console.log(obj.foo['bar.baz']);
  // => "goodbye"

API

deep(object, path[, value])

Where path is a dot-notation string foo.bar or an array of strings.

  • If value is passed it will be set on the path.
  • Set deep.p = true if you want non-existent paths to be initialized.
  • If you want to unset (or delete), pass undefined as the value.

Installation

With npm do:

npm install deep-get-set

Note

There's a dozen modules like this on npm. This is a fork from @juliangruber's deep-access module, with a big portion of code directly copied from here: https://github.com/substack/js-traverse/blob/master/index.js#L11-L18.

Similar modules:

License

MIT

deep-get-set's People

Contributors

acstll avatar jamieslome avatar josephschmitt avatar juliangruber avatar niksy avatar vitorluizc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.