Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jimmywarting/lazy-resolver
Skip hoops with promises, make async code sync-ish looking (it is still async)
https://github.com/jimmywarting/lazy-resolver
async chain javascript promise
Last synced: 25 days ago
JSON representation
Skip hoops with promises, make async code sync-ish looking (it is still async)
- Host: GitHub
- URL: https://github.com/jimmywarting/lazy-resolver
- Owner: jimmywarting
- License: mit
- Created: 2017-05-18T13:04:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T14:55:04.000Z (over 2 years ago)
- Last Synced: 2024-05-01T23:13:01.407Z (9 months ago)
- Topics: async, chain, javascript, promise
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lazy-resolver
Skip hoops with promises```bash
npm install lazy-resolver
```
Do you know how lodash _.get works or angulars $parse works?
this lib is kind of like that, you can test deep objects/path
but it dose it with promises and by chaining a dummy function
to evaluate the code when a promise has been resolved# Example:
```js
const resolve = require('lazy-resolver') // This is a Proxy handler
const fetch = resolve(import('node-fetch')).defaultfetch(url)
.then(response => console.log(response))
```Go beond what's possible and make promise chain sync-ish looking
```js
// Node variant
const fetch = resolve(import('node-fetch')).default
fetch('https://httpbin.org/get?items=4&items=2')
.json()
.args
.items
.map(n => ~~n * 4)
.then(console.log, console.warn)// Browser variant
resolve(window)
.fetch('https://httpbin.org/get?items=4&items=2')
.json()
.args
.items
.map(n => ~~n * 4)
.forEach(n => console.log(n))
```Test if obj exist, similar to lodash/get or optional chaining
```js
const obj = {}
exist = await resolve(obj).foo.bar().buz[28]
```