dotnot
v0.0.2
Published
Access object properties using dot notation.
Downloads
3
Readme
dotnot
Access object properties using dot notation.
Install
$ npm install dotnot --save
Use
import {
get,
set
} from 'dotnot'
const data = {
a: {
b: {
c: {
d: 1
}
}
},
e: 1
}
// get (object, path) -> value
get(data, 'a.b') // returns { c: { d: 1 } }
get(data, 'a.b.c') // returns { d: 1 }
get(data, 'a.b.c.d') // returns 1
get(data, 'a.c') // returns undefined
get(data, 'a.b.d') // returns undefined
get(data, 'a.b.c.e') // returns undefined
// set (object, path, value) -> value
set(data, 'a.c', 1) // returns 1
set(data, 'a.b.d', 1) // returns 1
set(data, 'a.b.c.e', 1) // returns 1
License
MIT. © 2018 Michael Cavalea