Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bluebird-tools

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bluebird-tools

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

  • 1.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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.resolve(1)
   .iif(x => x === 1, x => console.log('success', x), x => console.log('fail', x));
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.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.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
}

Keywords

FAQs

Package last updated on 28 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc