@xylabs/assert 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 +118 -92
- package/package.json +6 -10
package/README.md
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
1
|
# @xylabs/assert
|
|
2
2
|
|
|
3
|
-
[![
|
|
3
|
+
[![npm][npm-badge]][npm-link]
|
|
4
|
+
[![license][license-badge]][license-link]
|
|
4
5
|
|
|
5
|
-
|
|
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
|
-
|
|
10
|
+
Using npm:
|
|
17
11
|
|
|
12
|
+
```sh
|
|
13
|
+
npm install {{name}}
|
|
14
|
+
```
|
|
18
15
|
|
|
16
|
+
Using yarn:
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
```sh
|
|
19
|
+
yarn add {{name}}
|
|
20
|
+
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Using pnpm:
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
```sh
|
|
25
|
+
pnpm add {{name}}
|
|
26
|
+
```
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
Using bun:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
bun add {{name}}
|
|
32
|
+
```
|
|
27
33
|
|
|
28
|
-
| Function | Description |
|
|
29
|
-
| ------ | ------ |
|
|
30
|
-
| [assertDefinedEx](#functions/assertDefinedEx) | Implementation of assertDefinedEx that handles all overloads. |
|
|
31
|
-
| [assertEx](#functions/assertEx) | Implementation of assertEx that handles all overloads. |
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
## License
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
|
|
38
|
+
|
|
39
|
+
## Reference
|
|
40
|
+
|
|
41
|
+
### packages
|
|
42
|
+
|
|
43
|
+
### assert
|
|
44
|
+
|
|
45
|
+
### .temp-typedoc
|
|
46
|
+
|
|
47
|
+
### functions
|
|
48
|
+
|
|
49
|
+
### <a id="assertDefinedEx"></a>assertDefinedEx
|
|
36
50
|
|
|
37
51
|
[**@xylabs/assert**](#../README)
|
|
38
52
|
|
|
@@ -43,7 +57,7 @@ Implementation of assertDefinedEx that handles all overloads.
|
|
|
43
57
|
## Call Signature
|
|
44
58
|
|
|
45
59
|
```ts
|
|
46
|
-
function assertDefinedEx<T>(expr
|
|
60
|
+
function assertDefinedEx<T>(expr, messageFunc?): T;
|
|
47
61
|
```
|
|
48
62
|
|
|
49
63
|
Asserts that a value is defined (not undefined) and returns the value.
|
|
@@ -51,16 +65,25 @@ Throws an error if the value is undefined.
|
|
|
51
65
|
|
|
52
66
|
### Type Parameters
|
|
53
67
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
### T
|
|
69
|
+
|
|
70
|
+
`T`
|
|
71
|
+
|
|
72
|
+
The type of value to check
|
|
57
73
|
|
|
58
74
|
### Parameters
|
|
59
75
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
### expr
|
|
77
|
+
|
|
78
|
+
`T` \| `undefined`
|
|
79
|
+
|
|
80
|
+
Expression to be evaluated for being defined
|
|
81
|
+
|
|
82
|
+
### messageFunc?
|
|
83
|
+
|
|
84
|
+
`AssertExMessageFunc`\<`T`\>
|
|
85
|
+
|
|
86
|
+
Function that returns a message for the error if expression is undefined
|
|
64
87
|
|
|
65
88
|
### Returns
|
|
66
89
|
|
|
@@ -87,7 +110,7 @@ const safeConfig = assertDefinedEx(config, () => 'Config failed to load')
|
|
|
87
110
|
## Call Signature
|
|
88
111
|
|
|
89
112
|
```ts
|
|
90
|
-
function assertDefinedEx<T, R>(expr
|
|
113
|
+
function assertDefinedEx<T, R>(expr, errorFunc?): T;
|
|
91
114
|
```
|
|
92
115
|
|
|
93
116
|
Asserts that a value is defined (not undefined) and returns the value.
|
|
@@ -95,17 +118,31 @@ Throws a custom error if the value is undefined.
|
|
|
95
118
|
|
|
96
119
|
### Type Parameters
|
|
97
120
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
### T
|
|
122
|
+
|
|
123
|
+
`T`
|
|
124
|
+
|
|
125
|
+
The type of value to check
|
|
126
|
+
|
|
127
|
+
### R
|
|
128
|
+
|
|
129
|
+
`R` *extends* `Error`
|
|
130
|
+
|
|
131
|
+
The type of error to throw
|
|
102
132
|
|
|
103
133
|
### Parameters
|
|
104
134
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
135
|
+
### expr
|
|
136
|
+
|
|
137
|
+
`T` \| `undefined`
|
|
138
|
+
|
|
139
|
+
Expression to be evaluated for being defined
|
|
140
|
+
|
|
141
|
+
### errorFunc?
|
|
142
|
+
|
|
143
|
+
`AssertExErrorFunc`\<`T`, `R`\>
|
|
144
|
+
|
|
145
|
+
Function that returns a custom error instance if expression is undefined
|
|
109
146
|
|
|
110
147
|
### Returns
|
|
111
148
|
|
|
@@ -124,7 +161,7 @@ Custom error returned by errorFunc
|
|
|
124
161
|
const user = assertDefinedEx(getUser(), () => new UserNotFoundError('User not found'))
|
|
125
162
|
```
|
|
126
163
|
|
|
127
|
-
|
|
164
|
+
### <a id="assertEx"></a>assertEx
|
|
128
165
|
|
|
129
166
|
[**@xylabs/assert**](#../README)
|
|
130
167
|
|
|
@@ -135,7 +172,7 @@ Implementation of assertEx that handles all overloads.
|
|
|
135
172
|
## Call Signature
|
|
136
173
|
|
|
137
174
|
```ts
|
|
138
|
-
function assertEx<T>(expr
|
|
175
|
+
function assertEx<T>(expr, messageFunc?): T;
|
|
139
176
|
```
|
|
140
177
|
|
|
141
178
|
Asserts that an expression is truthy and returns the value.
|
|
@@ -143,16 +180,25 @@ Throws an error if the expression is falsy.
|
|
|
143
180
|
|
|
144
181
|
### Type Parameters
|
|
145
182
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
183
|
+
### T
|
|
184
|
+
|
|
185
|
+
`T`
|
|
186
|
+
|
|
187
|
+
The type of value to check
|
|
149
188
|
|
|
150
189
|
### Parameters
|
|
151
190
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
191
|
+
### expr
|
|
192
|
+
|
|
193
|
+
`T` \| `null` \| `undefined`
|
|
194
|
+
|
|
195
|
+
Expression to be evaluated for truthiness
|
|
196
|
+
|
|
197
|
+
### messageFunc?
|
|
198
|
+
|
|
199
|
+
`AssertExMessageFunc`\<`T`\>
|
|
200
|
+
|
|
201
|
+
Function that returns a message for the error if expression is falsy
|
|
156
202
|
|
|
157
203
|
### Returns
|
|
158
204
|
|
|
@@ -179,7 +225,7 @@ const safeConfig = assertEx(config, () => 'Config failed to load')
|
|
|
179
225
|
## Call Signature
|
|
180
226
|
|
|
181
227
|
```ts
|
|
182
|
-
function assertEx<T, R>(expr
|
|
228
|
+
function assertEx<T, R>(expr, errorFunc?): T;
|
|
183
229
|
```
|
|
184
230
|
|
|
185
231
|
Asserts that an expression is truthy and returns the value.
|
|
@@ -187,17 +233,31 @@ Throws a custom error if the expression is falsy.
|
|
|
187
233
|
|
|
188
234
|
### Type Parameters
|
|
189
235
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
236
|
+
### T
|
|
237
|
+
|
|
238
|
+
`T`
|
|
239
|
+
|
|
240
|
+
The type of value to check
|
|
241
|
+
|
|
242
|
+
### R
|
|
243
|
+
|
|
244
|
+
`R` *extends* `Error`
|
|
245
|
+
|
|
246
|
+
The type of error to throw
|
|
194
247
|
|
|
195
248
|
### Parameters
|
|
196
249
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
250
|
+
### expr
|
|
251
|
+
|
|
252
|
+
`T` \| `null` \| `undefined`
|
|
253
|
+
|
|
254
|
+
Expression to be evaluated for truthiness
|
|
255
|
+
|
|
256
|
+
### errorFunc?
|
|
257
|
+
|
|
258
|
+
`AssertExErrorFunc`\<`T`, `R`\>
|
|
259
|
+
|
|
260
|
+
Function that returns a custom error instance if expression is falsy
|
|
201
261
|
|
|
202
262
|
### Returns
|
|
203
263
|
|
|
@@ -217,41 +277,7 @@ const user = assertEx(getUser(), () => new UserNotFoundError('User not found'))
|
|
|
217
277
|
```
|
|
218
278
|
|
|
219
279
|
|
|
220
|
-
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
221
|
-
|
|
222
|
-
## Maintainers
|
|
223
|
-
|
|
224
|
-
- [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
|
|
225
|
-
- [Matt Jones](https://github.com/jonesmac)
|
|
226
|
-
- [Joel Carter](https://github.com/JoelBCarter)
|
|
227
|
-
- [Jordan Trouw](https://github.com/jordantrouw)
|
|
228
|
-
|
|
229
|
-
## License
|
|
230
|
-
|
|
231
|
-
> See the [LICENSE](LICENSE) file for license details
|
|
232
|
-
|
|
233
|
-
## Credits
|
|
234
|
-
|
|
235
|
-
[Made with 🔥 and ❄️ by XYLabs](https://xylabs.com)
|
|
236
|
-
|
|
237
|
-
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
|
|
238
|
-
|
|
239
|
-
[main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
|
|
240
|
-
[main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
|
|
241
280
|
[npm-badge]: https://img.shields.io/npm/v/@xylabs/assert.svg
|
|
242
281
|
[npm-link]: https://www.npmjs.com/package/@xylabs/assert
|
|
243
|
-
[
|
|
244
|
-
[
|
|
245
|
-
[codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
|
|
246
|
-
[codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
|
|
247
|
-
[snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
|
|
248
|
-
[snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
|
|
249
|
-
|
|
250
|
-
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/assert
|
|
251
|
-
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/assert
|
|
252
|
-
|
|
253
|
-
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/assert/badge
|
|
254
|
-
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/assert
|
|
255
|
-
|
|
256
|
-
[socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/assert
|
|
257
|
-
[socket-link]: https://socket.dev/npm/package/@xylabs/assert
|
|
282
|
+
[license-badge]: https://img.shields.io/npm/l/@xylabs/assert.svg
|
|
283
|
+
[license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/assert",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.96",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -28,12 +28,10 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/neutral/index.d.ts",
|
|
31
|
-
"import": "./dist/neutral/index.mjs",
|
|
32
31
|
"default": "./dist/neutral/index.mjs"
|
|
33
32
|
},
|
|
34
33
|
"./package.json": "./package.json"
|
|
35
34
|
},
|
|
36
|
-
"types": "./dist/neutral/index.d.ts",
|
|
37
35
|
"files": [
|
|
38
36
|
"dist",
|
|
39
37
|
"!**/*.bench.*",
|
|
@@ -42,15 +40,13 @@
|
|
|
42
40
|
"README.md"
|
|
43
41
|
],
|
|
44
42
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^25.
|
|
46
|
-
"@xylabs/
|
|
47
|
-
"@xylabs/
|
|
48
|
-
"@xylabs/tsconfig": "~7.7.3",
|
|
49
|
-
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
43
|
+
"@types/node": "^25.6.0",
|
|
44
|
+
"@xylabs/toolchain": "~7.10.4",
|
|
45
|
+
"@xylabs/tsconfig": "~7.10.4",
|
|
50
46
|
"esbuild": "^0.28.0",
|
|
51
47
|
"typescript": "^5",
|
|
52
|
-
"vite": "^
|
|
53
|
-
"vitest": "^4.1.
|
|
48
|
+
"vite": "^8.0.8",
|
|
49
|
+
"vitest": "^4.1.4"
|
|
54
50
|
},
|
|
55
51
|
"engines": {
|
|
56
52
|
"node": ">=18"
|