Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huruji/chain-get
程序员的自我修养:如何优雅地无报错链式取值
https://github.com/huruji/chain-get
chain debug proxy
Last synced: 3 months ago
JSON representation
程序员的自我修养:如何优雅地无报错链式取值
- Host: GitHub
- URL: https://github.com/huruji/chain-get
- Owner: huruji
- License: mit
- Created: 2018-11-19T15:57:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-29T09:42:16.000Z (almost 6 years ago)
- Last Synced: 2024-07-03T18:00:11.917Z (4 months ago)
- Topics: chain, debug, proxy
- Language: JavaScript
- Homepage:
- Size: 51.8 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-star - chain-get
README
# chain-get
## 使用Proxy实现的无报错链式优雅取值方法## 使用
```bash
npm i chain-get -S
``````js
import chainGet from 'chain-get';let person = {age: 12, name: 'huruji', sisters: ['a']}
chainGet(person).age() // 12
chainGet(person).sisters[0]() // a
chainGet(person).sisters[1]() // undefined
chainGet(person).brothers[1]() // undefined
```从此告别以下这类代码
```js
if (person && person.sister && persion.sister[0]) {
const sister = person.sister[0]
}
```