npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pearden/promise-props

v0.0.3

Published

<img alt="NPM Version" src="https://img.shields.io/npm/v/%40pearden%2Fpromise-props?logo=npm"/><img alt="NPM Downloads" src="https://img.shields.io/npm/dt/%40pearden%2fpromise-props?label=total%20downloads">![GitHub last commit (branch)](https://img.shiel

Downloads

5

Readme

promise-props

GitHub last commit (branch)

Table of Contents

Feature

  1. Provide propsDeep() to deal with object with promises nested in deep level
  2. Enable calling functions as other static methods on Promise by mounting withinit()
  3. Support ES6 module.
  4. Support typescript. Provide type declaration
  5. Provide detailed documentation including: README, tsDoc in IDE and API pages

Installation

npm install @pearden/promise-props
# or
yarn add @pearden/promise-props

Quick Start

// 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,
    }
}
*/

Usage

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"

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.

PropsDeep

Deal with any level promise nested in the object passed into function.

FAQs

How props() is implemented

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.

How propsDeep() is implemented

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

Test

This project use jest for testing

yarn test

Check test directory for detail.

Build

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

Local publish

Publish NPM package with yarn

yarn publish --acccess public

Github Action

Auto publish to NPM when a Github release or prerelease is published.

Check for workflow config.

See Also

petkaantonov/bluebird: :bird: Bluebird is a full featured promise library with unmatched performance

sindresorhus/p-props: Like Promise.all() but for Map and Object

promise-props

Siilwyn/promise-all-props: Like Promise.all but for object properties.

magicdawn/promise.obj: promise.obj / promise.props