bluebird-ff
Advanced tools
Comparing version 2.0.0 to 2.0.1
var fns = require('./fns'); | ||
exports.install = function(target) { | ||
exports.install = function(target, isStatic) { | ||
Object.keys(fns).forEach(function(name) { | ||
target[name] = function() { | ||
return this.then(fns[name].apply(null, arguments)); | ||
}; | ||
if (isStatic) { | ||
target[name] = function() { | ||
var args = [].slice.call(arguments, 0) | ||
return fns[name].apply(null, args.slice(1))(args[0]); | ||
}; | ||
} else { | ||
target[name] = function() { | ||
return this.then(fns[name].apply(null, arguments)); | ||
}; | ||
} | ||
}); | ||
@@ -9,0 +18,0 @@ }; |
@@ -1,48 +0,74 @@ | ||
var util = require('util'); | ||
var util = require('util'); | ||
var Promise = require('./index'); | ||
exports.pif = pif; | ||
exports.when = when; | ||
exports.unless = unless; | ||
exports.and = and; | ||
exports.pif = pif; | ||
exports.when = when; | ||
exports.unless = unless; | ||
exports.and = and; | ||
exports.propsWithErrors = propsWithErrors; | ||
function identity(a) { | ||
return a; | ||
return a; | ||
} | ||
function pif(test, consequent, alternate) { | ||
return function(value) { | ||
return test(value) ? consequent(value) : alternate(value); | ||
}; | ||
return function(value) { | ||
return test(value) ? consequent(value) : alternate(value); | ||
}; | ||
} | ||
function when(test, f) { | ||
return pif(test, f, identity); | ||
return pif(test, f, identity); | ||
} | ||
function unless(test, f) { | ||
return pif(test, identity, f); | ||
return pif(test, identity, f); | ||
} | ||
function and(fn) { | ||
return function(arg) { | ||
if (!arg || !util.isArray(arg) || arg.__ff_and_sig !== true) { | ||
arg = [arg]; | ||
return function(arg) { | ||
if (!arg || !util.isArray(arg) || arg.__ff_and_sig !== true) { | ||
arg = [arg]; | ||
Object.defineProperty(arg, '__ff_and_sig', { | ||
configurable: false, | ||
writable: false, | ||
enumerable: false, | ||
value: true | ||
}); | ||
} | ||
Object.defineProperty(arg, '__ff_and_sig', { | ||
configurable: false, | ||
writable: false, | ||
enumerable: false, | ||
value: true | ||
}); | ||
} | ||
return Promise.resolve(fn.apply(this, arg)) | ||
.then(function(result) { | ||
arg.push(result); | ||
return Promise.resolve(fn.apply(this, arg)) | ||
.then(function(result) { | ||
arg.push(result); | ||
return arg; | ||
}); | ||
}; | ||
return arg; | ||
}); | ||
}; | ||
} | ||
function propsWithErrors() { | ||
return function(_promises){ | ||
var errors = new Promise.AggregateError(); | ||
var safePromises = {}; | ||
return Promise.resolve(_promises).then(function(promises){ | ||
for(var key in promises){ | ||
safePromises[key] = Promise.resolve(promises[key]).catch(pushError); | ||
} | ||
return Promise.props(safePromises).then(function(result){ | ||
if(errors.length > 0){ | ||
throw errors; | ||
} else { | ||
return result; | ||
} | ||
}) | ||
}) | ||
function pushError(err){ | ||
errors.push(err); | ||
return null; | ||
} | ||
} | ||
} |
@@ -5,3 +5,4 @@ var Promise = require("bluebird/js/release/promise")(); | ||
require('./ff').install(Promise.prototype); | ||
require('./ff').install(Promise, true); | ||
require('./ff').install(Promise.prototype, false); | ||
{ | ||
"name": "bluebird-ff", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Functional/Control-Flow utilities for Bluebird", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -56,2 +56,6 @@ # bluebird-ff | ||
## propsWithErrors(promises) | ||
Like Promise.props, but returning AggregateError with each error. | ||
# License | ||
@@ -58,0 +62,0 @@ |
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
9564
15
215
64