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

bluebird-events

v3.0.1

Published

A wrapper around event emitters that returns a bluerbird promise resolved or rejected when certain events are fired.

Downloads

427

Readme

Travis CI Coveralls NPM version Downloads NPM license TS-Standard - Typescript Standard Style Guide Greenkeeper badge

Bluebird-Events

This package wraps an event emitter object and returns a bluebird promise that is either resolved, or rejected based on what events are fired from the emitter.

Note: Bluebird-Events v2.x is NOT backwards compatible with v1.x see changelog for details

Installation

npm install bluebird-events

Optionally run tests:

npm test

Usage

import { promisify } from 'bluebird-events'

const someEmitter = new TestEmitter()

const promise = promisify(someEmitter, {
  resolve: 'success-event-name',
  reject: ['error-event-name', 'error-event-name-2']
})

// Will resolve the promise
someEmitter.emit('success-event-name')

// Will reject the promise with the given error
someEmitter.emit('error-event-name', new Error('Some Error Occurred!'))

API

promisify(emitter, events)

emitter[Object] - Some object that can emit events (usually inherited from Events.EventEmitter)

events[Object] - Contains a mapping of events to listen for

events.resolve[String, Array of Strings, or Boolean] - The name for the event that will cause the promise to resolve (defaults to: 'finish')

events.reject[String, Array of Strings, or Boolean] - The name for the event that will cause the promise to reject (defaults to: 'error')

Returns - a bluebird promise

Note: To disable listening for all resolve or reject events (including default and custom events) just pass in false for the resolve/reject value.

// This promise cannot be resolve successfully via an emitted event
// But it can be rejected via the default 'error' event
promisify(emitter, { resolve: false })

Dependencies

This library is dependent upon bluebird, but because bluebird is so common, there is no need to install it multiple times so bluebird is declared as a peerDependency

Note: bluebird is also declared as a devDependency for running the test suite

Contributors

📋 Contributing Guide

I welcome all pull requests. Please make sure you add appropriate test cases for any features added. Before opening a PR please make sure to run the following scripts:

  • npm run lint checks for code errors and format according to ts-standard
  • npm test make sure all tests pass
  • npm run test-cover make sure the coverage has not decreased from current master