@xylabs/assert 2.7.5 → 2.8.0
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/cjs/index.js +8 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/docs.json +306 -40
- package/dist/esm/index.js +8 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +12 -8
package/dist/cjs/index.js
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertEx = void 0;
|
|
4
|
-
|
|
5
|
-
* Error object thrown by assertEx
|
|
6
|
-
*/
|
|
7
|
-
class AssertExError extends Error {
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* Intended for simple null/undefined checks for variables
|
|
12
|
-
*
|
|
13
|
-
* @param expr - Expression to be evaluated for truthiness
|
|
14
|
-
* @param message - Message in Error if expression is false, may be a function that returns a string
|
|
15
|
-
* @throws AssertExError
|
|
16
|
-
* @returns Value of expression
|
|
17
|
-
*/
|
|
18
|
-
const assertEx = (expr, message) => {
|
|
4
|
+
function assertEx(expr, messageOrFunc) {
|
|
19
5
|
if (expr)
|
|
20
6
|
return expr;
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
if (typeof messageOrFunc === 'function') {
|
|
8
|
+
const errorOrMessage = messageOrFunc(expr);
|
|
9
|
+
throw typeof errorOrMessage === 'string' ? Error(errorOrMessage) : errorOrMessage;
|
|
10
|
+
}
|
|
11
|
+
// a string was sent
|
|
12
|
+
throw Error(messageOrFunc);
|
|
13
|
+
}
|
|
23
14
|
exports.assertEx = assertEx;
|
|
24
15
|
// eslint-disable-next-line import/no-default-export
|
|
25
16
|
exports.default = assertEx;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAeA,SAAS,QAAQ,CAA0F,IAAe,EAAE,aAAiB;IAC3I,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IACrB,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;QACvC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;QAC1C,MAAM,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAA;KAClF;IACD,oBAAoB;IACpB,MAAM,KAAK,CAAC,aAAa,CAAC,CAAA;AAC5B,CAAC;AAKQ,4BAAQ;AAHjB,oDAAoD;AACpD,kBAAe,QAAQ,CAAA"}
|
package/dist/docs.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"originalName": "",
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
|
-
"id":
|
|
10
|
+
"id": 26,
|
|
11
11
|
"name": "default",
|
|
12
12
|
"kind": 8388608,
|
|
13
13
|
"kindString": "Reference",
|
|
@@ -15,12 +15,106 @@
|
|
|
15
15
|
"sources": [
|
|
16
16
|
{
|
|
17
17
|
"fileName": "index.ts",
|
|
18
|
-
"line":
|
|
18
|
+
"line": 27,
|
|
19
19
|
"character": 0,
|
|
20
|
-
"url": "https://github.com/xylabs/sdk-js/blob/
|
|
20
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L27"
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
|
-
"target":
|
|
23
|
+
"target": 12
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": 6,
|
|
27
|
+
"name": "AssertExErrorFunc",
|
|
28
|
+
"kind": 4194304,
|
|
29
|
+
"kindString": "Type alias",
|
|
30
|
+
"flags": {},
|
|
31
|
+
"sources": [
|
|
32
|
+
{
|
|
33
|
+
"fileName": "index.ts",
|
|
34
|
+
"line": 2,
|
|
35
|
+
"character": 12,
|
|
36
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L2"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"typeParameters": [
|
|
40
|
+
{
|
|
41
|
+
"id": 10,
|
|
42
|
+
"name": "T",
|
|
43
|
+
"kind": 131072,
|
|
44
|
+
"kindString": "Type parameter",
|
|
45
|
+
"flags": {}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": 11,
|
|
49
|
+
"name": "R",
|
|
50
|
+
"kind": 131072,
|
|
51
|
+
"kindString": "Type parameter",
|
|
52
|
+
"flags": {},
|
|
53
|
+
"type": {
|
|
54
|
+
"type": "reference",
|
|
55
|
+
"name": "Error",
|
|
56
|
+
"qualifiedName": "Error",
|
|
57
|
+
"package": "typescript"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"type": {
|
|
62
|
+
"type": "reflection",
|
|
63
|
+
"declaration": {
|
|
64
|
+
"id": 7,
|
|
65
|
+
"name": "__type",
|
|
66
|
+
"kind": 65536,
|
|
67
|
+
"kindString": "Type literal",
|
|
68
|
+
"flags": {},
|
|
69
|
+
"sources": [
|
|
70
|
+
{
|
|
71
|
+
"fileName": "index.ts",
|
|
72
|
+
"line": 2,
|
|
73
|
+
"character": 52,
|
|
74
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L2"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"signatures": [
|
|
78
|
+
{
|
|
79
|
+
"id": 8,
|
|
80
|
+
"name": "__type",
|
|
81
|
+
"kind": 4096,
|
|
82
|
+
"kindString": "Call signature",
|
|
83
|
+
"flags": {},
|
|
84
|
+
"parameters": [
|
|
85
|
+
{
|
|
86
|
+
"id": 9,
|
|
87
|
+
"name": "value",
|
|
88
|
+
"kind": 32768,
|
|
89
|
+
"kindString": "Parameter",
|
|
90
|
+
"flags": {
|
|
91
|
+
"isOptional": true
|
|
92
|
+
},
|
|
93
|
+
"type": {
|
|
94
|
+
"type": "union",
|
|
95
|
+
"types": [
|
|
96
|
+
{
|
|
97
|
+
"type": "reference",
|
|
98
|
+
"id": 10,
|
|
99
|
+
"name": "T"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"type": "literal",
|
|
103
|
+
"value": null
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"type": {
|
|
110
|
+
"type": "reference",
|
|
111
|
+
"id": 11,
|
|
112
|
+
"name": "R"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
24
118
|
},
|
|
25
119
|
{
|
|
26
120
|
"id": 1,
|
|
@@ -31,9 +125,18 @@
|
|
|
31
125
|
"sources": [
|
|
32
126
|
{
|
|
33
127
|
"fileName": "index.ts",
|
|
34
|
-
"line":
|
|
128
|
+
"line": 1,
|
|
35
129
|
"character": 12,
|
|
36
|
-
"url": "https://github.com/xylabs/sdk-js/blob/
|
|
130
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L1"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"typeParameters": [
|
|
134
|
+
{
|
|
135
|
+
"id": 5,
|
|
136
|
+
"name": "T",
|
|
137
|
+
"kind": 131072,
|
|
138
|
+
"kindString": "Type parameter",
|
|
139
|
+
"flags": {}
|
|
37
140
|
}
|
|
38
141
|
],
|
|
39
142
|
"type": {
|
|
@@ -47,9 +150,9 @@
|
|
|
47
150
|
"sources": [
|
|
48
151
|
{
|
|
49
152
|
"fileName": "index.ts",
|
|
50
|
-
"line":
|
|
51
|
-
"character":
|
|
52
|
-
"url": "https://github.com/xylabs/sdk-js/blob/
|
|
153
|
+
"line": 1,
|
|
154
|
+
"character": 37,
|
|
155
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L1"
|
|
53
156
|
}
|
|
54
157
|
],
|
|
55
158
|
"signatures": [
|
|
@@ -59,26 +162,28 @@
|
|
|
59
162
|
"kind": 4096,
|
|
60
163
|
"kindString": "Call signature",
|
|
61
164
|
"flags": {},
|
|
62
|
-
"typeParameter": [
|
|
63
|
-
{
|
|
64
|
-
"id": 5,
|
|
65
|
-
"name": "T",
|
|
66
|
-
"kind": 131072,
|
|
67
|
-
"kindString": "Type parameter",
|
|
68
|
-
"flags": {}
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
165
|
"parameters": [
|
|
72
166
|
{
|
|
73
167
|
"id": 4,
|
|
74
168
|
"name": "value",
|
|
75
169
|
"kind": 32768,
|
|
76
170
|
"kindString": "Parameter",
|
|
77
|
-
"flags": {
|
|
171
|
+
"flags": {
|
|
172
|
+
"isOptional": true
|
|
173
|
+
},
|
|
78
174
|
"type": {
|
|
79
|
-
"type": "
|
|
80
|
-
"
|
|
81
|
-
|
|
175
|
+
"type": "union",
|
|
176
|
+
"types": [
|
|
177
|
+
{
|
|
178
|
+
"type": "reference",
|
|
179
|
+
"id": 5,
|
|
180
|
+
"name": "T"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"type": "literal",
|
|
184
|
+
"value": null
|
|
185
|
+
}
|
|
186
|
+
]
|
|
82
187
|
}
|
|
83
188
|
}
|
|
84
189
|
],
|
|
@@ -92,7 +197,7 @@
|
|
|
92
197
|
}
|
|
93
198
|
},
|
|
94
199
|
{
|
|
95
|
-
"id":
|
|
200
|
+
"id": 12,
|
|
96
201
|
"name": "assertEx",
|
|
97
202
|
"kind": 64,
|
|
98
203
|
"kindString": "Function",
|
|
@@ -100,14 +205,32 @@
|
|
|
100
205
|
"sources": [
|
|
101
206
|
{
|
|
102
207
|
"fileName": "index.ts",
|
|
103
|
-
"line":
|
|
104
|
-
"character":
|
|
105
|
-
"url": "https://github.com/xylabs/sdk-js/blob/
|
|
208
|
+
"line": 13,
|
|
209
|
+
"character": 9,
|
|
210
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L13"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"fileName": "index.ts",
|
|
214
|
+
"line": 14,
|
|
215
|
+
"character": 9,
|
|
216
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L14"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"fileName": "index.ts",
|
|
220
|
+
"line": 15,
|
|
221
|
+
"character": 9,
|
|
222
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L15"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"fileName": "index.ts",
|
|
226
|
+
"line": 16,
|
|
227
|
+
"character": 9,
|
|
228
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L16"
|
|
106
229
|
}
|
|
107
230
|
],
|
|
108
231
|
"signatures": [
|
|
109
232
|
{
|
|
110
|
-
"id":
|
|
233
|
+
"id": 13,
|
|
111
234
|
"name": "assertEx",
|
|
112
235
|
"kind": 4096,
|
|
113
236
|
"kindString": "Call signature",
|
|
@@ -142,7 +265,7 @@
|
|
|
142
265
|
},
|
|
143
266
|
"typeParameter": [
|
|
144
267
|
{
|
|
145
|
-
"id":
|
|
268
|
+
"id": 14,
|
|
146
269
|
"name": "T",
|
|
147
270
|
"kind": 131072,
|
|
148
271
|
"kindString": "Type parameter",
|
|
@@ -151,7 +274,7 @@
|
|
|
151
274
|
],
|
|
152
275
|
"parameters": [
|
|
153
276
|
{
|
|
154
|
-
"id":
|
|
277
|
+
"id": 15,
|
|
155
278
|
"name": "expr",
|
|
156
279
|
"kind": 32768,
|
|
157
280
|
"kindString": "Parameter",
|
|
@@ -175,14 +298,14 @@
|
|
|
175
298
|
},
|
|
176
299
|
{
|
|
177
300
|
"type": "reference",
|
|
178
|
-
"id":
|
|
301
|
+
"id": 14,
|
|
179
302
|
"name": "T"
|
|
180
303
|
}
|
|
181
304
|
]
|
|
182
305
|
}
|
|
183
306
|
},
|
|
184
307
|
{
|
|
185
|
-
"id":
|
|
308
|
+
"id": 16,
|
|
186
309
|
"name": "message",
|
|
187
310
|
"kind": 32768,
|
|
188
311
|
"kindString": "Parameter",
|
|
@@ -197,25 +320,167 @@
|
|
|
197
320
|
}
|
|
198
321
|
]
|
|
199
322
|
},
|
|
323
|
+
"type": {
|
|
324
|
+
"type": "intrinsic",
|
|
325
|
+
"name": "string"
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
],
|
|
329
|
+
"type": {
|
|
330
|
+
"type": "reference",
|
|
331
|
+
"id": 14,
|
|
332
|
+
"name": "T"
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
"id": 17,
|
|
337
|
+
"name": "assertEx",
|
|
338
|
+
"kind": 4096,
|
|
339
|
+
"kindString": "Call signature",
|
|
340
|
+
"flags": {},
|
|
341
|
+
"typeParameter": [
|
|
342
|
+
{
|
|
343
|
+
"id": 18,
|
|
344
|
+
"name": "T",
|
|
345
|
+
"kind": 131072,
|
|
346
|
+
"kindString": "Type parameter",
|
|
347
|
+
"flags": {}
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
"parameters": [
|
|
351
|
+
{
|
|
352
|
+
"id": 19,
|
|
353
|
+
"name": "expr",
|
|
354
|
+
"kind": 32768,
|
|
355
|
+
"kindString": "Parameter",
|
|
356
|
+
"flags": {
|
|
357
|
+
"isOptional": true
|
|
358
|
+
},
|
|
359
|
+
"type": {
|
|
360
|
+
"type": "union",
|
|
361
|
+
"types": [
|
|
362
|
+
{
|
|
363
|
+
"type": "literal",
|
|
364
|
+
"value": null
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
"type": "reference",
|
|
368
|
+
"id": 18,
|
|
369
|
+
"name": "T"
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"id": 20,
|
|
376
|
+
"name": "messageFunc",
|
|
377
|
+
"kind": 32768,
|
|
378
|
+
"kindString": "Parameter",
|
|
379
|
+
"flags": {
|
|
380
|
+
"isOptional": true
|
|
381
|
+
},
|
|
382
|
+
"type": {
|
|
383
|
+
"type": "reference",
|
|
384
|
+
"id": 1,
|
|
385
|
+
"typeArguments": [
|
|
386
|
+
{
|
|
387
|
+
"type": "reference",
|
|
388
|
+
"id": 18,
|
|
389
|
+
"name": "T"
|
|
390
|
+
}
|
|
391
|
+
],
|
|
392
|
+
"name": "AssertExMessageFunc"
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
],
|
|
396
|
+
"type": {
|
|
397
|
+
"type": "reference",
|
|
398
|
+
"id": 18,
|
|
399
|
+
"name": "T"
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
"id": 21,
|
|
404
|
+
"name": "assertEx",
|
|
405
|
+
"kind": 4096,
|
|
406
|
+
"kindString": "Call signature",
|
|
407
|
+
"flags": {},
|
|
408
|
+
"typeParameter": [
|
|
409
|
+
{
|
|
410
|
+
"id": 22,
|
|
411
|
+
"name": "T",
|
|
412
|
+
"kind": 131072,
|
|
413
|
+
"kindString": "Type parameter",
|
|
414
|
+
"flags": {}
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
"id": 23,
|
|
418
|
+
"name": "R",
|
|
419
|
+
"kind": 131072,
|
|
420
|
+
"kindString": "Type parameter",
|
|
421
|
+
"flags": {},
|
|
422
|
+
"type": {
|
|
423
|
+
"type": "reference",
|
|
424
|
+
"name": "Error",
|
|
425
|
+
"qualifiedName": "Error",
|
|
426
|
+
"package": "typescript"
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
],
|
|
430
|
+
"parameters": [
|
|
431
|
+
{
|
|
432
|
+
"id": 24,
|
|
433
|
+
"name": "expr",
|
|
434
|
+
"kind": 32768,
|
|
435
|
+
"kindString": "Parameter",
|
|
436
|
+
"flags": {
|
|
437
|
+
"isOptional": true
|
|
438
|
+
},
|
|
200
439
|
"type": {
|
|
201
440
|
"type": "union",
|
|
202
441
|
"types": [
|
|
203
442
|
{
|
|
204
|
-
"type": "
|
|
205
|
-
"
|
|
443
|
+
"type": "literal",
|
|
444
|
+
"value": null
|
|
206
445
|
},
|
|
207
446
|
{
|
|
208
447
|
"type": "reference",
|
|
209
|
-
"id":
|
|
210
|
-
"name": "
|
|
448
|
+
"id": 22,
|
|
449
|
+
"name": "T"
|
|
211
450
|
}
|
|
212
451
|
]
|
|
213
452
|
}
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
"id": 25,
|
|
456
|
+
"name": "errorFunc",
|
|
457
|
+
"kind": 32768,
|
|
458
|
+
"kindString": "Parameter",
|
|
459
|
+
"flags": {
|
|
460
|
+
"isOptional": true
|
|
461
|
+
},
|
|
462
|
+
"type": {
|
|
463
|
+
"type": "reference",
|
|
464
|
+
"id": 6,
|
|
465
|
+
"typeArguments": [
|
|
466
|
+
{
|
|
467
|
+
"type": "reference",
|
|
468
|
+
"id": 22,
|
|
469
|
+
"name": "T"
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"type": "reference",
|
|
473
|
+
"id": 23,
|
|
474
|
+
"name": "R"
|
|
475
|
+
}
|
|
476
|
+
],
|
|
477
|
+
"name": "AssertExErrorFunc"
|
|
478
|
+
}
|
|
214
479
|
}
|
|
215
480
|
],
|
|
216
481
|
"type": {
|
|
217
482
|
"type": "reference",
|
|
218
|
-
"id":
|
|
483
|
+
"id": 22,
|
|
219
484
|
"name": "T"
|
|
220
485
|
}
|
|
221
486
|
}
|
|
@@ -226,28 +491,29 @@
|
|
|
226
491
|
{
|
|
227
492
|
"title": "References",
|
|
228
493
|
"children": [
|
|
229
|
-
|
|
494
|
+
26
|
|
230
495
|
]
|
|
231
496
|
},
|
|
232
497
|
{
|
|
233
498
|
"title": "Type Aliases",
|
|
234
499
|
"children": [
|
|
500
|
+
6,
|
|
235
501
|
1
|
|
236
502
|
]
|
|
237
503
|
},
|
|
238
504
|
{
|
|
239
505
|
"title": "Functions",
|
|
240
506
|
"children": [
|
|
241
|
-
|
|
507
|
+
12
|
|
242
508
|
]
|
|
243
509
|
}
|
|
244
510
|
],
|
|
245
511
|
"sources": [
|
|
246
512
|
{
|
|
247
513
|
"fileName": "index.ts",
|
|
248
|
-
"line":
|
|
514
|
+
"line": 1,
|
|
249
515
|
"character": 0,
|
|
250
|
-
"url": "https://github.com/xylabs/sdk-js/blob/
|
|
516
|
+
"url": "https://github.com/xylabs/sdk-js/blob/9ad4029/packages/assert/src/index.ts#L1"
|
|
251
517
|
}
|
|
252
518
|
]
|
|
253
519
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
* Error object thrown by assertEx
|
|
3
|
-
*/
|
|
4
|
-
class AssertExError extends Error {
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* Intended for simple null/undefined checks for variables
|
|
9
|
-
*
|
|
10
|
-
* @param expr - Expression to be evaluated for truthiness
|
|
11
|
-
* @param message - Message in Error if expression is false, may be a function that returns a string
|
|
12
|
-
* @throws AssertExError
|
|
13
|
-
* @returns Value of expression
|
|
14
|
-
*/
|
|
15
|
-
const assertEx = (expr, message) => {
|
|
1
|
+
function assertEx(expr, messageOrFunc) {
|
|
16
2
|
if (expr)
|
|
17
3
|
return expr;
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
if (typeof messageOrFunc === 'function') {
|
|
5
|
+
const errorOrMessage = messageOrFunc(expr);
|
|
6
|
+
throw typeof errorOrMessage === 'string' ? Error(errorOrMessage) : errorOrMessage;
|
|
7
|
+
}
|
|
8
|
+
// a string was sent
|
|
9
|
+
throw Error(messageOrFunc);
|
|
10
|
+
}
|
|
20
11
|
// eslint-disable-next-line import/no-default-export
|
|
21
12
|
export default assertEx;
|
|
22
13
|
export { assertEx };
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAeA,SAAS,QAAQ,CAA0F,IAAe,EAAE,aAAiB;IAC3I,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IACrB,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;QACvC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;QAC1C,MAAM,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAA;KAClF;IACD,oBAAoB;IACpB,MAAM,KAAK,CAAC,aAAa,CAAC,CAAA;AAC5B,CAAC;AAED,oDAAoD;AACpD,eAAe,QAAQ,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type AssertExMessageFunc =
|
|
1
|
+
export type AssertExMessageFunc<T> = (value?: T | null) => string;
|
|
2
|
+
export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R;
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
4
5
|
* Intended for simple null/undefined checks for variables
|
|
@@ -8,7 +9,9 @@ export type AssertExMessageFunc = <T>(value: T) => string;
|
|
|
8
9
|
* @throws AssertExError
|
|
9
10
|
* @returns Value of expression
|
|
10
11
|
*/
|
|
11
|
-
declare
|
|
12
|
+
declare function assertEx<T>(expr?: T | null, message?: string): T;
|
|
13
|
+
declare function assertEx<T>(expr?: T | null, messageFunc?: AssertExMessageFunc<T>): T;
|
|
14
|
+
declare function assertEx<T, R extends Error>(expr?: T | null, errorFunc?: AssertExErrorFunc<T, R>): T;
|
|
12
15
|
export default assertEx;
|
|
13
16
|
export { assertEx };
|
|
14
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,MAAM,CAAA;AACjE,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAA;AAE3E;;;;;;;;GAQG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;AAC1D,iBAAS,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,WAAW,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAC9E,iBAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAY9F,eAAe,QAAQ,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"./package.json": "./package.json"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@xylabs/ts-scripts-yarn3": "^2.
|
|
37
|
+
"@xylabs/ts-scripts-yarn3": "^2.17.13"
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://xylabs.com",
|
|
40
40
|
"keywords": [
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
52
52
|
},
|
|
53
53
|
"sideEffects": false,
|
|
54
|
-
"version": "2.
|
|
54
|
+
"version": "2.8.0"
|
|
55
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
class AssertExError extends Error {}
|
|
5
|
-
|
|
6
|
-
export type AssertExMessageFunc = <T>(value: T) => string
|
|
1
|
+
export type AssertExMessageFunc<T> = (value?: T | null) => string
|
|
2
|
+
export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
*
|
|
@@ -14,9 +10,17 @@ export type AssertExMessageFunc = <T>(value: T) => string
|
|
|
14
10
|
* @throws AssertExError
|
|
15
11
|
* @returns Value of expression
|
|
16
12
|
*/
|
|
17
|
-
|
|
13
|
+
function assertEx<T>(expr?: T | null, message?: string): T
|
|
14
|
+
function assertEx<T>(expr?: T | null, messageFunc?: AssertExMessageFunc<T>): T
|
|
15
|
+
function assertEx<T, R extends Error>(expr?: T | null, errorFunc?: AssertExErrorFunc<T, R>): T
|
|
16
|
+
function assertEx<T, R extends Error, P extends string | AssertExMessageFunc<T> | AssertExErrorFunc<T, R>>(expr?: T | null, messageOrFunc?: P): T {
|
|
18
17
|
if (expr) return expr
|
|
19
|
-
|
|
18
|
+
if (typeof messageOrFunc === 'function') {
|
|
19
|
+
const errorOrMessage = messageOrFunc(expr)
|
|
20
|
+
throw typeof errorOrMessage === 'string' ? Error(errorOrMessage) : errorOrMessage
|
|
21
|
+
}
|
|
22
|
+
// a string was sent
|
|
23
|
+
throw Error(messageOrFunc)
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
// eslint-disable-next-line import/no-default-export
|