https://github.com/shigma/prochain
Proxified Promise Chain in JavaScript
https://github.com/shigma/prochain
chain javascript promise proxy typescript
Last synced: about 1 month ago
JSON representation
Proxified Promise Chain in JavaScript
- Host: GitHub
- URL: https://github.com/shigma/prochain
- Owner: shigma
- License: mit
- Created: 2021-04-24T07:02:31.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-23T13:28:03.000Z (about 4 years ago)
- Last Synced: 2025-05-05T21:12:56.703Z (about 1 month ago)
- Topics: chain, javascript, promise, proxy, typescript
- Language: TypeScript
- Homepage:
- Size: 55.7 KB
- Stars: 21
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# prochain
Proxified Promise Chain in JavaScript.
It allows for method and property chaining without need for intermediate then() or await for cleaner and simpler code.
```js
const { wrap } = require('prochain')
// Instead of thens
fetch(url)
.then(res => res.json())
.then(json => json.foo.bar)
.then(value => console.log(value))// Instead of awaits
const res = await fetch(url)
const json = await res.json()
const value = json.foo.bar
console.log(value)// With prochain
const value = await wrap(fetch(url)).json().foo.bar
console.log(value)// Or you can even create a wrapped fetch
const wrapFetch = wrap(fetch)
const value = await wrapFetch(url).json().foo.bar
console.log(value)
```