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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jpromise

v1.0.8

Published

jPromise ==========

Readme

jPromise

A Promise Library that is actually spec compliant with the latest versions of the spec...

A library conforming to the Promise/A spec.

Tested in Chrome, Firefox, Safari, and IE8/9/10.

This is a promise library that is speedy quick, doesn't hold onto scopes everywhere all willy-nilly, and is also quite flexible.

  • p Constructor
    • Creates a new deferred object
  • dfd.promise()
    • Returns the promise for a given deferred object. The promise object is not able to access some of the deferrer's methods, such as resolve and reject.
  • dfd.resolve(arg)
    • Resolves the deferred object. When the deferred object gets resolved, callbacks on dfd.then, dfd.done, and dfd.always will get called with arg.
  • dfd.reject(arg)
    • Rejects the deferred object. When the deferred object gets resolved, callbacks on dfd.then, dfd.fail, and dfd.always will get called with arg.
  • dfd.progress(arg)
    • Progresses the deferred object (like a resolve but can be called multiple times). When the deferred object gets resolved, callbacks on dfd.notify will get called with arg.
  • dfd.done(cb) and promise.done(cb)
    • Creates a callback for when the deferred object gets resolved. The cb function will get called with the arg that the deferred object was resolved with.
  • dfd.fail(cb) and promise.fail(cb)
    • Creates a callback for when the deferred object gets rejected. The cb function will get called with the arg that the deferred object was rejected with.
  • dfd.progress(cb) and promise.progress(cb)
    • Creates a callback for when the deferred object gets notified. The cb function will get called with the arg that the deferred object was notified with.

Example:

//Stashes on the global _ on the property Dfd...
//The closure also returns the Dfd constructor and could be munged to work in AMD/Common if we gave a...
var p = require('jpromise');

var dfd = new p();

var pro = dfd.promise();

pro.always(function(data) {
  console.log("always", data);
});

pro.done(function(data) {
  console.log("done", data);
});

pro.fail(function(data) {
  console.log("fail", data);
});

pro.progress(function(data) {
  console.log("progress", data);
});

setTimeout(function() {
  dfd.notify("foo");

  console.log("state", dfd.state());

  dfd.resolve("bar");

  pro.done(function(data) {
    console.log("after Done", data);
  });

  console.log("state", dfd.state());

}, 500);

//returns in console:
// progress "foo"
// state 0
// always "bar"
// done "bar"
// after Done "bar"
// state 1

Notes

  • You can done/fail/progress/then on the dfd as well as the promise, but you can only resolve/reject/notify on the dfd
  • You cannot escalate the promise into the dfd, it is a one way street
  • You can get the promise from the dfd multiple times and it will always return the same promise instance
  • You can bind at any point even after a dfd has resolved/rejected and it will instantly return
  • This sucker is about 3x as fast/efficient as jQuery's Deferred piece clocking in at about 100k ops a second