bluebird-tools
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "bluebird-tools", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -29,4 +29,5 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^3.2.0" | ||
} | ||
} |
@@ -100,2 +100,12 @@ # Bluebird Tools | ||
#### promise.whenLog(level, conditional, text, ...args) -> `promise` | ||
```js | ||
Promise.resolve(1).whenLog('into', x => x === 1, 'testing log', 1, 2, 3); | ||
``` | ||
#### promise.unlessLog(level, conditional, text, ...args) -> `promise` | ||
```js | ||
Promise.resolve(1).unlessLog('into', x => x === 2, 'testing log', 1, 2, 3); | ||
``` | ||
### Manipulating promises | ||
@@ -102,0 +112,0 @@ |
@@ -58,2 +58,9 @@ const Promise = require('bluebird'); | ||
Promise.prototype.whenLog = function when(level, conditional, text, ...args) { | ||
if (conditional(this.value())) { | ||
Promise.log(level, text, ...args); | ||
} | ||
return this; | ||
}; | ||
Promise.prototype.unless = function unless(conditional, fail) { | ||
@@ -63,2 +70,9 @@ return this.iif(conditional, echo, fail); | ||
Promise.prototype.unlessLog = function unless(level, conditional, text, ...args) { | ||
if (!conditional(this.value())) { | ||
Promise.log(level, text, ...args); | ||
} | ||
return this; | ||
}; | ||
Promise.convert = function convert(promise) { | ||
@@ -65,0 +79,0 @@ return new Promise((resolve, reject) => { |
@@ -0,0 +0,0 @@ const Promise = require('../src'); |
@@ -254,2 +254,30 @@ const Promise = require('../src'); | ||
}); | ||
context('#whenLog', () => { | ||
it('when the result is true, must log', (done) => { | ||
const level = 'error'; | ||
const message = 'log test'; | ||
Promise.configureLog((l, msg) => { | ||
assert.equal(l, level); | ||
assert.equal(msg, message); | ||
done(); | ||
}); | ||
Promise.resolve(3) | ||
.whenLog(level, x => x === 3, message) | ||
}); | ||
it('when the result is false, must not execute the method', (done) => { | ||
const level = 'error'; | ||
const message = 'log test'; | ||
Promise.configureLog(() => { | ||
done({ message: 'has logged' }); | ||
}); | ||
Promise.resolve(2) | ||
.whenLog(level, x => x === 3, message) | ||
.then(() => done()); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16823
8
368
116
2