Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eryouhao/safe-get-plus
Securely get attributes from objects and can provide default value
https://github.com/eryouhao/safe-get-plus
javascript npm-module
Last synced: about 4 hours ago
JSON representation
Securely get attributes from objects and can provide default value
- Host: GitHub
- URL: https://github.com/eryouhao/safe-get-plus
- Owner: EryouHao
- Created: 2018-04-19T03:48:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-19T04:07:26.000Z (over 6 years ago)
- Last Synced: 2024-11-17T02:42:25.466Z (3 days ago)
- Topics: javascript, npm-module
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# safe-get-plus
## Install
``` sh
npm install safe-get-plus --save
```
## Start``` javascript
const safeGet = require('safe-get-plus')const response = {
data: {
user: {
name: 'eryou',
age: 18,
friends: ['xiaoming', 'xiaohong'],
},
list: [1, 2, 3],
}
}const data = safeGet(response, 'data.user.friends', []) // ['xiaoming', 'xiaohong']
const data = safeGet(response, 'data.user.address', '') // ''
```
## API
``` javascript
const safeGet = require('safe-get-plus')
safeGet(Object, [Property dot string], [Default Value])
```
**Arguments**`Object`: The object to be valued.
`[Property dot string]`: A string that gets a value with a point.
`[Default Value]|null`: Default value when no value is taken.