1.1.0 • Published 5 years ago

dot-js v1.1.0

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

dot-js

Use dot notation to get/set value in object

npm

Install

npm i --save dot-js

Usage

var dot = require('dot-js');

var sample = {
  foo: {
    bar: {
      single: 3
    }
  }
};

let value;

// 3
value = sample.dot('foo.bar.single');

// or
value = dot.get(sample, 'foo.bar.single');

// set bar value
sample.dot('foo.bar', value * 4);

// or
dot.set(sample, 'foo.bar', value * 4);

// set a new field
sample.dot('foo.create.new.field', 'hello');

/* {
    "foo": {
        "bar": 12,
        "create": {
            "new": {
                "field": "hello"
            }
        }
    }
} */
console.log(sample);

Object Prototype

Object.dot(path)

get

Object.dot(path, value)

set

Functions

get(object, path)

set(object, path, value)

1.1.0

5 years ago

1.0.6

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago