A simple extension for promise
English
·
简体中文
Usage
·
Report Bug
·
API Documentation
- Provide
propsDeep()
to deal with object with promises nested in deep level - Enable calling functions as other static methods on Promise by mounting with
init()
- Support ES6 module.
- Support typescript. Provide type declaration
- Provide detailed documentation including: README, tsDoc in IDE and API pages
npm install @pearden/promise-props
# or
yarn add @pearden/promise-props
// mount props() and propsDeep() methods on Promise
init() ;
await Promise.props({
name: "promise",
age: Promise.resolve(123),
}) ;
/* output
{
name: "promise",
age: 123,
}
*/
await Promise.propsDeep({
sub: {
name: "promise",
age: Promise.resolve(123),
}
}) ;
/* output
{
sub: {
name: "promise",
age: 123,
}
}
*/
Import
// Enable calling like Promise.props and Promise.propsDeep
// Do this in your main.[ts|js] file
init()
// or import whenever you want
import {props, propsDeep} from "promise-props"
Like Promise.all
,but only deal with top level promise in the object passed in.
- Other top level none promise properties will be shallow copied to the result object
- Nonenumerable properties will be ignored.
Deal with any level promise nested in the object passed into function.
Notice: nonenumerable properties will always be ignored.
All the top level promise will be extract into an array. Then call Promise.all
on this array. If all promises reslove, then the resolve value will be set into result object with the origin key of promise properties.
If any top level promise reject, as props()
is an async function, it will automatically return an promise with the same reject reason.
Finally, other top level properties will be shallow copied to result object.
Use lodash
to deep copy the object passed in as the result object
Use tarverse
to traverse object filtering out all promise properties at any level and record the property path in the object.
Call Promise.all
on promises array and get an array of all resloved value.
Use``object-path` lib to set value into result object with paths
Finally return the result
This project use jest for testing
yarn test
Check test directory for detail.
This project use Rollup to build.
# build once
yarn build
# build with file watching
yarn build:watch
For detailed building configuration, check rollup config.
Publish NPM package with yarn
yarn publish --acccess public
Auto publish to NPM when a Github release or prerelease is published.
Check for workflow config.
petkaantonov/bluebird: 🐦 Bluebird is a full featured promise library with unmatched performance
sindresorhus/p-props: Like Promise.all()
but for Map
and Object
Siilwyn/promise-all-props: Like Promise.all
but for object properties.