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

bonded

v1.0.0

Published

Wrap Node.js style async callbacks in Promises

Readme

bonded

The bonded module provides functions for wrapping Node.js style calls function(arg_1, ..., function(err, result)) in Promise objects.

Example - Wrap a standard Node.js asynchronous call within a Promise

var bonded = require("bonded"),
    fs = require("fs"),
    fdMaybe, fd;

// create a Promise variant of fs.open
fs.openMaybe = bonded.maybe(fs.open);

// use the function to get a Promised file descriptor
fdMaybe = fs.openMaybe("/tmp/file", "r");

// set the fd once the Promise is fulfilled or display error
fdMaybe
    .then(function(val) {fd = val;})
    .catch(console.error.bind(console));

Example - Wrap within a Promise an asynchronous call which does not pass an error

var bonded = require("bonded"),
    fs = require("fs"),
    existsEventually;

// created a Promise variant of fs.exists
fs.existsEventually = bonded.eventually(fs.exists);

// use the function to get a Promised result
existsEventually = fs.existsEventually("/tmp/file");

// display a message once the Promise is fullfilled
existsEventually.then(function(exists) {
    if (exists) console.log("file exists");
    else console.log("file does not exist");
});

Example - Binding this context

var bonded = require("bonded"),
    nano = require("nano")("http://example.com:5984"),  // nano CouchDB client
    db = nano.db.use("db");

// won't work; nano.db.insert requires 'this' to be bound to 'db'
var insertMaybe = bonded.maybe(db.insert);

// you could do this, of course
var insertMaybe = bonded.maybe(db.insert.bind(db));

// you can also do this with the maybe function
var insertMaybe = bonded.maybe(db.insert, db);

// use the function to insert a document
var insertedMaybe = insertMaybe({foo: 42}, "example_id");

// handle success/failure
insertedMaybe.then(function(inserted) {
    console.log("inserted document", inserted.id, "revision", inserted.rev);
}).catch(function(err) {
    console.error(err);
});

Other Notes

  • what if the callback passes multiple results? (the nano example glosses over this detail; insert passes body and headers to callback)