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

pinkypromise

v0.2.1

Published

A straight-forward Promises/A+ 1.1 implementation

Downloads

5

Readme

Pinky

A straight-forward Promises/A+ 1.1 implementation

Pinky is a no-nonsense Promises/A+ 1.1 implementation. Pinky is written to be very readable and easy to follow, with references to the relevant sections of the spec for each operation. As such, Pinky can be used as an academic example of a promises implementation.

Pinky includes a number of fully documented examples that illustrate common use cases, explain exactly what's going on, and highlight the power of promises. Several included examples can be used as independent explanations of the functionality promises can provide without any prior introduction to the concept.

API

Create a new Pinky instance with var pinky = new Pinky().

pinky.then( onFulfilled , onRejected )

Used to add onFulfilled and onRejected callbacks to the promise. The same method is provided as pinky.promise.then(...).

pinky.fulfill( value )

When passed a value, the promise will be fulfilled. All onFulfilled callbacks will receive the passed value as their first argument. pinky.resolve is aliased to this method.

pinky.reject( reason )

When passed a reason, the promise will be rejected. All onRejected callbacks will receive the passed error as their first argument.

pinky.promise

The pinky.promise property is a "thenable" object that should be returned by functions that use Pinky. Instead of returning the Pinky instance itself, which would allow callers to fulfill/reject the promise, your function should return pinky.promise -- an object that includes the one method a promise must have: pinky.then(...).

Usage

Pinky can be used on both the server and the client.

Node.js

First, install the pinkypromise module using npm. Optionally use --save to save Pinky as a dependency in your package.json:

npm install pinkypromise --save

Next, require Pinky:

var pinky = require('pinky');

Then, use promises in your code:

function helloWorld() {
	var pinky = new Pinky();

	pinky.fulfill('world');

	return pinky.promise;
}

helloWorld().then(function(value) {
	console.log('Hello '+value);
});

Browser

Just include pinky.js on your page.

AMD module

Pinky can also be used as an AMD module.

Examples

Examples for Node.js and the browser are available in the examples/ folder.

Some of the examples located in examples/browser/ fetch files with XMLHttpRequest, and most browsers prevent local files from being fetched in this way. There are a number of different ways to run examples locally, the most straightforward of which is to run python -m SimpleHTTPServer or python -m http.server and navigate to http://127.0.0.1:8000.

Testing

Execute the following commands to run the Promises/A+ test suite:

npm install
npm test

License

BSD license, Copyright © 2014 Lawrence Davis