@xylabs/error 5.0.94 → 5.0.96

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/README.md CHANGED
@@ -1,46 +1,52 @@
1
1
  # @xylabs/error
2
2
 
3
- [![logo][]](https://xylabs.com)
3
+ [![npm][npm-badge]][npm-link]
4
+ [![license][license-badge]][license-link]
4
5
 
5
- [![main-build][]][main-build-link]
6
- [![npm-badge][]][npm-link]
7
- [![npm-downloads-badge][]][npm-link]
8
- [![jsdelivr-badge][]][jsdelivr-link]
9
- [![npm-license-badge][]](LICENSE)
10
- [![codacy-badge][]][codacy-link]
11
- [![codeclimate-badge][]][codeclimate-link]
12
- [![snyk-badge][]][snyk-link]
13
- [![socket-badge][]][socket-link]
6
+ > Base functionality used throughout XY Labs TypeScript/JavaScript libraries
14
7
 
8
+ ## Install
15
9
 
16
- Base functionality used throughout XY Labs TypeScript/JavaScript libraries
10
+ Using npm:
17
11
 
12
+ ```sh
13
+ npm install {{name}}
14
+ ```
18
15
 
16
+ Using yarn:
19
17
 
20
- ## Reference
18
+ ```sh
19
+ yarn add {{name}}
20
+ ```
21
21
 
22
- **@xylabs/error**
22
+ Using pnpm:
23
23
 
24
- ***
24
+ ```sh
25
+ pnpm add {{name}}
26
+ ```
27
+
28
+ Using bun:
29
+
30
+ ```sh
31
+ bun add {{name}}
32
+ ```
25
33
 
26
- ## Type Aliases
27
34
 
28
- | Type Alias | Description |
29
- | ------ | ------ |
30
- | [AssertConfig](#type-aliases/AssertConfig) | Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. |
35
+ ## License
36
+
37
+ See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
38
+
39
+ ## Reference
31
40
 
32
- ## Functions
41
+ ### packages
33
42
 
34
- | Function | Description |
35
- | ------ | ------ |
36
- | [assertError](#functions/assertError) | Throws an Error based on the assert configuration when a value fails validation. |
37
- | [handleError](#functions/handleError) | Invokes the handler if the value is an Error, otherwise re-throws it. |
38
- | [handleErrorAsync](#functions/handleErrorAsync) | Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it. |
39
- | [isError](#functions/isError) | Type guard that checks whether a value is an Error instance. |
43
+ ### error
40
44
 
41
- ### functions
45
+ ### .temp-typedoc
42
46
 
43
- ### <a id="assertError"></a>assertError
47
+ ### functions
48
+
49
+ ### <a id="assertError"></a>assertError
44
50
 
45
51
  [**@xylabs/error**](#../README)
46
52
 
@@ -48,138 +54,116 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
48
54
 
49
55
  ```ts
50
56
  function assertError(
51
- value: unknown,
52
- assert: AssertConfig | undefined,
53
- defaultMessage: string): undefined;
57
+ value,
58
+ assert,
59
+ defaultMessage): undefined;
54
60
  ```
55
61
 
56
62
  Throws an Error based on the assert configuration when a value fails validation.
57
63
 
58
64
  ## Parameters
59
65
 
60
- | Parameter | Type | Description |
61
- | ------ | ------ | ------ |
62
- | `value` | `unknown` | The value being validated |
63
- | `assert` | [`AssertConfig`](#../type-aliases/AssertConfig) \| `undefined` | Assertion config controlling the error message |
64
- | `defaultMessage` | `string` | Fallback message if no custom message is provided |
65
-
66
- ## Returns
67
-
68
- `undefined`
69
-
70
- ### <a id="handleError"></a>handleError
66
+ ### value
71
67
 
72
- [**@xylabs/error**](#../README)
68
+ `unknown`
73
69
 
74
- ***
70
+ The value being validated
75
71
 
76
- ```ts
77
- function handleError<T>(error: any, handler: (error: Error) => T): T;
78
- ```
72
+ ### assert
79
73
 
80
- Invokes the handler if the value is an Error, otherwise re-throws it.
74
+ [`AssertConfig`](#../type-aliases/AssertConfig) \| `undefined`
81
75
 
82
- ## Type Parameters
76
+ Assertion config controlling the error message
83
77
 
84
- | Type Parameter |
85
- | ------ |
86
- | `T` |
78
+ ### defaultMessage
87
79
 
88
- ## Parameters
80
+ `string`
89
81
 
90
- | Parameter | Type | Description |
91
- | ------ | ------ | ------ |
92
- | `error` | `any` | The caught value to inspect |
93
- | `handler` | (`error`: `Error`) => `T` | Callback invoked with the Error if it is one |
82
+ Fallback message if no custom message is provided
94
83
 
95
84
  ## Returns
96
85
 
97
- `T`
98
-
99
- The handler's return value
86
+ `undefined`
100
87
 
101
- ### <a id="handleErrorAsync"></a>handleErrorAsync
88
+ ### <a id="handleError"></a>handleError
102
89
 
103
90
  [**@xylabs/error**](#../README)
104
91
 
105
92
  ***
106
93
 
107
94
  ```ts
108
- function handleErrorAsync<T>(error: any, handler: (error: Error) => Promise<T>): Promise<T>;
95
+ function handleError<T>(error, handler): T;
109
96
  ```
110
97
 
111
- Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
98
+ Invokes the handler if the value is an Error, otherwise re-throws it.
112
99
 
113
100
  ## Type Parameters
114
101
 
115
- | Type Parameter |
116
- | ------ |
117
- | `T` |
102
+ ### T
103
+
104
+ `T`
118
105
 
119
106
  ## Parameters
120
107
 
121
- | Parameter | Type | Description |
122
- | ------ | ------ | ------ |
123
- | `error` | `any` | The caught value to inspect |
124
- | `handler` | (`error`: `Error`) => `Promise`\<`T`\> | Async callback invoked with the Error if it is one |
108
+ ### error
109
+
110
+ `any`
111
+
112
+ The caught value to inspect
113
+
114
+ ### handler
115
+
116
+ (`error`) => `T`
117
+
118
+ Callback invoked with the Error if it is one
125
119
 
126
120
  ## Returns
127
121
 
128
- `Promise`\<`T`\>
122
+ `T`
129
123
 
130
- The handler's resolved return value
124
+ The handler's return value
131
125
 
132
- ### <a id="isError"></a>isError
126
+ ### <a id="handleErrorAsync"></a>handleErrorAsync
133
127
 
134
128
  [**@xylabs/error**](#../README)
135
129
 
136
130
  ***
137
131
 
138
- ## Call Signature
139
-
140
132
  ```ts
141
- function isError(value: unknown): value is Error;
133
+ function handleErrorAsync<T>(error, handler): Promise<T>;
142
134
  ```
143
135
 
144
- Type guard that checks whether a value is an Error instance.
136
+ Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
145
137
 
146
- ### Parameters
138
+ ## Type Parameters
147
139
 
148
- | Parameter | Type |
149
- | ------ | ------ |
150
- | `value` | `unknown` |
140
+ ### T
151
141
 
152
- ### Returns
142
+ `T`
153
143
 
154
- `value is Error`
144
+ ## Parameters
155
145
 
156
- ## Call Signature
146
+ ### error
157
147
 
158
- ```ts
159
- function isError<T>(value: T): value is Extract<T, Error>;
160
- ```
148
+ `any`
161
149
 
162
- Type guard that checks whether a value is an Error instance.
150
+ The caught value to inspect
163
151
 
164
- ### Type Parameters
152
+ ### handler
165
153
 
166
- | Type Parameter |
167
- | ------ |
168
- | `T` |
154
+ (`error`) => `Promise`\<`T`\>
169
155
 
170
- ### Parameters
156
+ Async callback invoked with the Error if it is one
171
157
 
172
- | Parameter | Type |
173
- | ------ | ------ |
174
- | `value` | `T` |
158
+ ## Returns
175
159
 
176
- ### Returns
160
+ `Promise`\<`T`\>
177
161
 
178
- `value is Extract<T, Error>`
162
+ The handler's resolved return value
179
163
 
180
- ### type-aliases
164
+ ### type-aliases
181
165
 
182
- ### <a id="AssertConfig"></a>AssertConfig
166
+ ### <a id="AssertConfig"></a>AssertConfig
183
167
 
184
168
  [**@xylabs/error**](#../README)
185
169
 
@@ -192,41 +176,7 @@ type AssertConfig = string | AssertCallback | boolean;
192
176
  Configuration for assertion behavior: a static message string, a boolean toggle, or a callback.
193
177
 
194
178
 
195
- Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
196
-
197
- ## Maintainers
198
-
199
- - [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
200
- - [Matt Jones](https://github.com/jonesmac)
201
- - [Joel Carter](https://github.com/JoelBCarter)
202
- - [Jordan Trouw](https://github.com/jordantrouw)
203
-
204
- ## License
205
-
206
- > See the [LICENSE](LICENSE) file for license details
207
-
208
- ## Credits
209
-
210
- [Made with 🔥 and ❄️ by XYLabs](https://xylabs.com)
211
-
212
- [logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
213
-
214
- [main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
215
- [main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
216
179
  [npm-badge]: https://img.shields.io/npm/v/@xylabs/error.svg
217
180
  [npm-link]: https://www.npmjs.com/package/@xylabs/error
218
- [codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698
219
- [codacy-link]: https://www.codacy.com/gh/xylabs/sdk-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=xylabs/sdk-js&utm_campaign=Badge_Grade
220
- [codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
221
- [codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
222
- [snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
223
- [snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
224
-
225
- [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/error
226
- [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/error
227
-
228
- [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/error/badge
229
- [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/error
230
-
231
- [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/error
232
- [socket-link]: https://socket.dev/npm/package/@xylabs/error
181
+ [license-badge]: https://img.shields.io/npm/l/@xylabs/error.svg
182
+ [license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
@@ -1,4 +1,3 @@
1
1
  export * from './assert.ts';
2
2
  export * from './handleError.ts';
3
- export { isError } from '@xylabs/typeof';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
@@ -26,13 +26,9 @@ var handleErrorAsync = async (error, handler) => {
26
26
  throw error;
27
27
  }
28
28
  };
29
-
30
- // src/index.ts
31
- import { isError as isError2 } from "@xylabs/typeof";
32
29
  export {
33
30
  assertError,
34
31
  handleError,
35
- handleErrorAsync,
36
- isError2 as isError
32
+ handleErrorAsync
37
33
  };
38
34
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/assert.ts","../../src/handleError.ts","../../src/index.ts"],"sourcesContent":["import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\n/** Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. */\nexport type AssertConfig = string | AssertCallback | boolean\n\n/**\n * Throws an Error based on the assert configuration when a value fails validation.\n * @param value - The value being validated\n * @param assert - Assertion config controlling the error message\n * @param defaultMessage - Fallback message if no custom message is provided\n */\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isError } from '@xylabs/typeof'\n\n/**\n * Invokes the handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Callback invoked with the Error if it is one\n * @returns The handler's return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleError = <T>(error: any, handler: (error: Error) => T) => {\n if (isError(error)) {\n return handler(error)\n } else {\n throw error\n }\n}\n\n/**\n * Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Async callback invoked with the Error if it is one\n * @returns The handler's resolved return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleErrorAsync = async <T>(error: any, handler: (error: Error) => Promise<T>) => {\n if (isError(error)) {\n return await handler(error)\n } else {\n throw error\n }\n}\n","export * from './assert.ts'\nexport * from './handleError.ts'\nexport { isError } from '@xylabs/typeof'\n"],"mappings":";AAAA,SAAS,UAAU,mBAAmB;AAa/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AC3BA,SAAS,eAAe;AASjB,IAAM,cAAc,CAAI,OAAY,YAAiC;AAC1E,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,QAAQ,KAAK;AAAA,EACtB,OAAO;AACL,UAAM;AAAA,EACR;AACF;AASO,IAAM,mBAAmB,OAAU,OAAY,YAA0C;AAC9F,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,MAAM,QAAQ,KAAK;AAAA,EAC5B,OAAO;AACL,UAAM;AAAA,EACR;AACF;;;AC5BA,SAAS,WAAAA,gBAAe;","names":["isError"]}
1
+ {"version":3,"sources":["../../src/assert.ts","../../src/handleError.ts"],"sourcesContent":["import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\n/** Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. */\nexport type AssertConfig = string | AssertCallback | boolean\n\n/**\n * Throws an Error based on the assert configuration when a value fails validation.\n * @param value - The value being validated\n * @param assert - Assertion config controlling the error message\n * @param defaultMessage - Fallback message if no custom message is provided\n */\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isError } from '@xylabs/typeof'\n\n/**\n * Invokes the handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Callback invoked with the Error if it is one\n * @returns The handler's return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleError = <T>(error: any, handler: (error: Error) => T) => {\n if (isError(error)) {\n return handler(error)\n } else {\n throw error\n }\n}\n\n/**\n * Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Async callback invoked with the Error if it is one\n * @returns The handler's resolved return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleErrorAsync = async <T>(error: any, handler: (error: Error) => Promise<T>) => {\n if (isError(error)) {\n return await handler(error)\n } else {\n throw error\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,mBAAmB;AAa/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AC3BA,SAAS,eAAe;AASjB,IAAM,cAAc,CAAI,OAAY,YAAiC;AAC1E,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,QAAQ,KAAK;AAAA,EACtB,OAAO;AACL,UAAM;AAAA,EACR;AACF;AASO,IAAM,mBAAmB,OAAU,OAAY,YAA0C;AAC9F,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,MAAM,QAAQ,KAAK;AAAA,EAC5B,OAAO;AACL,UAAM;AAAA,EACR;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/error",
3
- "version": "5.0.94",
3
+ "version": "5.0.96",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "error",
@@ -29,12 +29,10 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/neutral/index.d.ts",
32
- "import": "./dist/neutral/index.mjs",
33
32
  "default": "./dist/neutral/index.mjs"
34
33
  },
35
34
  "./package.json": "./package.json"
36
35
  },
37
- "types": "./dist/neutral/index.d.ts",
38
36
  "files": [
39
37
  "dist",
40
38
  "!**/*.bench.*",
@@ -43,18 +41,16 @@
43
41
  "README.md"
44
42
  ],
45
43
  "dependencies": {
46
- "@xylabs/typeof": "~5.0.94"
44
+ "@xylabs/typeof": "~5.0.96"
47
45
  },
48
46
  "devDependencies": {
49
- "@types/node": "^25.5.2",
50
- "@xylabs/ts-scripts-common": "~7.7.3",
51
- "@xylabs/ts-scripts-pnpm": "~7.7.3",
52
- "@xylabs/tsconfig": "~7.7.3",
53
- "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0",
47
+ "@types/node": "^25.6.0",
48
+ "@xylabs/toolchain": "~7.10.4",
49
+ "@xylabs/tsconfig": "~7.10.4",
54
50
  "esbuild": "^0.28.0",
55
51
  "typescript": "^5",
56
- "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
57
- "vitest": "^4.1.2"
52
+ "vite": "^8.0.8",
53
+ "vitest": "^4.1.4"
58
54
  },
59
55
  "engines": {
60
56
  "node": ">=18"