await-to-done
Advanced tools
Comparing version 1.0.2 to 1.1.0
'use strict'; | ||
var tslib = require('tslib'); | ||
function awaitToDone(promise) { | ||
@@ -8,3 +10,9 @@ var promises = []; | ||
} | ||
if (!Array.isArray(promise) && promises.length === 0) { | ||
if (Array.isArray(promise)) { | ||
return Promise.all(promise).then(function (data) { | ||
return [null, data]; | ||
}).catch(function (err) { | ||
return [err, undefined]; | ||
}); | ||
} else if (promises.length === 0) { | ||
return promise.then(function (data) { | ||
@@ -16,3 +24,3 @@ return [null, data]; | ||
} | ||
return Promise.all([].concat(promise).concat(promises)).then(function (data) { | ||
return Promise.all(tslib.__spreadArray([promise], tslib.__read(promises), false)).then(function (data) { | ||
return [null, data]; | ||
@@ -19,0 +27,0 @@ }).catch(function (err) { |
/** | ||
* Async await wrapper for easy error handling | ||
* | ||
* @example | ||
* ```ts | ||
* const bar = () => new Promise<boolean>((resolve, reject) => {}) | ||
* const foo = () => new Promise<string>((resolve, reject) => {}) | ||
* ;(async () => { | ||
* const [err, data] = await awaitToDone(bar()) | ||
* const [err1, data1] = await awaitToDone(bar(), foo()) | ||
* const [err2, data2] = await awaitToDone([bar(), foo()]) | ||
* })() | ||
* ``` | ||
* @since 1.0.0 | ||
@@ -8,11 +18,15 @@ * @author saqqdy | ||
* @param promises - Promise rest params | ||
* @return - [Error, undefined] | [null, data | data[]] | ||
* @return - result | ||
*/ | ||
declare function awaitToDone<T, E = Error>(promise: Promise<T>): Promise<[E, undefined] | [null, T]>; | ||
declare function awaitToDone<T, E = Error>(promise: Array<Promise<T>>): Promise<[E, undefined] | [null, T[]]>; | ||
declare function awaitToDone<P extends readonly unknown[] | [], E = Error>(promise: PromiseAll<P>): Promise<[E, undefined] | [null, P]>; | ||
declare function awaitToDone<T, E = Error>(promise: Promise<T>, ...promises: Array<Promise<T>>): Promise<[E, undefined] | [null, T[]]>; | ||
declare function awaitToDone<T, P extends readonly unknown[] | [], E = Error>(promise: Promise<T>, ...promises: PromiseAll<P>): Promise<[E, undefined] | [null, [T, ...P]]>; | ||
export default awaitToDone; | ||
export declare type PromiseAll<P extends readonly unknown[] | []> = { | ||
-readonly [K in keyof P]: Promise<P[K]>; | ||
}; | ||
export { } |
/*! | ||
* await-to-done v1.0.2 | ||
* await-to-done v1.1.0 | ||
* Async await wrapper for easy error handling | ||
* (c) 2021-2023 saqqdy | ||
* (c) 2021-2024 saqqdy | ||
* Released under the MIT License. | ||
*/ | ||
import { __spreadArray, __read } from 'tslib'; | ||
function awaitToDone(promise) { | ||
@@ -12,3 +14,9 @@ var promises = []; | ||
} | ||
if (!Array.isArray(promise) && promises.length === 0) { | ||
if (Array.isArray(promise)) { | ||
return Promise.all(promise).then(function (data) { | ||
return [null, data]; | ||
}).catch(function (err) { | ||
return [err, undefined]; | ||
}); | ||
} else if (promises.length === 0) { | ||
return promise.then(function (data) { | ||
@@ -20,3 +28,3 @@ return [null, data]; | ||
} | ||
return Promise.all([].concat(promise).concat(promises)).then(function (data) { | ||
return Promise.all(__spreadArray([promise], __read(promises), false)).then(function (data) { | ||
return [null, data]; | ||
@@ -23,0 +31,0 @@ }).catch(function (err) { |
/*! | ||
* await-to-done v1.0.2 | ||
* await-to-done v1.1.0 | ||
* Async await wrapper for easy error handling | ||
* (c) 2021-2023 saqqdy | ||
* (c) 2021-2024 saqqdy | ||
* Released under the MIT License. | ||
*/ | ||
function n(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return Array.isArray(n)||0!==t.length?Promise.all([].concat(n).concat(t)).then((function(n){return[null,n]})).catch((function(n){return[n,void 0]})):n.then((function(n){return[null,n]})).catch((function(n){return[n,void 0]}))}export{n as default}; | ||
import{__spreadArray as n,__read as t}from"tslib";function r(r){for(var u=[],e=1;e<arguments.length;e++)u[e-1]=arguments[e];return Array.isArray(r)?Promise.all(r).then((function(n){return[null,n]})).catch((function(n){return[n,void 0]})):0===u.length?r.then((function(n){return[null,n]})).catch((function(n){return[n,void 0]})):Promise.all(n([r],t(u),!1)).then((function(n){return[null,n]})).catch((function(n){return[n,void 0]}))}export{r as default}; |
@@ -0,1 +1,3 @@ | ||
import { __spreadArray, __read } from 'tslib'; | ||
function awaitToDone(promise) { | ||
@@ -6,3 +8,9 @@ var promises = []; | ||
} | ||
if (!Array.isArray(promise) && promises.length === 0) { | ||
if (Array.isArray(promise)) { | ||
return Promise.all(promise).then(function (data) { | ||
return [null, data]; | ||
}).catch(function (err) { | ||
return [err, undefined]; | ||
}); | ||
} else if (promises.length === 0) { | ||
return promise.then(function (data) { | ||
@@ -14,3 +22,3 @@ return [null, data]; | ||
} | ||
return Promise.all([].concat(promise).concat(promises)).then(function (data) { | ||
return Promise.all(__spreadArray([promise], __read(promises), false)).then(function (data) { | ||
return [null, data]; | ||
@@ -17,0 +25,0 @@ }).catch(function (err) { |
/*! | ||
* await-to-done v1.0.2 | ||
* await-to-done v1.1.0 | ||
* Async await wrapper for easy error handling | ||
* (c) 2021-2023 saqqdy | ||
* (c) 2021-2024 saqqdy | ||
* Released under the MIT License. | ||
@@ -10,2 +10,38 @@ */ | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), | ||
r, | ||
ar = [], | ||
e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} catch (error) { | ||
e = { | ||
error: error | ||
}; | ||
} finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} finally { | ||
if (e) throw e.error; | ||
} | ||
} | ||
return ar; | ||
} | ||
function __spreadArray(to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
} | ||
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
var e = new Error(message); | ||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
}; | ||
function awaitToDone(promise) { | ||
@@ -16,3 +52,9 @@ var promises = []; | ||
} | ||
if (!Array.isArray(promise) && promises.length === 0) { | ||
if (Array.isArray(promise)) { | ||
return Promise.all(promise).then(function (data) { | ||
return [null, data]; | ||
}).catch(function (err) { | ||
return [err, undefined]; | ||
}); | ||
} else if (promises.length === 0) { | ||
return promise.then(function (data) { | ||
@@ -24,3 +66,3 @@ return [null, data]; | ||
} | ||
return Promise.all([].concat(promise).concat(promises)).then(function (data) { | ||
return Promise.all(__spreadArray([promise], __read(promises), false)).then(function (data) { | ||
return [null, data]; | ||
@@ -27,0 +69,0 @@ }).catch(function (err) { |
/*! | ||
* await-to-done v1.0.2 | ||
* await-to-done v1.1.0 | ||
* Async await wrapper for easy error handling | ||
* (c) 2021-2023 saqqdy | ||
* (c) 2021-2024 saqqdy | ||
* Released under the MIT License. | ||
*/ | ||
this.awaitToDone=function(){"use strict";return function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return Array.isArray(n)||0!==t.length?Promise.all([].concat(n).concat(t)).then((function(n){return[null,n]})).catch((function(n){return[n,void 0]})):n.then((function(n){return[null,n]})).catch((function(n){return[n,void 0]}))}}(); | ||
this.awaitToDone=function(){"use strict";return"function"==typeof SuppressedError&&SuppressedError,function(r){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return Array.isArray(r)?Promise.all(r).then((function(r){return[null,r]})).catch((function(r){return[r,void 0]})):0===n.length?r.then((function(r){return[null,r]})).catch((function(r){return[r,void 0]})):Promise.all(function(r,n,t){if(t||2===arguments.length)for(var e,o=0,u=n.length;o<u;o++)!e&&o in n||(e||(e=Array.prototype.slice.call(n,0,o)),e[o]=n[o]);return r.concat(e||Array.prototype.slice.call(n))}([r],function(r,n){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var e,o,u=t.call(r),i=[];try{for(;(void 0===n||n-- >0)&&!(e=u.next()).done;)i.push(e.value)}catch(r){o={error:r}}finally{try{e&&!e.done&&(t=u.return)&&t.call(u)}finally{if(o)throw o.error}}return i}(n),!1)).then((function(r){return[null,r]})).catch((function(r){return[r,void 0]}))}}(); |
{ | ||
"name": "await-to-done", | ||
"description": "Async await wrapper for easy error handling", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"packageManager": "pnpm@8.9.0", | ||
@@ -53,39 +53,39 @@ "main": "dist/index.cjs.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.23.2", | ||
"@babel/preset-env": "^7.23.2", | ||
"@babel/preset-typescript": "^7.23.2", | ||
"@eslint-sets/eslint-config-ts": "^5.10.0", | ||
"@microsoft/api-extractor": "^7.38.2", | ||
"@babel/core": "^7.24.6", | ||
"@babel/preset-env": "^7.24.6", | ||
"@babel/preset-typescript": "^7.24.6", | ||
"@eslint-sets/eslint-config-ts": "^5.13.0", | ||
"@microsoft/api-extractor": "^7.46.2", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-json": "^6.0.1", | ||
"@rollup/plugin-commonjs": "^25.0.8", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"@types/jest": "^29.5.7", | ||
"@types/node": "^20.8.10", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.12.13", | ||
"chalk": "^5.3.0", | ||
"core-js": "^3.33.2", | ||
"core-js": "^3.37.1", | ||
"coveralls": "^3.1.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.52.0", | ||
"fast-glob": "^3.3.1", | ||
"eslint": "^8.57.0", | ||
"fast-glob": "^3.3.2", | ||
"jest": "^29.7.0", | ||
"load-yml": "^1.4.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^3.0.3", | ||
"prettier": "^3.2.5", | ||
"prettier-config-common": "^1.4.0", | ||
"reinstaller": "^3.0.2", | ||
"rm-all": "^1.1.1", | ||
"rollup": "^4.2.0", | ||
"rollup": "^4.18.0", | ||
"rollup-plugin-filesize": "^10.0.0", | ||
"rollup-plugin-inject-code": "^1.1.0", | ||
"rollup-plugin-visualizer": "^5.9.2", | ||
"ts-jest": "^29.1.1", | ||
"ts-morph": "^20.0.0", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
"ts-jest": "^29.1.4", | ||
"ts-morph": "^22.0.0", | ||
"tsnd": "^1.1.0", | ||
"typedoc": "^0.25.3", | ||
"typedoc-plugin-markdown": "^3.17.0", | ||
"typescript": "^5.2.2", | ||
"zx": "^7.2.3" | ||
"typedoc": "^0.25.13", | ||
"typedoc-plugin-markdown": "^4.0.3", | ||
"typescript": "^5.4.5", | ||
"zx": "^8.1.2" | ||
}, | ||
@@ -92,0 +92,0 @@ "sideEffects": false, |
14784
200