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

promisify-me

v0.1.1

Published

Turn ordinary async APIs into shiny promise based ones

Downloads

13

Readme

Promisify Me

A small library to wrap objects and turn ordinary async callback based APIs into shiny promise based ones (using the Q promise library)

Build Status

Build Status

Usage

Start with something like this

var PromisifyMe = require('promisify-me');

Then we can replace simple success callbacks with promises

var Example1 = function() {};

// Waits for millis then reports actual time taken to callback
Example1.prototype.delay = function(millis, callback) {
  var start = new Date();
  setTimeout(function() {
    var now = new Date();
    callback(null, now.getTime() - start.getTime());
  }, millis);
};

var PromissyExample1 = PromisifyMe(Example1);

var test = new PromissyExample1();

test.delay(1000)
.then(function(actualDelay) {
  console.log('A 1000ms delay actually took ' + actualDelay + 'ms');
})
.done();

// You can also call it with a callback too for compatibility
test.delay(2000, function(err, actualDelay) {
  console.log('A 2000ms delay actually took ' + actualDelay + 'ms');
});

Callback errors will reject the promise

var Example2 = function() {};

// Waits for millis then reports actual time taken to callback
Example2.prototype.causeError = function(callback) {
  setTimeout(function() {
    callback(new Error("Something bad!"));
  }, 1000);
};

var PromissyExample2 = PromisifyMe(Example2);

var test = new PromissyExample2();

test.causeError()
.then(function(actualDelay) {
  console.log('This won\'t get called as the error will happen');
})
.fail(function(err) {
  console.error(err);
});

We can also tell it how we want the adapter to function using a definition In this case we are using the built in 'nedb' definition, but we could equally provide a definition object

var DataStore = PromisifyMe(require('nedb'), 'nedb');

var store = new DataStore();

var data = [
  { name: "Steve" },
  { name: "Dave" },
  { name: "Tony" }
];

store.insert(data)
.then(function(newRecords) {
  console.log('Inserted ' + newRecords.length + ' records');

  // Now we will retrieve them, ordered.
  var cursor = store.find({});

  // Find is a little different and almost always
  // returns a cursor so we can sort/skip/etc.
  cursor.sort({name: 1});

  // And it's exec() which gives us a promise
  return cursor.exec();
})
.then(function(data) {
  console.log('Found records:');

  data.forEach(function(record) {
    console.log(' -> ' + record.name);
  });
});

Currently the 'nedb' definition is the only built in one.

How does it work?

By default a method will try to guess whether to provide a promise based callback to the delegate object based on how you call it as follows:

  • If the number of arguments you pass is >= the number of arguments defined in the original function then the underlying function will be called directly with no callback. Any return value will be passed through from the underlying function.

  • If the last argument supplied is a function then it assumes you are providing your own callback and the function will be called directly. Any return value will be passed through from the underlying function.

  • If the last argument is not a function then a callback linked to a promise will be appended to the arguments passed to the underlying function. The promise linked to the callback will be returned.

So, as you can see there is plenty of room for error here, and hard to debug issues, so it's best to provide a definition if possible.