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

pify-proto

v0.2.0

Published

Promisify methods on the prototype of an object

Downloads

4

Readme

pify-proto

Promisify methods on the prototype of an object

  • Exclusively for promisfying enumerable methods on a prototype
  • Does not modify the original object prototype; returns a copy with a new prototype*
  • Only include/exclude/multiArgs options (I don't need the others; always open to PRs)

* In order that the lib can operate normally if it uses any method internally (because it will be passing callbacks as per original method signature).


Credit goes to Sindre Sorhus and other contributors of pify, for which this is a fork. Thanks y'all!

Install

$ npm install --save pify-proto

Usage

const pify = require('pify-proto');

class SomeConstructor {
  constructor () {
    this.foo = 'bar'
  }
  
  baz (cb) {
    cb(null, this.foo)
  }
}

// promisify prototype of an object

const inst = pify(new SomeConstructor())

inst.baz().then(console.log.bind(console))
//=> 'foo'

API

pify(input, [promiseModule], [options])

Returns a new object with prototype methods on obj promisified.

input

Type: object

The object to promisify.

promiseModule

Type: function

Custom promise module to use instead of the native one.

Check out pinkie-promise if you need a tiny promise polyfill.

options

include

Type: array of (string|regex)

Methods in a module to promisify. Remaining methods will be left untouched.

exclude

Type: array of (string|regex) Default: [/.+Sync$/]

Methods in a module not to promisify. Methods with names ending with 'Sync' are excluded by default.

multiArgs

Type: boolean Default: false

By default, the promisified methods will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like oauth with prototype methods that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument.

const OAuth = require('oauth').OAuth;
const pify = require('pify-proto');

const oauth = pify(new OAuth(
    'http://blah',
    'http://blah',
    'blah blah'
), {multiArgs: true});

oauth.getOAuthRequestToken()
.then(result => {
	const [ oauth_token, oauth_secret ] = result;
});

Authors & License

pify was created by Sindre Sorhus.

pify-proto was created by Sam Gluck.

pify-proto contributors:

pify-proto is released under the MIT license.