promise-tuple 1.1.0 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +61 -60
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,11 @@ __export(index_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
async function promiseTuple(promise, successCallback, failureCallback) {
|
|
28
|
-
return promise.then(
|
|
28
|
+
return promise.then(
|
|
29
|
+
(result) => (successCallback?.(), [void 0, result])
|
|
30
|
+
).catch(
|
|
31
|
+
(error) => (failureCallback?.(), [error, void 0])
|
|
32
|
+
);
|
|
29
33
|
}
|
|
30
34
|
var index_default = promiseTuple;
|
|
31
35
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["/**\r\n * Handles a promise and returns a tuple with error and result.\r\n *\r\n * This function wraps a promise and returns a tuple containing either an error or a result,\r\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\r\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\r\n *\r\n * @template R - The type of the resolved value. Defaults to `unknown`.\r\n * @template E - The type of the error. Defaults to `unknown`.\r\n * @param promise - The promise to handle.\r\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\r\n * @param failureCallback - Optional callback to execute when the promise rejects.\r\n * @returns A promise that resolves to a tuple containing either an error or a result.\r\n * On success: `[undefined, result]`\r\n * On failure: `[error, undefined]`\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(fetchData());\r\n * if (error) {\r\n * console.error('Error:', error);\r\n * } else {\r\n * console.log('Data:', data);\r\n * }\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(\r\n * fetchData(),\r\n * () => console.log('Success!'),\r\n * () => console.log('Failed!')\r\n * );\r\n */\r\nexport async function promiseTuple<R = unknown, E = unknown>(\r\n
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["/**\r\n * Handles a promise and returns a tuple with error and result.\r\n *\r\n * This function wraps a promise and returns a tuple containing either an error or a result,\r\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\r\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\r\n *\r\n * @template R - The type of the resolved value. Defaults to `unknown`.\r\n * @template E - The type of the error. Defaults to `unknown`.\r\n * @param promise - The promise to handle.\r\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\r\n * @param failureCallback - Optional callback to execute when the promise rejects.\r\n * @returns A promise that resolves to a tuple containing either an error or a result.\r\n * On success: `[undefined, result]`\r\n * On failure: `[error, undefined]`\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(fetchData());\r\n * if (error) {\r\n * console.error('Error:', error);\r\n * } else {\r\n * console.log('Data:', data);\r\n * }\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(\r\n * fetchData(),\r\n * () => console.log('Success!'),\r\n * () => console.log('Failed!')\r\n * );\r\n */\r\nexport async function promiseTuple<R = unknown, E = unknown>(\r\n promise: Promise<R>,\r\n successCallback?: () => void,\r\n failureCallback?: () => void,\r\n): Promise<[E, undefined] | [undefined, R]> {\r\n return promise\r\n .then(\r\n (result) => (successCallback?.(), [undefined, result] as [undefined, R]),\r\n )\r\n .catch(\r\n (error) => (failureCallback?.(), [error, undefined] as [E, undefined]),\r\n );\r\n}\r\n\r\nexport default promiseTuple;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,eAAsB,aACpB,SACA,iBACA,iBAC0C;AAC1C,SAAO,QACJ;AAAA,IACC,CAAC,YAAY,kBAAkB,GAAG,CAAC,QAAW,MAAM;AAAA,EACtD,EACC;AAAA,IACC,CAAC,WAAW,kBAAkB,GAAG,CAAC,OAAO,MAAS;AAAA,EACpD;AACJ;AAEA,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
* () => console.log('Failed!')
|
|
30
30
|
* );
|
|
31
31
|
*/
|
|
32
|
-
declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E | undefined, R
|
|
32
|
+
declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E, undefined] | [undefined, R]>;
|
|
33
33
|
|
|
34
34
|
export { promiseTuple as default, promiseTuple };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
* () => console.log('Failed!')
|
|
30
30
|
* );
|
|
31
31
|
*/
|
|
32
|
-
declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E | undefined, R
|
|
32
|
+
declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E, undefined] | [undefined, R]>;
|
|
33
33
|
|
|
34
34
|
export { promiseTuple as default, promiseTuple };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
async function promiseTuple(promise, successCallback, failureCallback) {
|
|
3
|
-
return promise.then(
|
|
3
|
+
return promise.then(
|
|
4
|
+
(result) => (successCallback?.(), [void 0, result])
|
|
5
|
+
).catch(
|
|
6
|
+
(error) => (failureCallback?.(), [error, void 0])
|
|
7
|
+
);
|
|
4
8
|
}
|
|
5
9
|
var index_default = promiseTuple;
|
|
6
10
|
export {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["/**\r\n * Handles a promise and returns a tuple with error and result.\r\n *\r\n * This function wraps a promise and returns a tuple containing either an error or a result,\r\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\r\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\r\n *\r\n * @template R - The type of the resolved value. Defaults to `unknown`.\r\n * @template E - The type of the error. Defaults to `unknown`.\r\n * @param promise - The promise to handle.\r\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\r\n * @param failureCallback - Optional callback to execute when the promise rejects.\r\n * @returns A promise that resolves to a tuple containing either an error or a result.\r\n * On success: `[undefined, result]`\r\n * On failure: `[error, undefined]`\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(fetchData());\r\n * if (error) {\r\n * console.error('Error:', error);\r\n * } else {\r\n * console.log('Data:', data);\r\n * }\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(\r\n * fetchData(),\r\n * () => console.log('Success!'),\r\n * () => console.log('Failed!')\r\n * );\r\n */\r\nexport async function promiseTuple<R = unknown, E = unknown>(\r\n
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["/**\r\n * Handles a promise and returns a tuple with error and result.\r\n *\r\n * This function wraps a promise and returns a tuple containing either an error or a result,\r\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\r\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\r\n *\r\n * @template R - The type of the resolved value. Defaults to `unknown`.\r\n * @template E - The type of the error. Defaults to `unknown`.\r\n * @param promise - The promise to handle.\r\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\r\n * @param failureCallback - Optional callback to execute when the promise rejects.\r\n * @returns A promise that resolves to a tuple containing either an error or a result.\r\n * On success: `[undefined, result]`\r\n * On failure: `[error, undefined]`\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(fetchData());\r\n * if (error) {\r\n * console.error('Error:', error);\r\n * } else {\r\n * console.log('Data:', data);\r\n * }\r\n *\r\n * @example\r\n * const [error, data] = await promiseTuple(\r\n * fetchData(),\r\n * () => console.log('Success!'),\r\n * () => console.log('Failed!')\r\n * );\r\n */\r\nexport async function promiseTuple<R = unknown, E = unknown>(\r\n promise: Promise<R>,\r\n successCallback?: () => void,\r\n failureCallback?: () => void,\r\n): Promise<[E, undefined] | [undefined, R]> {\r\n return promise\r\n .then(\r\n (result) => (successCallback?.(), [undefined, result] as [undefined, R]),\r\n )\r\n .catch(\r\n (error) => (failureCallback?.(), [error, undefined] as [E, undefined]),\r\n );\r\n}\r\n\r\nexport default promiseTuple;\r\n"],"mappings":";AA+BA,eAAsB,aACpB,SACA,iBACA,iBAC0C;AAC1C,SAAO,QACJ;AAAA,IACC,CAAC,YAAY,kBAAkB,GAAG,CAAC,QAAW,MAAM;AAAA,EACtD,EACC;AAAA,IACC,CAAC,WAAW,kBAAkB,GAAG,CAAC,OAAO,MAAS;AAAA,EACpD;AACJ;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,63 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"sideEffects": false,
|
|
23
|
-
"scripts": {
|
|
24
|
-
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
25
|
-
"build": "tsup index.ts",
|
|
26
|
-
"test": "tsx index.test.ts",
|
|
27
|
-
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
28
|
-
},
|
|
29
|
-
"keywords": [
|
|
30
|
-
"promise",
|
|
31
|
-
"error-handling",
|
|
32
|
-
"async",
|
|
33
|
-
"utility",
|
|
34
|
-
"go-style",
|
|
35
|
-
"tuple",
|
|
36
|
-
"await",
|
|
37
|
-
"typescript"
|
|
38
|
-
],
|
|
39
|
-
"author": "Eduardo DONATO <eduardo.donato@gmail.com>",
|
|
40
|
-
"license": "ISC",
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "git+https://github.com/ebdonato/promise-tuple.git"
|
|
44
|
-
},
|
|
45
|
-
"bugs": {
|
|
46
|
-
"url": "https://github.com/ebdonato/promise-tuple/issues"
|
|
47
|
-
},
|
|
48
|
-
"homepage": "https://github.com/ebdonato/promise-tuple#readme",
|
|
49
|
-
"engines": {
|
|
50
|
-
"node": ">=16"
|
|
51
|
-
},
|
|
52
|
-
"files": [
|
|
53
|
-
"dist",
|
|
54
|
-
"README.md",
|
|
55
|
-
"LICENSE"
|
|
56
|
-
],
|
|
57
|
-
"devDependencies": {
|
|
58
|
-
"@types/node": "^20.0.0",
|
|
59
|
-
"tsup": "^8.5.1",
|
|
60
|
-
"tsx": "^4.21.0",
|
|
61
|
-
"typescript": "^5.9.3"
|
|
2
|
+
"name": "promise-tuple",
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"description": "A utility function for handling promises with Go-like error handling pattern",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./dist/index.d.cts",
|
|
14
|
+
"default": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
62
20
|
}
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
25
|
+
"build": "tsup index.ts",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"promise",
|
|
31
|
+
"error-handling",
|
|
32
|
+
"async",
|
|
33
|
+
"utility",
|
|
34
|
+
"go-style",
|
|
35
|
+
"tuple",
|
|
36
|
+
"await",
|
|
37
|
+
"typescript"
|
|
38
|
+
],
|
|
39
|
+
"author": "Eduardo DONATO <eduardo.donato@gmail.com>",
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/ebdonato/promise-tuple.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/ebdonato/promise-tuple/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/ebdonato/promise-tuple#readme",
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=16"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
],
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^20.0.0",
|
|
59
|
+
"tsup": "^8.5.1",
|
|
60
|
+
"tsx": "^4.21.0",
|
|
61
|
+
"typescript": "^5.9.3",
|
|
62
|
+
"vitest": "^4.0.18"
|
|
63
|
+
}
|
|
63
64
|
}
|