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 🙏

© 2026 – Pkg Stats / Ryan Hefner

prim

v1.0.0

Published

Promise lib for use inside requirejs-related projects

Downloads

38

Readme

A promise library for use in requirejs-related projects. If you are looking for a robust promise library, consider Q instead.

prim passes version 2.1.1 of the promises-aplus-tests as the baseline tests to check if it is working like a promise library.

This library just aims to be a minimum implementation that passes the standard tests. The hope is that over time, requirejs-related code that use this library can just remove it and use promises provided by the JS language.

API

This module works as an AMD or Node module.

It should conform to the basic Promises API. You can alias the export value of the prim module to Promise if you want to write the code assuming promises will be available in the language at some point:

var Promise = require('prim');

var p = new Promise(function (resolve, reject) {
    // Call resolve(value) to resolve the promise to a value.
    // Call reject(Error) to resolve the promise to an error.
});

p.then(function (value) {
    console.log('Promise p has value: ' + value;)
}, function (error) {
    console.log('Promise p has error: ' + error);
});

Passing new is not required to create a new promise, prim will do the right thing even without new. So, this is fine:

var prim = require('prim');
var p = prim(function (resolve, reject) { });

catch can be used as a shorthand to just listening for a rejection:

var p = new Promise(function (resolve, reject) {
    // Call reject(Error) to resolve the promise to an error.
});

// same as p.then(null, function (error) {});
p.catch(function (error) {
    console.log('Promise p has error: ' + error);
});

all is also available: it takes an array of promises and waits for them all to be fulfilled, and resolves the all promise with an array of the results:

prim.all([promise1, promise2]).then(function(values))
.then(function (values) {
    // values[0] is the value for promise1,
    // values[1] is the value for promise2
}, function (err) {
    // The first promise that is in the reject state
    // will result `all` promise being rejected with
    // that rejection value.
});

Right now all only supports arrays, not any iterable.

Tests

To get the tests to run, you need node installed, along with the promises-aplus test suite:

cd tests
npm install promises-aplus-tests mocha
./runTests.sh

License

MIT or new BSD.