https://github.com/uppercod/get-prop
https://github.com/uppercod/get-prop
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/uppercod/get-prop
- Owner: UpperCod
- Created: 2020-08-17T19:42:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-18T04:21:50.000Z (over 5 years ago)
- Last Synced: 2024-04-25T06:43:11.770Z (about 2 years ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# get-prop
Obtains the value of an object or array, according to a string or array type map.
## install
```
npm install @uppercod/get-prop
```
### usage
```js
import getProp from "@uppercod/get-prop";
const data = {
a: {
b: {
c: {
d: "d",
},
},
},
};
getProp(data, "a.b.c.d"); // d
getProp(data, "f", "..."); //...
```
### Selector Map Syntax
1. `a.b.c` equivalent to selector `data.a.b.c`.
2. `a.b[1]` equivalent to selector `data.a.b[1]`.
3. `a/b/c` equivalent to selector `data.a.b.c`.
4. `["a","b","c"]` equivalent to selector `data.a.b.c`.