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 - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

src/flow-control/for-all.js

4

package.json
{
"name": "bluebird-tools",
"version": "1.7.0",
"version": "1.8.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha tests --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"test": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},

@@ -9,0 +9,0 @@ "repository": {

@@ -31,2 +31,16 @@ # Bluebird Tools

#### promise.for(start, end, method) -> `promise`
Calls `method` passing the `iterator` and the resolved `value`
```js
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`

@@ -33,0 +47,0 @@ Calls `success` if pass the `condition` or calls `fail`

const Promise = require('bluebird');
const now = require('performance-now');
Promise.configureLog = function configureLog(log) {
this._log = function(level, text, ...args) {
log(level, text, ...args);
}
};
require('./flow-control')(Promise);
require('./log')(Promise);
require('./manipulation')(Promise);
require('./monitor')(Promise);
Promise.log = function log(level, text, ...args) {
if (this._log) {
this._log(level, text, ...args);
}
else {
console.log(level, text, ...args);
}
return Promise.resolve();
};
Promise.prototype.log = function log(level, text, ...args) {
return this.tap(() => Promise.log(level, text, ...args));
};
Promise.prototype.silly = function log(text, ...args) {
return this.log('silly', text, ...args);
};
Promise.prototype.debug = function log(text, ...args) {
return this.log('debug', text, ...args);
};
Promise.prototype.verbose = function log(text, ...args) {
return this.log('verbose', text, ...args);
};
Promise.prototype.info = function log(text, ...args) {
return this.log('info', text, ...args);
};
Promise.prototype.warning = function log(text, ...args) {
return this.log('warning', text, ...args);
};
Promise.prototype.error = function log(text, ...args) {
return this.log('error', text, ...args);
};
Promise.prototype.iif = function iif(conditional, success, fail) {
return this.then(
(val) => new Promise(
(resolve) => resolve(conditional(val) ? success(val) : fail(val))));
};
Promise.iif = function iif(conditional, success, fail) {
return new Promise(
(resolve) => resolve(conditional() ? success() : fail()));
};
Promise.prototype.when = function when(conditional, success) {
return this.iif(conditional, success, echo);
};
Promise.when = function when(conditional, success) {
return Promise.iif(conditional, success, echo);
};
Promise.prototype.whenLog = function when(level, conditional, text, ...args) {
return this.then(() => {
if (conditional(this.value())) {
Promise.log(level, text, ...args);
}
return this;
});
};
Promise.prototype.unless = function unless(conditional, fail) {
return this.iif(conditional, echo, fail);
};
Promise.unless = function unless(conditional, fail) {
return Promise.iif(conditional, echo, fail);
};
Promise.prototype.unlessLog = function unless(level, conditional, text, ...args) {
return this.then(() => {
if (!conditional(this.value())) {
Promise.log(level, text, ...args);
}
return this;
}
);
};
Promise.prototype.thenMonitor = function thenMonitor(name, method) {
return this.then(x => {
const start = now();
this.debug('starting', name);
return method(x)
.debug('finished', name, 'in', (now() - start).toFixed(3), 'ms');
});
};
Promise.prototype.iifMonitor = function iifMonitor(name, conditional, success, fail) {
const start = now();
return this.then(
val => new Promise((resolve) => {
this.debug('starting', name);
const cond = conditional(val);
let result;
if (cond) {
this.debug('process', name, 'has success');
result = success(val);
} else {
this.debug('process', name, 'has fail');
result = fail(val);
}
return resolve(result);
}))
.debug('finished', name, 'in', (now() - start).toFixed(3), 'ms');
};
Promise.prototype.whenMonitor = function thenMonitor(name, conditional, method) {
return this.when(conditional, x => {
const start = now();
this.debug('starting', name);
return method(x)
.debug('finished', name, 'in', (now() - start).toFixed(3), 'ms');
});
};
Promise.prototype.unlessMonitor = function unlessMonitor(name, conditional, method) {
return this.unlessLog(conditional, x => {
const start = now();
this.debug('starting', name);
return method(x)
.debug('finished', name, 'in', (now() - start).toFixed(3), 'ms');
});
};
Promise.monitor = function monitor(name, method) {
const start = now();
Promise.log('debug', 'starting', name);
return method()
.debug('finished', name, 'in', (now() - start).toFixed(3), 'ms');
};
Promise.prototype.isBluebird = true;
Promise.convert = function convert(promise) {
return promise.isBluebird
? promise
: new Promise((resolve, reject) => {
promise
.then(resolve)
.catch(reject);
});
};
module.exports = Promise;
function echo(ping) {
return ping;
}

Sorry, the diff of this file is not supported yet

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