try-catch-util 1.0.7 → 1.0.8

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": "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",
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 * 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 * @param input - Function to execute safely without messy try/catch blocks.\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": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GAWA,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"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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",
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 * 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 * @param input - Function to execute safely without messy try/catch blocks.\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": "+EAWA,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"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -9,11 +9,9 @@ export type Failure<E> = {
9
9
  export type Result<T, E extends Error = Error> = Success<T> | Failure<E>;
10
10
  /**
11
11
  * Executes a synchronous or asynchronous function and returns a typed result object.
12
- *
13
12
  * Successful executions resolve with `{ result }`, while thrown errors resolve with
14
13
  * `{ error }`. If a string is thrown, it is converted into an `Error` instance.
15
- *
16
- * @param input - Function to execute safely.
14
+ * @param input - Function to execute safely without messy try/catch blocks.
17
15
  * @returns A promise containing either the function result or the captured error.
18
16
  */
19
17
  export declare function tryCatch<T, E extends Error = Error>(input: () => Promise<T> | T): Promise<Result<T, E>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "try-catch-util",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A simple util to wrap sync/async functions and handle errors type-safely.",
5
5
  "keywords": [
6
6
  "try catch",
@@ -35,7 +35,8 @@
35
35
  "check": "biome check .",
36
36
  "test": "jest",
37
37
  "build": "tsc --build --noEmit && tsx esbuild.config.ts",
38
- "prepublishOnly": "npm run build && npm test"
38
+ "prepublishOnly": "npm run build && npm test",
39
+ "patch": "npm version patch -m \"chore(release): %s [skip ci]\""
39
40
  },
40
41
  "devDependencies": {
41
42
  "@biomejs/biome": "^2.4.16",