https://github.com/callmecavs/dotnot
Access object properties using dot notation.
https://github.com/callmecavs/dotnot
dot-notation object
Last synced: 9 months ago
JSON representation
Access object properties using dot notation.
- Host: GitHub
- URL: https://github.com/callmecavs/dotnot
- Owner: callmecavs
- Created: 2018-02-22T17:49:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-24T21:18:21.000Z (almost 8 years ago)
- Last Synced: 2025-04-10T05:17:13.075Z (10 months ago)
- Topics: dot-notation, object
- Language: JavaScript
- Homepage:
- Size: 42 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dotnot
[](https://travis-ci.org/callmecavs/dotnot) [](https://www.npmjs.com/package/dotnot) [](https://www.npmjs.com/package/dotnot) [](http://standardjs.com/)
Access object properties using dot notation.
### Install
```sh
$ npm install dotnot --save
```
### Use
```javascript
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](https://opensource.org/licenses/MIT). © 2018 Michael Cavalea