@xylabs/promise
Advanced tools
Comparing version 2.11.0 to 2.11.1
'use strict'; | ||
/** | ||
* For use with Promise.allSettled to filter only successful results | ||
* @param val | ||
* @returns | ||
*/ | ||
const fulfilled = (val) => { | ||
return val.status === 'fulfilled'; | ||
}; | ||
var fulfilled = require('./fulfilled.js'); | ||
var fulfilledValues = require('./fulfilledValues.js'); | ||
var rejected = require('./rejected.js'); | ||
/** | ||
* For use with Promise.allSettled to reduce to only successful result values | ||
* @example <caption>Casting the initialValue provided to reduce</caption> | ||
* const resolved = Promise.resolve('resolved') | ||
* const rejected = Promise.reject('rejected') | ||
* const settled = await Promise.allSettled([resolved, rejected]) | ||
* const results = settled.reduce(fulfilledValues, [] as string[]) | ||
* // results === [ 'resolved' ] | ||
* @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption> | ||
* const resolved = Promise.resolve('resolved') | ||
* const rejected = Promise.reject('rejected') | ||
* const settled = await Promise.allSettled([resolved, rejected]) | ||
* const results = settled.reduce<string[]>(fulfilledValues, []) | ||
* // results === [ 'resolved' ] | ||
* @param previousValue | ||
* @param currentValue | ||
* @returns | ||
*/ | ||
const fulfilledValues = (previousValue, currentValue) => { | ||
if (currentValue.status === 'fulfilled') | ||
previousValue.push(currentValue.value); | ||
return previousValue; | ||
}; | ||
/** | ||
* For use with Promise.allSettled to filter only rejected results | ||
* @param val | ||
* @returns | ||
*/ | ||
const rejected = (val) => { | ||
return val.status === 'rejected'; | ||
}; | ||
exports.fulfilled = fulfilled; | ||
exports.fulfilledValues = fulfilledValues; | ||
exports.rejected = rejected; | ||
exports.fulfilled = fulfilled.fulfilled; | ||
exports.fulfilledValues = fulfilledValues.fulfilledValues; | ||
exports.rejected = rejected.rejected; | ||
//# sourceMappingURL=index.js.map |
@@ -51,4 +51,4 @@ { | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.15", | ||
"@xylabs/tsconfig": "^3.0.0-rc.15" | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.16", | ||
"@xylabs/tsconfig": "^3.0.0-rc.16" | ||
}, | ||
@@ -63,3 +63,3 @@ "publishConfig": { | ||
"sideEffects": false, | ||
"version": "2.11.0" | ||
"version": "2.11.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
21048
33
182