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

compact-promise

v3.0.1

Published

Very compact version of promise

Downloads

1

Readme

Compact implementation of Promise/A+

Compact Promise is a lightweight Promise/A+ compliant implementation with very small footprint (870 bytes for smallest compilation after minified and gzipped).

References

  • Promise.onError - Overwrite this property with a function so that the function gets called whenever an error or exception is detected.
  • Promise(func) - constructor of a promise, func will be called once instantiation is done with 2 functions as its parameters -- resolve and reject. Call each function respectly to resolve or reject the promise.
    • Promise.prototype.then(resolveCallback, rejectCallback) - Invoke resolveCallback when the promise is resolved, the vice versa for rejectCallback.
  • Promise.all(promises) - Resolve when the all the promises in the promises array are resolved, reject when any of the promises is rejected.
  • Promise.resolve(promise) - Return a resolved promise when promise is resolved or null.
  • Promise.reject(reason) - Return a reject promise with reason as its error.
  • Promise.Defer() - Constructor of defer.
    • Promise.Defer.prototype.resolve(value) - Resolve the defer with value.
    • Promise.Defer.prototype.reject(error) - Reject the defer with error.

Compilation and Promise/A+ Compliant

The complete version of Compact Promise is fully compliant with Promise/A+. However lots of developers may find that its unnecessary to bring in all the standard and extended features into the project, as most of them probably never used.

To reduce the extra fat, Compact Promise is also compiled with/without certain function sets so that you can pick up just what you need for your next project.

Here is list of compliancy of each compilations:

  • Default - full compliant, with extension methods such as Defer.all()
  • notick - Promise/A+ 3.1 is excluded to avoid to implement platform specific micro-task nextTick or macro-task setImmediate, as a lot of developers has already pointed out, the cross platform implementation of those, at the moment is bloated with feature detections, workarounds and hacks, which means it doesn't fit the ideology of being a compact, lightweight, use anywhere library. And even so, it still doesn't support a lot of older platforms and mobile platforms and at those cases it fallbacks to setTimeout, which means very slow execution and performance. By not implementing Promise/A+ 3.1, in a lot of cases, its not just make page loads faster, run faster, but also avoid unnecessary async calls so it makes debugging a lot of easier as well.
  • noext - No extension method such as Defer.all(), these methods are not part of the standard, they are added because they are very common in the other similiar libs.
  • noumd - No UMD header, plain Javascript!

install with NPM or Bower

npm install compact-promise bower install compact-promise --save

Tests

To run full tests

npm run test

To run Promise/A+ tests

npm run test-basic

To run extended tests

npm run test-ext