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-tools

v1.8.0

Published

Tools to improve the bluebird promises with control flow and logging.

Downloads

16

Readme

Bluebird Tools

Tools to improve the bluebird promises with control flow and logging.

Install

npm install --save bluebird-tools

How to use

const Promise = require('bluebird-tools');

Control Flow

Promise.iif(condition, success, fail) -> promise

Calls success if pass the condition or calls fail

Promise.iif(x => x === 1, x => console.log('success', x), x => console.log('fail', x));

promise.iif(condition, success, fail) -> promise

Calls success if pass the condition or calls fail

Promise.resolve(1)
   .iif(x => x === 1, x => console.log('success', x), x => console.log('fail', x));

promise.for(start, end, method) -> promise

Calls method passing the iterator and the resolved value

Promise.resolve(123)
   .for(0, 5, (i, val) => console.log('iterator:', i, 'value:', val));
/* output:
iterator: 0 value: 123
iterator: 1 value: 123
iterator: 2 value: 123
iterator: 3 value: 123
iterator: 4 value: 123
*/

promise.when(condition, success) -> promise

Calls success if pass the condition or calls fail

Promise.resolve(1)
   .when(x => x === 1, x => console.log('success', x));

Promise.when(condition, success) -> promise

Calls success if pass the condition or calls fail

Promise.when(x => x === 1, x => console.log('success', x));

promise.unless(condition, fail) -> promise

Calls success if pass the condition or calls fail

Promise.resolve(1)
   .unless(x => x === 2, x => console.log('fail', x));

Promise.unless(condition, fail) -> promise

Calls success if pass the condition or calls fail

Promise.unless(x => x === 2, x => console.log('fail', x));

promise.thenMonitor(name, method) -> promise

Calls method monitoring starting and ending

Promise.resolve()
   .thenMonitor('something', () => executeSomething());
   // logs:
   // - starting something
   // - finishing something - 65.564ms

promise.whenMonitor(name, conditional, method) -> promise

If conditional is true, calls method monitoring starting and ending

Promise.resolve(3)
   .whenMonitor('something', x => x === 3, () => executeSomething());
   // logs:
   // - starting something
   // - finishing something - 1.234ms

promise.unlessMonitor(name, conditional, method) -> promise

If conditional is false, calls method monitoring starting and ending

Promise.resolve(3)
   .unlessMonitor('something', x => x === 2, () => executeSomething());
   // logs:
   // - starting something
   // - finishing something - 1.234ms

promise.iifMonitor(name, conditional, method) -> promise

If conditional is true, calls success or, if is false, calls fail, monitoring starting and ending

Promise.resolve(3)
   .iifMonitor('something', x => x === 3,
    () => executeSomething(), () => executeSomethingElse());
   // logs:
   // - starting something
   // - process something has success
   // - finishing something - 1.234ms

Promise.monitor(name, method) -> promise

Calls method, monitoring starting and ending

Promise.monitor('something', () => executeSomething());
   // logs:
   // - starting something
   // - finishing something - 1.234ms

Logging

Configure logging for all Promise with the logging function. Default levels to call the log:

  • silly
  • debug
  • verbose
  • info
  • warning
  • error

Promise.configureLog(logging)

const winston = require('winston');

// configure winston

Promise.configureLog(function logging(level, text, ...args) {
	winston.log(level, text, ...args);
});

Promise.log(level, text, ...args) -> promise

Promise.log('info', 'testing log', 1, 2, 3);

promise.log(level, text, ...args) -> promise

Promise.resolve().log('info', 'testing log', 1, 2, 3);

promise.silly(text, ...args) -> promise

Promise.resolve().silly('testing log', 1, 2, 3);

promise.debug(text, ...args) -> promise

Promise.resolve().debug('testing log', 1, 2, 3);

promise.verbose(text, ...args) -> promise

Promise.resolve().verbose('testing log', 1, 2, 3);

promise.info(text, ...args) -> promise

Promise.resolve().info('testing log', 1, 2, 3);

promise.warning(text, ...args) -> promise

Promise.resolve().warning('testing log', 1, 2, 3);

promise.error(text, ...args) -> promise

Promise.resolve().error('testing log', 1, 2, 3);

promise.whenLog(level, conditional, text, ...args) -> promise

Promise.resolve(1).whenLog('into', x => x === 1, 'testing log', 1, 2, 3);

promise.unlessLog(level, conditional, text, ...args) -> promise

Promise.resolve(1).unlessLog('into', x => x === 2, 'testing log', 1, 2, 3);

Manipulating promises

Promise.convert(promise) -> promise

Converts a native promise to a BluebirdTools promise

Promise.convert(promise)

promise.isBluebird -> bool

Converts a native promise to a BluebirdTools promise

if (Promise.resolve().isBluebird) { // true
}