Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
bluebird-tools
Advanced tools
Readme
Tools to improve the bluebird promises with control flow and logging.
npm install --save bluebird-tools
const Promise = require('bluebird-tools');
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
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
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
Calls success
if pass the condition
or calls fail
Promise.resolve(1)
.when(x => x === 1, x => console.log('success', x));
promise
Calls success
if pass the condition
or calls fail
Promise.when(x => x === 1, x => console.log('success', x));
promise
Calls success
if pass the condition
or calls fail
Promise.resolve(1)
.unless(x => x === 2, x => console.log('fail', x));
promise
Calls success
if pass the condition
or calls fail
Promise.unless(x => x === 2, x => console.log('fail', x));
promise
Calls method
monitoring starting and ending
Promise.resolve()
.thenMonitor('something', () => executeSomething());
// logs:
// - starting something
// - finishing something - 65.564ms
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
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
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
Calls method
, monitoring starting and ending
Promise.monitor('something', () => executeSomething());
// logs:
// - starting something
// - finishing something - 1.234ms
Configure logging for all Promise with the logging
function.
Default levels to call the log:
const winston = require('winston');
// configure winston
Promise.configureLog(function logging(level, text, ...args) {
winston.log(level, text, ...args);
});
promise
Promise.log('info', 'testing log', 1, 2, 3);
promise
Promise.resolve().log('info', 'testing log', 1, 2, 3);
promise
Promise.resolve().silly('testing log', 1, 2, 3);
promise
Promise.resolve().debug('testing log', 1, 2, 3);
promise
Promise.resolve().verbose('testing log', 1, 2, 3);
promise
Promise.resolve().info('testing log', 1, 2, 3);
promise
Promise.resolve().warning('testing log', 1, 2, 3);
promise
Promise.resolve().error('testing log', 1, 2, 3);
promise
Promise.resolve(1).whenLog('into', x => x === 1, 'testing log', 1, 2, 3);
promise
Promise.resolve(1).unlessLog('into', x => x === 2, 'testing log', 1, 2, 3);
promise
Converts a native promise to a BluebirdTools promise
Promise.convert(promise)
bool
Converts a native promise to a BluebirdTools promise
if (Promise.resolve().isBluebird) { // true
}
FAQs
Tools to improve the bluebird promises with control flow and logging.
The npm package bluebird-tools receives a total of 14 weekly downloads. As such, bluebird-tools popularity was classified as not popular.
We found that bluebird-tools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.