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

jspromise

v2.0.2

Published

Promises/A+ implementation

Downloads

48

Readme

JSPromise Build Status

JS Promises/A+ implementation

Instance API

Static API

###Instance API###

####new JSPromise()#### Constructor, creates a new promise object

promise = new JSPromise();

####promise.then([onFulfilled], [onRejected])#### See https://github.com/promises-aplus/promises-spec#the-then-method

promise2 = promise1.then(onFulfilled, onRejected);

####promise.resolve([value])#### Resolves the promise according to promise resolution procedure

promise.resolve(42);

####promise.fulfill([result])#### Fulfills promise with result

promise.fulfill(42);

####promise.reject([reason])#### Rejects promise with reason

promise.reject( new Error("Awesome exception") );

####promise.always([onResolved])#### Calls reason when the promise will be resolved

promise.always(function (promise) {
    console.log( promise.isFulfilled() );
});

####promise.done([onFulfilled], [onRejected])#### Terminates promise chaining, if the last promise was rejected, an exception will be thrown

promise.then(function () {
    throw 42;
}).done();

####promise.fail([onRejected])#### Simple shortcut for promise.then(undefined, onRejected);

promise.fail(myFallback);

####promise.isFulfilled()#### Returns true if the promise is in fulfilled state

promise.fulfill();
promise.isFulfilled();  //  -> true

####promise.isPending()#### Returns true if promise is in pending state

promise = new JSPromise();
promise.isPending();  //  ->  true
promise.resolve()
promise.isPending();  //  -> false

####promise.isRejected()#### Returns true if the promise is in rejected state

promise.reject();
promise.isRejected(); //  -> true

####promise.isResolved()#### Returns true if the promise is in one of resolved or rejected states

promise = new JSPromise();

promise.isResolved(); //  -> false
promise.fulfill();
promise.isResolved(); //  -> true

promise = new JSPromise();
promise.reject();
promise.isResolved(); //  -> true

###Static API###

####JSPromise.allFulfilled(promises)#### Creates a new promise to be fulfilled when all given promises will be fulfilled. Promise will be rejected if any of given promises will be rejected

promise1 = new JSPromise();
promise1.fulfill(6);
promise2 = new JSPromise();

JSPromise.allFulfilled([5, promise1, promise2]).then(function (results) {
    console.log(results); // [5, 6, 7];
});

setTimeout(function () {
    promise2.fulfill(7);
}, 100);

####JSPromise.allResolved(promises)#### Creates a new promise to be resolved when all given promises will bew resolved

promise1 = new JSPromise();
promise1.reject(6);
promise2 = new JSPromise();

JSPromise.allResolved([5, promise1, promise2]).then(function (results) {
    console.log(results.map(function (promise) {
        return promise.valueOf();
    })); // [5, 6, 7];
});

setTimeout(function () {
    promise2.fulfill(7);
}, 100);

####JSPromise.create([result])#### Creates a new promise and resolves it, if given value is thenable

JSPromise.create(5);  // -> {JSPromise}

####JSPromise.resolve([value])#### Resolves value and returns a new promise

promise = JSPromise.resolve(42);

####JSPromise.fulfill([result])#### Fulfills a new promise with given result

JSPromise.fulfill(42);

####JSPromise.reject([reason])#### Creates a new promise and rejects it with given reason

JSPromise.reject(42);

####JSPromise.when([result], [onFulfilled], [onRejected])#### Creates a new promise to be resolved when result will be resolved according to promise resolution procedure. onFulfilled and onRejected callbacks can be passed.

JSPromise.when(42, function (result) {
    console.log(result); // -> 42
});

####JSPromise.invoke(fn)#### Calls the given function and resolves new promise with returned value

JSPromise.invoke(function (result) {
    return result;
}, null, 42).then(function (res) {
    console.log(res); // -> 42
})