try-catch-util 1.0.2 → 1.0.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/{node/index.cjs → index.cjs} +1 -1
- package/dist/{node/index.cjs.map → index.cjs.map} +1 -1
- package/dist/{neutral/index.js.map → index.js.map} +1 -1
- package/package.json +9 -25
- package/dist/browser/index.js.map +0 -7
- package/dist/neutral/index.d.ts +0 -19
- package/dist/neutral/index.js +0 -2
- package/dist/node/index.d.ts +0 -19
- package/dist/node/index.js +0 -2
- package/dist/node/index.js.map +0 -7
- /package/dist/{browser/index.d.ts → index.d.ts} +0 -0
- /package/dist/{browser/index.js → index.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(e,r)=>o(e,"name",{value:r,configurable:!0});var i=(e,r)=>{for(var t in r)o(e,t,{get:r[t],enumerable:!0})},l=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of c(r))!a.call(e,s)&&s!==t&&o(e,s,{get:()=>r[s],enumerable:!(n=E(r,s))||n.enumerable});return e};var p=e=>l(o({},"__esModule",{value:!0}),e);var y={};i(y,{tryCatch:()=>T});module.exports=p(y);async function T(e){try{return{result:await e()}}catch(r){return{error:typeof r=="string"?new Error(String(r)):r}}}u(T,"tryCatch");
|
|
1
|
+
"use strict";var o=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(e,r)=>o(e,"name",{value:r,configurable:!0});var i=(e,r)=>{for(var t in r)o(e,t,{get:r[t],enumerable:!0})},l=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of c(r))!a.call(e,s)&&s!==t&&o(e,s,{get:()=>r[s],enumerable:!(n=E(r,s))||n.enumerable});return e};var p=e=>l(o({},"__esModule",{value:!0}),e);var y={};i(y,{tryCatch:()=>T});module.exports=p(y);async function T(e){try{return{result:await e()}}catch(r){return{error:typeof r=="string"?new Error(String(r)):r}}}u(T,"tryCatch");
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export type Success<T> = { result: T; error?: never };\nexport type Failure<E> = { result?: never; error: E };\nexport type Result<T, E extends Error = Error> = Success<T> | Failure<E>;\n\n/**\n * Executes a synchronous or asynchronous function and returns a typed result object.\n *\n * Successful executions resolve with `{ result }`, while thrown errors resolve with\n * `{ error }`. If a string is thrown, it is converted into an `Error` instance.\n *\n * @param input - Function to execute safely.\n * @returns A promise containing either the function result or the captured error.\n */\nexport async function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>> {\n try {\n const result = await input();\n return { result };\n } catch (e) {\n const error = typeof e === 'string' ? (new Error(String(e)) as E) : (e as E);\n return { error };\n }\n}\n"],
|
|
5
5
|
"mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GAaA,eAAsBI,EAAqCC,EAAoD,CAC7G,GAAI,CAEF,MAAO,CAAE,OADM,MAAMA,EAAM,CACX,CAClB,OAASC,EAAG,CAEV,MAAO,CAAE,MADK,OAAOA,GAAM,SAAY,IAAI,MAAM,OAAOA,CAAC,CAAC,EAAWA,CACtD,CACjB,CACF,CARsBC,EAAAH,EAAA",
|
|
6
6
|
"names": ["index_exports", "__export", "tryCatch", "__toCommonJS", "tryCatch", "input", "e", "__name"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export type Success<T> = { result: T; error?: never };\nexport type Failure<E> = { result?: never; error: E };\nexport type Result<T, E extends Error = Error> = Success<T> | Failure<E>;\n\n/**\n * Executes a synchronous or asynchronous function and returns a typed result object.\n *\n * Successful executions resolve with `{ result }`, while thrown errors resolve with\n * `{ error }`. If a string is thrown, it is converted into an `Error` instance.\n *\n * @param input - Function to execute safely.\n * @returns A promise containing either the function result or the captured error.\n */\nexport async function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>> {\n try {\n const result = await input();\n return { result };\n } catch (e) {\n const error = typeof e === 'string' ? (new Error(String(e)) as E) : (e as E);\n return { error };\n }\n}\n"],
|
|
5
5
|
"mappings": "+EAaA,eAAsBA,EAAqCC,EAAoD,CAC7G,GAAI,CAEF,MAAO,CAAE,OADM,MAAMA,EAAM,CACX,CAClB,OAASC,EAAG,CAEV,MAAO,CAAE,MADK,OAAOA,GAAM,SAAY,IAAI,MAAM,OAAOA,CAAC,CAAC,EAAWA,CACtD,CACjB,CACF,CARsBC,EAAAH,EAAA",
|
|
6
6
|
"names": ["tryCatch", "input", "e", "__name"]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "try-catch-util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A simple util to wrap sync/async functions and handle errors type-safely.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"try catch",
|
|
@@ -14,31 +14,14 @@
|
|
|
14
14
|
"url": "https://github.com/raghurana/tryCatch"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
|
-
"main": "./dist/
|
|
18
|
-
"
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
21
|
-
"types": "./dist/
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"require": "./dist/node/index.cjs",
|
|
25
|
-
"default": "./dist/neutral/index.js"
|
|
26
|
-
},
|
|
27
|
-
"./node": {
|
|
28
|
-
"types": "./dist/node/index.d.ts",
|
|
29
|
-
"import": "./dist/node/index.js",
|
|
30
|
-
"require": "./dist/node/index.cjs",
|
|
31
|
-
"default": "./dist/node/index.js"
|
|
32
|
-
},
|
|
33
|
-
"./neutral": {
|
|
34
|
-
"types": "./dist/neutral/index.d.ts",
|
|
35
|
-
"import": "./dist/neutral/index.js",
|
|
36
|
-
"default": "./dist/neutral/index.js"
|
|
37
|
-
},
|
|
38
|
-
"./browser": {
|
|
39
|
-
"types": "./dist/browser/index.d.ts",
|
|
40
|
-
"import": "./dist/browser/index.js",
|
|
41
|
-
"default": "./dist/browser/index.js"
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
42
25
|
}
|
|
43
26
|
},
|
|
44
27
|
"files": [
|
|
@@ -52,7 +35,8 @@
|
|
|
52
35
|
"check": "biome check .",
|
|
53
36
|
"test": "jest",
|
|
54
37
|
"build": "tsc --build --noEmit && tsx esbuild.config.ts",
|
|
55
|
-
"prepublishOnly": "npm run build && npm test"
|
|
38
|
+
"prepublishOnly": "npm run build && npm test",
|
|
39
|
+
"publish": "npm version patch && npm publish"
|
|
56
40
|
},
|
|
57
41
|
"devDependencies": {
|
|
58
42
|
"@biomejs/biome": "^2.4.16",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export type Success<T> = { result: T; error?: never };\nexport type Failure<E> = { result?: never; error: E };\nexport type Result<T, E extends Error = Error> = Success<T> | Failure<E>;\n\n/**\n * Executes a synchronous or asynchronous function and returns a typed result object.\n *\n * Successful executions resolve with `{ result }`, while thrown errors resolve with\n * `{ error }`. If a string is thrown, it is converted into an `Error` instance.\n *\n * @param input - Function to execute safely.\n * @returns A promise containing either the function result or the captured error.\n */\nexport async function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>> {\n try {\n const result = await input();\n return { result };\n } catch (e) {\n const error = typeof e === 'string' ? (new Error(String(e)) as E) : (e as E);\n return { error };\n }\n}\n"],
|
|
5
|
-
"mappings": "+EAaA,eAAsBA,EAAqCC,EAAoD,CAC7G,GAAI,CAEF,MAAO,CAAE,OADM,MAAMA,EAAM,CACX,CAClB,OAASC,EAAG,CAEV,MAAO,CAAE,MADK,OAAOA,GAAM,SAAY,IAAI,MAAM,OAAOA,CAAC,CAAC,EAAWA,CACtD,CACjB,CACF,CARsBC,EAAAH,EAAA",
|
|
6
|
-
"names": ["tryCatch", "input", "e", "__name"]
|
|
7
|
-
}
|
package/dist/neutral/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Success<T> = {
|
|
2
|
-
result: T;
|
|
3
|
-
error?: never;
|
|
4
|
-
};
|
|
5
|
-
export type Failure<E> = {
|
|
6
|
-
result?: never;
|
|
7
|
-
error: E;
|
|
8
|
-
};
|
|
9
|
-
export type Result<T, E extends Error = Error> = Success<T> | Failure<E>;
|
|
10
|
-
/**
|
|
11
|
-
* Executes a synchronous or asynchronous function and returns a typed result object.
|
|
12
|
-
*
|
|
13
|
-
* Successful executions resolve with `{ result }`, while thrown errors resolve with
|
|
14
|
-
* `{ error }`. If a string is thrown, it is converted into an `Error` instance.
|
|
15
|
-
*
|
|
16
|
-
* @param input - Function to execute safely.
|
|
17
|
-
* @returns A promise containing either the function result or the captured error.
|
|
18
|
-
*/
|
|
19
|
-
export declare function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>>;
|
package/dist/neutral/index.js
DELETED
package/dist/node/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Success<T> = {
|
|
2
|
-
result: T;
|
|
3
|
-
error?: never;
|
|
4
|
-
};
|
|
5
|
-
export type Failure<E> = {
|
|
6
|
-
result?: never;
|
|
7
|
-
error: E;
|
|
8
|
-
};
|
|
9
|
-
export type Result<T, E extends Error = Error> = Success<T> | Failure<E>;
|
|
10
|
-
/**
|
|
11
|
-
* Executes a synchronous or asynchronous function and returns a typed result object.
|
|
12
|
-
*
|
|
13
|
-
* Successful executions resolve with `{ result }`, while thrown errors resolve with
|
|
14
|
-
* `{ error }`. If a string is thrown, it is converted into an `Error` instance.
|
|
15
|
-
*
|
|
16
|
-
* @param input - Function to execute safely.
|
|
17
|
-
* @returns A promise containing either the function result or the captured error.
|
|
18
|
-
*/
|
|
19
|
-
export declare function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>>;
|
package/dist/node/index.js
DELETED
package/dist/node/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export type Success<T> = { result: T; error?: never };\nexport type Failure<E> = { result?: never; error: E };\nexport type Result<T, E extends Error = Error> = Success<T> | Failure<E>;\n\n/**\n * Executes a synchronous or asynchronous function and returns a typed result object.\n *\n * Successful executions resolve with `{ result }`, while thrown errors resolve with\n * `{ error }`. If a string is thrown, it is converted into an `Error` instance.\n *\n * @param input - Function to execute safely.\n * @returns A promise containing either the function result or the captured error.\n */\nexport async function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>> {\n try {\n const result = await input();\n return { result };\n } catch (e) {\n const error = typeof e === 'string' ? (new Error(String(e)) as E) : (e as E);\n return { error };\n }\n}\n"],
|
|
5
|
-
"mappings": "+EAaA,eAAsBA,EAAqCC,EAAoD,CAC7G,GAAI,CAEF,MAAO,CAAE,OADM,MAAMA,EAAM,CACX,CAClB,OAASC,EAAG,CAEV,MAAO,CAAE,MADK,OAAOA,GAAM,SAAY,IAAI,MAAM,OAAOA,CAAC,CAAC,EAAWA,CACtD,CACjB,CACF,CARsBC,EAAAH,EAAA",
|
|
6
|
-
"names": ["tryCatch", "input", "e", "__name"]
|
|
7
|
-
}
|
|
File without changes
|
|
File without changes
|