4.0.0 • Published 6 years ago

deepval v4.0.0

Weekly downloads
23
License
MIT
Repository
github
Last release
6 years ago

deepval npm.io

Get, Set and Remove object values using dot-delimited key strings

deepval(<object to inspect>, <string path> or <array of string keys>, [value to set], [boolean: remove])

or:

deepval.get(obj, path);
deepval.set(obj, path, value);
deepval.del(obj, path);

examples:

var obj = {
  a: {
    b: {
      c: 'deep'
    },
    d: ['foo'],
    e: ['bar', ['aaa', 'bbb']]
  }
};

// get a value
console.log(deepval(obj, 'a.b.c'));   // 'deep'
// set a value
deepval(obj, 'a.b.c', 'something');
console.log(deepval(obj, 'a.b.c'));   // 'something'
// remove a value
deepval(obj, 'a.b.c', null, true);
console.log(deepval(obj, 'a.b.c'));   // undefined
// read array values
console.log(deepval(obj, 'a.d.0'));   // 'foo'
console.log(deepval(obj, ['a', 'd', 0]));   // 'foo'
console.log(deepval(obj, 'a.e.1.0')); // 'aaa'

deepval provides a utility function dotpath to create a dot-delimited string from a set of passed arguments:

console.log(deepval.dotpath('hello', a.b.0))  //  'hello.foo'
4.0.0

6 years ago

3.0.0

6 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

8 years ago

2.0.0

9 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago