@xylabs/promise 5.0.95 → 5.0.97

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,69 +1,52 @@
1
1
  # @xylabs/promise
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/promise**
22
+ Using pnpm:
23
23
 
24
- ***
24
+ ```sh
25
+ pnpm add {{name}}
26
+ ```
25
27
 
26
- ## Classes
28
+ Using bun:
27
29
 
28
- | Class | Description |
29
- | ------ | ------ |
30
- | [PromiseEx](#classes/PromiseEx) | An extended Promise that carries an optional attached value and supports cancellation. The value can be inspected via the `then` or `value` methods to conditionally cancel. |
30
+ ```sh
31
+ bun add {{name}}
32
+ ```
31
33
 
32
- ## Interfaces
33
34
 
34
- | Interface | Description |
35
- | ------ | ------ |
36
- | [PromiseType](#interfaces/PromiseType) | An interface representing any thenable (promise-like) object. |
35
+ ## License
37
36
 
38
- ## Type Aliases
37
+ See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
39
38
 
40
- | Type Alias | Description |
41
- | ------ | ------ |
42
- | [PromiseExSubFunc](#type-aliases/PromiseExSubFunc) | A resolve/reject callback used within PromiseEx. |
43
- | [PromiseExFunc](#type-aliases/PromiseExFunc) | The executor function passed to the PromiseEx constructor. |
44
- | [PromiseExValueFunc](#type-aliases/PromiseExValueFunc) | A callback that inspects the attached value and returns whether to cancel the promise. |
45
- | [Promisable](#type-aliases/Promisable) | A value that may be a Promise, PromiseEx, or a plain synchronous value. |
46
- | [PromisableArray](#type-aliases/PromisableArray) | A Promisable that resolves to an array. |
47
- | [OptionalPromisable](#type-aliases/OptionalPromisable) | A Promisable that may resolve to undefined. |
48
- | [OptionalPromisableArray](#type-aliases/OptionalPromisableArray) | A Promisable array where elements may be undefined. |
49
- | [NullablePromisable](#type-aliases/NullablePromisable) | A Promisable that may resolve to null. |
50
- | [NullablePromisableArray](#type-aliases/NullablePromisableArray) | A Promisable array where elements may be null. |
51
- | [AsyncMutex](#type-aliases/AsyncMutex) | - |
52
- | [AnyNonPromise](#type-aliases/AnyNonPromise) | Any non-promise typed value, excluding thenables. |
39
+ ## Reference
53
40
 
54
- ## Functions
41
+ ### packages
55
42
 
56
- | Function | Description |
57
- | ------ | ------ |
58
- | [fulfilled](#functions/fulfilled) | For use with Promise.allSettled to filter only successful results |
59
- | [fulfilledValues](#functions/fulfilledValues) | For use with Promise.allSettled to reduce to only successful result values |
60
- | [rejected](#functions/rejected) | For use with Promise.allSettled to filter only rejected results |
61
- | [toPromise](#functions/toPromise) | Wraps a value in a Promise if it is not already one. |
62
- | [isPromise](#functions/isPromise) | Type guard that checks whether a value is a Promise instance. |
43
+ ### promise
63
44
 
64
- ### classes
45
+ ### .temp-typedoc
65
46
 
66
- ### <a id="PromiseEx"></a>PromiseEx
47
+ ### classes
48
+
49
+ ### <a id="PromiseEx"></a>PromiseEx
67
50
 
68
51
  [**@xylabs/promise**](#../README)
69
52
 
@@ -78,25 +61,31 @@ The value can be inspected via the `then` or `value` methods to conditionally ca
78
61
 
79
62
  ## Type Parameters
80
63
 
81
- | Type Parameter | Default type |
82
- | ------ | ------ |
83
- | `T` | - |
84
- | `V` | `void` |
64
+ ### T
65
+
66
+ `T`
67
+
68
+ ### V
69
+
70
+ `V` = `void`
85
71
 
86
72
  ## Constructors
87
73
 
88
74
  ### Constructor
89
75
 
90
76
  ```ts
91
- new PromiseEx<T, V>(func: PromiseExFunc<T>, value?: V): PromiseEx<T, V>;
77
+ new PromiseEx<T, V>(func, value?): PromiseEx<T, V>;
92
78
  ```
93
79
 
94
80
  ### Parameters
95
81
 
96
- | Parameter | Type |
97
- | ------ | ------ |
98
- | `func` | [`PromiseExFunc`](#../type-aliases/PromiseExFunc)\<`T`\> |
99
- | `value?` | `V` |
82
+ #### func
83
+
84
+ [`PromiseExFunc`](#../type-aliases/PromiseExFunc)\<`T`\>
85
+
86
+ #### value?
87
+
88
+ `V`
100
89
 
101
90
  ### Returns
102
91
 
@@ -110,9 +99,13 @@ Promise<T>.constructor
110
99
 
111
100
  ## Properties
112
101
 
113
- | Property | Type | Description |
114
- | ------ | ------ | ------ |
115
- | <a id="cancelled"></a> `cancelled?` | `boolean` | Whether the promise has been cancelled via a value callback. |
102
+ ### cancelled?
103
+
104
+ ```ts
105
+ optional cancelled?: boolean;
106
+ ```
107
+
108
+ Whether the promise has been cancelled via a value callback.
116
109
 
117
110
  ## Methods
118
111
 
@@ -120,29 +113,40 @@ Promise<T>.constructor
120
113
 
121
114
  ```ts
122
115
  then<TResult1, TResult2>(
123
- onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1> | null,
124
- onrejected?:
125
- | (reason: unknown) => TResult2 | PromiseLike<TResult2>
126
- | null,
127
- onvalue?: (value?: V) => boolean): Promise<TResult1 | TResult2>;
116
+ onfulfilled?,
117
+ onrejected?,
118
+ onvalue?): Promise<TResult1 | TResult2>;
128
119
  ```
129
120
 
130
121
  Attaches callbacks for the resolution and/or rejection of the Promise.
131
122
 
132
123
  ### Type Parameters
133
124
 
134
- | Type Parameter | Default type |
135
- | ------ | ------ |
136
- | `TResult1` | `T` |
137
- | `TResult2` | `never` |
125
+ #### TResult1
126
+
127
+ `TResult1` = `T`
128
+
129
+ #### TResult2
130
+
131
+ `TResult2` = `never`
138
132
 
139
133
  ### Parameters
140
134
 
141
- | Parameter | Type | Description |
142
- | ------ | ------ | ------ |
143
- | `onfulfilled?` | (`value`: `T`) => `TResult1` \| `PromiseLike`\<`TResult1`\> \| `null` | The callback to execute when the Promise is resolved. |
144
- | `onrejected?` | \| (`reason`: `unknown`) => `TResult2` \| `PromiseLike`\<`TResult2`\> \| `null` | The callback to execute when the Promise is rejected. |
145
- | `onvalue?` | (`value?`: `V`) => `boolean` | - |
135
+ #### onfulfilled?
136
+
137
+ ((`value`) => `TResult1` \| `PromiseLike`\<`TResult1`\>) \| `null`
138
+
139
+ The callback to execute when the Promise is resolved.
140
+
141
+ #### onrejected?
142
+
143
+ ((`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\>) \| `null`
144
+
145
+ The callback to execute when the Promise is rejected.
146
+
147
+ #### onvalue?
148
+
149
+ (`value?`) => `boolean`
146
150
 
147
151
  ### Returns
148
152
 
@@ -161,16 +165,18 @@ Promise.then
161
165
  ### value()
162
166
 
163
167
  ```ts
164
- value(onvalue?: (value?: V) => boolean): PromiseEx<T, V>;
168
+ value(onvalue?): PromiseEx<T, V>;
165
169
  ```
166
170
 
167
171
  Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
168
172
 
169
173
  ### Parameters
170
174
 
171
- | Parameter | Type | Description |
172
- | ------ | ------ | ------ |
173
- | `onvalue?` | (`value?`: `V`) => `boolean` | A callback that receives the attached value and returns whether to cancel. |
175
+ #### onvalue?
176
+
177
+ (`value?`) => `boolean`
178
+
179
+ A callback that receives the attached value and returns whether to cancel.
174
180
 
175
181
  ### Returns
176
182
 
@@ -178,60 +184,63 @@ Inspects the attached value via the callback; if it returns true, marks the prom
178
184
 
179
185
  This instance for chaining.
180
186
 
181
- ### functions
187
+ ### functions
182
188
 
183
- ### <a id="fulfilled"></a>fulfilled
189
+ ### <a id="fulfilled"></a>fulfilled
184
190
 
185
191
  [**@xylabs/promise**](#../README)
186
192
 
187
193
  ***
188
194
 
189
195
  ```ts
190
- function fulfilled<T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T>;
196
+ function fulfilled<T>(val): val is PromiseFulfilledResult<T>;
191
197
  ```
192
198
 
193
199
  For use with Promise.allSettled to filter only successful results
194
200
 
195
201
  ## Type Parameters
196
202
 
197
- | Type Parameter |
198
- | ------ |
199
- | `T` |
203
+ ### T
204
+
205
+ `T`
200
206
 
201
207
  ## Parameters
202
208
 
203
- | Parameter | Type | Description |
204
- | ------ | ------ | ------ |
205
- | `val` | `PromiseSettledResult`\<`T`\> | - |
209
+ ### val
210
+
211
+ `PromiseSettledResult`\<`T`\>
206
212
 
207
213
  ## Returns
208
214
 
209
215
  `val is PromiseFulfilledResult<T>`
210
216
 
211
- ### <a id="fulfilledValues"></a>fulfilledValues
217
+ ### <a id="fulfilledValues"></a>fulfilledValues
212
218
 
213
219
  [**@xylabs/promise**](#../README)
214
220
 
215
221
  ***
216
222
 
217
223
  ```ts
218
- function fulfilledValues<T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[];
224
+ function fulfilledValues<T>(previousValue, currentValue): T[];
219
225
  ```
220
226
 
221
227
  For use with Promise.allSettled to reduce to only successful result values
222
228
 
223
229
  ## Type Parameters
224
230
 
225
- | Type Parameter |
226
- | ------ |
227
- | `T` |
231
+ ### T
232
+
233
+ `T`
228
234
 
229
235
  ## Parameters
230
236
 
231
- | Parameter | Type | Description |
232
- | ------ | ------ | ------ |
233
- | `previousValue` | `T`[] | - |
234
- | `currentValue` | `PromiseSettledResult`\<`T`\> | - |
237
+ ### previousValue
238
+
239
+ `T`[]
240
+
241
+ ### currentValue
242
+
243
+ `PromiseSettledResult`\<`T`\>
235
244
 
236
245
  ## Returns
237
246
 
@@ -255,105 +264,59 @@ const results = settled.reduce<string[]>(fulfilledValues, [])
255
264
  // results === [ 'resolved' ]
256
265
  ```
257
266
 
258
- ### <a id="isPromise"></a>isPromise
259
-
260
- [**@xylabs/promise**](#../README)
261
-
262
- ***
263
-
264
- ## Call Signature
265
-
266
- ```ts
267
- function isPromise(value: unknown): value is Promise<unknown>;
268
- ```
269
-
270
- Type guard that checks whether a value is a Promise instance.
271
-
272
- ### Parameters
273
-
274
- | Parameter | Type |
275
- | ------ | ------ |
276
- | `value` | `unknown` |
277
-
278
- ### Returns
279
-
280
- `value is Promise<unknown>`
281
-
282
- ## Call Signature
283
-
284
- ```ts
285
- function isPromise<T>(value: T): value is Extract<T, Promise<unknown>>;
286
- ```
287
-
288
- Type guard that checks whether a value is a Promise instance.
289
-
290
- ### Type Parameters
291
-
292
- | Type Parameter |
293
- | ------ |
294
- | `T` |
295
-
296
- ### Parameters
297
-
298
- | Parameter | Type |
299
- | ------ | ------ |
300
- | `value` | `T` |
301
-
302
- ### Returns
303
-
304
- `value is Extract<T, Promise<unknown>>`
305
-
306
- ### <a id="rejected"></a>rejected
267
+ ### <a id="rejected"></a>rejected
307
268
 
308
269
  [**@xylabs/promise**](#../README)
309
270
 
310
271
  ***
311
272
 
312
273
  ```ts
313
- function rejected<T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult;
274
+ function rejected<T>(val): val is PromiseRejectedResult;
314
275
  ```
315
276
 
316
277
  For use with Promise.allSettled to filter only rejected results
317
278
 
318
279
  ## Type Parameters
319
280
 
320
- | Type Parameter |
321
- | ------ |
322
- | `T` |
281
+ ### T
282
+
283
+ `T`
323
284
 
324
285
  ## Parameters
325
286
 
326
- | Parameter | Type | Description |
327
- | ------ | ------ | ------ |
328
- | `val` | `PromiseSettledResult`\<`T`\> | - |
287
+ ### val
288
+
289
+ `PromiseSettledResult`\<`T`\>
329
290
 
330
291
  ## Returns
331
292
 
332
293
  `val is PromiseRejectedResult`
333
294
 
334
- ### <a id="toPromise"></a>toPromise
295
+ ### <a id="toPromise"></a>toPromise
335
296
 
336
297
  [**@xylabs/promise**](#../README)
337
298
 
338
299
  ***
339
300
 
340
301
  ```ts
341
- function toPromise<T>(value: Promisable<T>): Promise<T>;
302
+ function toPromise<T>(value): Promise<T>;
342
303
  ```
343
304
 
344
305
  Wraps a value in a Promise if it is not already one.
345
306
 
346
307
  ## Type Parameters
347
308
 
348
- | Type Parameter |
349
- | ------ |
350
- | `T` |
309
+ ### T
310
+
311
+ `T`
351
312
 
352
313
  ## Parameters
353
314
 
354
- | Parameter | Type | Description |
355
- | ------ | ------ | ------ |
356
- | `value` | [`Promisable`](#../type-aliases/Promisable)\<`T`\> | A value that may or may not be a Promise. |
315
+ ### value
316
+
317
+ [`Promisable`](#../type-aliases/Promisable)\<`T`\>
318
+
319
+ A value that may or may not be a Promise.
357
320
 
358
321
  ## Returns
359
322
 
@@ -361,9 +324,9 @@ Wraps a value in a Promise if it is not already one.
361
324
 
362
325
  A Promise resolving to the value.
363
326
 
364
- ### interfaces
327
+ ### interfaces
365
328
 
366
- ### <a id="PromiseType"></a>PromiseType
329
+ ### <a id="PromiseType"></a>PromiseType
367
330
 
368
331
  [**@xylabs/promise**](#../README)
369
332
 
@@ -373,13 +336,19 @@ An interface representing any thenable (promise-like) object.
373
336
 
374
337
  ## Properties
375
338
 
376
- | Property | Type |
377
- | ------ | ------ |
378
- | <a id="then"></a> `then` | () => `unknown` |
339
+ ### then
340
+
341
+ ```ts
342
+ then: () => unknown;
343
+ ```
344
+
345
+ ### Returns
346
+
347
+ `unknown`
379
348
 
380
- ### type-aliases
349
+ ### type-aliases
381
350
 
382
- ### <a id="AnyNonPromise"></a>AnyNonPromise
351
+ ### <a id="AnyNonPromise"></a>AnyNonPromise
383
352
 
384
353
  [**@xylabs/promise**](#../README)
385
354
 
@@ -391,7 +360,7 @@ type AnyNonPromise = Exclude<TypedValue, PromiseType>;
391
360
 
392
361
  Any non-promise typed value, excluding thenables.
393
362
 
394
- ### <a id="AsyncMutex"></a>AsyncMutex
363
+ ### <a id="AsyncMutex"></a>AsyncMutex
395
364
 
396
365
  [**@xylabs/promise**](#../README)
397
366
 
@@ -403,15 +372,15 @@ type AsyncMutex<T> = Promise<T>;
403
372
 
404
373
  ## Type Parameters
405
374
 
406
- | Type Parameter |
407
- | ------ |
408
- | `T` |
375
+ ### T
376
+
377
+ `T`
409
378
 
410
379
  ## Description
411
380
 
412
381
  Used to document promises that are being used as Mutexes
413
382
 
414
- ### <a id="NullablePromisable"></a>NullablePromisable
383
+ ### <a id="NullablePromisable"></a>NullablePromisable
415
384
 
416
385
  [**@xylabs/promise**](#../README)
417
386
 
@@ -425,12 +394,15 @@ A Promisable that may resolve to null.
425
394
 
426
395
  ## Type Parameters
427
396
 
428
- | Type Parameter | Default type |
429
- | ------ | ------ |
430
- | `T` | - |
431
- | `V` | `never` |
397
+ ### T
398
+
399
+ `T`
400
+
401
+ ### V
402
+
403
+ `V` = `never`
432
404
 
433
- ### <a id="NullablePromisableArray"></a>NullablePromisableArray
405
+ ### <a id="NullablePromisableArray"></a>NullablePromisableArray
434
406
 
435
407
  [**@xylabs/promise**](#../README)
436
408
 
@@ -444,12 +416,15 @@ A Promisable array where elements may be null.
444
416
 
445
417
  ## Type Parameters
446
418
 
447
- | Type Parameter | Default type |
448
- | ------ | ------ |
449
- | `T` | - |
450
- | `V` | `never` |
419
+ ### T
451
420
 
452
- ### <a id="OptionalPromisable"></a>OptionalPromisable
421
+ `T`
422
+
423
+ ### V
424
+
425
+ `V` = `never`
426
+
427
+ ### <a id="OptionalPromisable"></a>OptionalPromisable
453
428
 
454
429
  [**@xylabs/promise**](#../README)
455
430
 
@@ -463,12 +438,15 @@ A Promisable that may resolve to undefined.
463
438
 
464
439
  ## Type Parameters
465
440
 
466
- | Type Parameter | Default type |
467
- | ------ | ------ |
468
- | `T` | - |
469
- | `V` | `never` |
441
+ ### T
442
+
443
+ `T`
470
444
 
471
- ### <a id="OptionalPromisableArray"></a>OptionalPromisableArray
445
+ ### V
446
+
447
+ `V` = `never`
448
+
449
+ ### <a id="OptionalPromisableArray"></a>OptionalPromisableArray
472
450
 
473
451
  [**@xylabs/promise**](#../README)
474
452
 
@@ -482,12 +460,15 @@ A Promisable array where elements may be undefined.
482
460
 
483
461
  ## Type Parameters
484
462
 
485
- | Type Parameter | Default type |
486
- | ------ | ------ |
487
- | `T` | - |
488
- | `V` | `never` |
463
+ ### T
464
+
465
+ `T`
489
466
 
490
- ### <a id="Promisable"></a>Promisable
467
+ ### V
468
+
469
+ `V` = `never`
470
+
471
+ ### <a id="Promisable"></a>Promisable
491
472
 
492
473
  [**@xylabs/promise**](#../README)
493
474
 
@@ -501,12 +482,15 @@ A value that may be a Promise, PromiseEx, or a plain synchronous value.
501
482
 
502
483
  ## Type Parameters
503
484
 
504
- | Type Parameter | Default type |
505
- | ------ | ------ |
506
- | `T` | - |
507
- | `V` | `never` |
485
+ ### T
486
+
487
+ `T`
488
+
489
+ ### V
508
490
 
509
- ### <a id="PromisableArray"></a>PromisableArray
491
+ `V` = `never`
492
+
493
+ ### <a id="PromisableArray"></a>PromisableArray
510
494
 
511
495
  [**@xylabs/promise**](#../README)
512
496
 
@@ -520,133 +504,108 @@ A Promisable that resolves to an array.
520
504
 
521
505
  ## Type Parameters
522
506
 
523
- | Type Parameter | Default type |
524
- | ------ | ------ |
525
- | `T` | - |
526
- | `V` | `never` |
507
+ ### T
508
+
509
+ `T`
510
+
511
+ ### V
512
+
513
+ `V` = `never`
527
514
 
528
- ### <a id="PromiseExFunc"></a>PromiseExFunc
515
+ ### <a id="PromiseExFunc"></a>PromiseExFunc
529
516
 
530
517
  [**@xylabs/promise**](#../README)
531
518
 
532
519
  ***
533
520
 
534
521
  ```ts
535
- type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
522
+ type PromiseExFunc<T> = (resolve?, reject?) => void;
536
523
  ```
537
524
 
538
525
  The executor function passed to the PromiseEx constructor.
539
526
 
540
527
  ## Type Parameters
541
528
 
542
- | Type Parameter |
543
- | ------ |
544
- | `T` |
529
+ ### T
530
+
531
+ `T`
545
532
 
546
533
  ## Parameters
547
534
 
548
- | Parameter | Type |
549
- | ------ | ------ |
550
- | `resolve?` | [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\> |
551
- | `reject?` | [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\> |
535
+ ### resolve?
536
+
537
+ [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\>
538
+
539
+ ### reject?
540
+
541
+ [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\>
552
542
 
553
543
  ## Returns
554
544
 
555
545
  `void`
556
546
 
557
- ### <a id="PromiseExSubFunc"></a>PromiseExSubFunc
547
+ ### <a id="PromiseExSubFunc"></a>PromiseExSubFunc
558
548
 
559
549
  [**@xylabs/promise**](#../README)
560
550
 
561
551
  ***
562
552
 
563
553
  ```ts
564
- type PromiseExSubFunc<T, TResult> = (value: T) => TResult;
554
+ type PromiseExSubFunc<T, TResult> = (value) => TResult;
565
555
  ```
566
556
 
567
557
  A resolve/reject callback used within PromiseEx.
568
558
 
569
559
  ## Type Parameters
570
560
 
571
- | Type Parameter | Default type |
572
- | ------ | ------ |
573
- | `T` | - |
574
- | `TResult` | `T` |
561
+ ### T
562
+
563
+ `T`
564
+
565
+ ### TResult
566
+
567
+ `TResult` = `T`
575
568
 
576
569
  ## Parameters
577
570
 
578
- | Parameter | Type |
579
- | ------ | ------ |
580
- | `value` | `T` |
571
+ ### value
572
+
573
+ `T`
581
574
 
582
575
  ## Returns
583
576
 
584
577
  `TResult`
585
578
 
586
- ### <a id="PromiseExValueFunc"></a>PromiseExValueFunc
579
+ ### <a id="PromiseExValueFunc"></a>PromiseExValueFunc
587
580
 
588
581
  [**@xylabs/promise**](#../README)
589
582
 
590
583
  ***
591
584
 
592
585
  ```ts
593
- type PromiseExValueFunc<V> = (value?: V) => boolean;
586
+ type PromiseExValueFunc<V> = (value?) => boolean;
594
587
  ```
595
588
 
596
589
  A callback that inspects the attached value and returns whether to cancel the promise.
597
590
 
598
591
  ## Type Parameters
599
592
 
600
- | Type Parameter |
601
- | ------ |
602
- | `V` |
593
+ ### V
594
+
595
+ `V`
603
596
 
604
597
  ## Parameters
605
598
 
606
- | Parameter | Type |
607
- | ------ | ------ |
608
- | `value?` | `V` |
599
+ ### value?
600
+
601
+ `V`
609
602
 
610
603
  ## Returns
611
604
 
612
605
  `boolean`
613
606
 
614
607
 
615
- Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
616
-
617
- ## Maintainers
618
-
619
- - [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
620
- - [Matt Jones](https://github.com/jonesmac)
621
- - [Joel Carter](https://github.com/JoelBCarter)
622
- - [Jordan Trouw](https://github.com/jordantrouw)
623
-
624
- ## License
625
-
626
- > See the [LICENSE](LICENSE) file for license details
627
-
628
- ## Credits
629
-
630
- [Made with 🔥 and ❄️ by XYLabs](https://xylabs.com)
631
-
632
- [logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
633
-
634
- [main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
635
- [main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
636
608
  [npm-badge]: https://img.shields.io/npm/v/@xylabs/promise.svg
637
609
  [npm-link]: https://www.npmjs.com/package/@xylabs/promise
638
- [codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698
639
- [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
640
- [codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
641
- [codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
642
- [snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
643
- [snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
644
-
645
- [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/promise
646
- [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/promise
647
-
648
- [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/promise/badge
649
- [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/promise
650
-
651
- [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/promise
652
- [socket-link]: https://socket.dev/npm/package/@xylabs/promise
610
+ [license-badge]: https://img.shields.io/npm/l/@xylabs/promise.svg
611
+ [license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
@@ -1,5 +1,4 @@
1
1
  import { TypedValue } from '@xylabs/typeof';
2
- export { isPromise } from '@xylabs/typeof';
3
2
 
4
3
  /**
5
4
  * For use with Promise.allSettled to filter only successful results
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
@@ -47,14 +47,10 @@ var rejected = (val) => {
47
47
  function toPromise(value) {
48
48
  return value instanceof Promise ? value : Promise.resolve(value);
49
49
  }
50
-
51
- // src/index.ts
52
- import { isPromise } from "@xylabs/typeof";
53
50
  export {
54
51
  PromiseEx,
55
52
  fulfilled,
56
53
  fulfilledValues,
57
- isPromise,
58
54
  rejected,
59
55
  toPromise
60
56
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fulfilled.ts","../../src/fulfilledValues.ts","../../src/PromiseEx.ts","../../src/rejected.ts","../../src/toPromise.ts","../../src/index.ts"],"sourcesContent":["/**\n * For use with Promise.allSettled to filter only successful results\n * @param val\n * @returns\n */\nexport const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {\n return val.status === 'fulfilled'\n}\n","/**\n * For use with Promise.allSettled to reduce to only successful result values\n * @example <caption>Casting the initialValue provided to reduce</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce(fulfilledValues, [] as string[])\n * // results === [ 'resolved' ]\n * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce<string[]>(fulfilledValues, [])\n * // results === [ 'resolved' ]\n * @param previousValue\n * @param currentValue\n * @returns\n */\nexport const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {\n if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)\n return previousValue\n}\n","/** A resolve/reject callback used within PromiseEx. */\nexport type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult\n\n/** The executor function passed to the PromiseEx constructor. */\nexport type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void\n\n/** A callback that inspects the attached value and returns whether to cancel the promise. */\nexport type PromiseExValueFunc<V> = (value?: V) => boolean\n\n/**\n * An extended Promise that carries an optional attached value and supports cancellation.\n * The value can be inspected via the `then` or `value` methods to conditionally cancel.\n */\nexport class PromiseEx<T, V = void> extends Promise<T> {\n /** Whether the promise has been cancelled via a value callback. */\n cancelled?: boolean\n private _value?: V\n\n constructor(func: PromiseExFunc<T>, value?: V) {\n super(func)\n this._value = value\n }\n\n // eslint-disable-next-line unicorn/no-thenable\n override then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n onvalue?: (value?: V) => boolean,\n ): Promise<TResult1 | TResult2> {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return super.then(onfulfilled, onrejected)\n }\n\n /**\n * Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.\n * @param onvalue - A callback that receives the attached value and returns whether to cancel.\n * @returns This instance for chaining.\n */\n value(onvalue?: (value?: V) => boolean) {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return this\n }\n}\n","/**\n * For use with Promise.allSettled to filter only rejected results\n * @param val\n * @returns\n */\nexport const rejected = <T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult => {\n return val.status === 'rejected'\n}\n","import type { Promisable } from './types.ts'\n\n/**\n * Wraps a value in a Promise if it is not already one.\n * @param value - A value that may or may not be a Promise.\n * @returns A Promise resolving to the value.\n */\nexport function toPromise<T>(value: Promisable<T>): Promise<T> {\n return value instanceof Promise ? value : Promise.resolve(value)\n}\n","export { fulfilled } from './fulfilled.ts'\nexport { fulfilledValues } from './fulfilledValues.ts'\nexport * from './PromiseEx.ts'\nexport { rejected } from './rejected.ts'\nexport * from './toPromise.ts'\nexport * from './types.ts'\nexport { isPromise } from '@xylabs/typeof'\n"],"mappings":";AAKO,IAAM,YAAY,CAAI,QAAmE;AAC9F,SAAO,IAAI,WAAW;AACxB;;;ACWO,IAAM,kBAAkB,CAAI,eAAoB,iBAA+C;AACpG,MAAI,aAAa,WAAW,YAAa,eAAc,KAAK,aAAa,KAAK;AAC9E,SAAO;AACT;;;ACRO,IAAM,YAAN,cAAqC,QAAW;AAAA;AAAA,EAErD;AAAA,EACQ;AAAA,EAER,YAAY,MAAwB,OAAW;AAC7C,UAAM,IAAI;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGS,KACP,aACA,YACA,SAC8B;AAC9B,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO,MAAM,KAAK,aAAa,UAAU;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAkC;AACtC,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO;AAAA,EACT;AACF;;;ACzCO,IAAM,WAAW,CAAI,QAA+D;AACzF,SAAO,IAAI,WAAW;AACxB;;;ACAO,SAAS,UAAa,OAAkC;AAC7D,SAAO,iBAAiB,UAAU,QAAQ,QAAQ,QAAQ,KAAK;AACjE;;;ACHA,SAAS,iBAAiB;","names":[]}
1
+ {"version":3,"sources":["../../src/fulfilled.ts","../../src/fulfilledValues.ts","../../src/PromiseEx.ts","../../src/rejected.ts","../../src/toPromise.ts"],"sourcesContent":["/**\n * For use with Promise.allSettled to filter only successful results\n * @param val\n * @returns\n */\nexport const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {\n return val.status === 'fulfilled'\n}\n","/**\n * For use with Promise.allSettled to reduce to only successful result values\n * @example <caption>Casting the initialValue provided to reduce</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce(fulfilledValues, [] as string[])\n * // results === [ 'resolved' ]\n * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce<string[]>(fulfilledValues, [])\n * // results === [ 'resolved' ]\n * @param previousValue\n * @param currentValue\n * @returns\n */\nexport const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {\n if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)\n return previousValue\n}\n","/** A resolve/reject callback used within PromiseEx. */\nexport type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult\n\n/** The executor function passed to the PromiseEx constructor. */\nexport type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void\n\n/** A callback that inspects the attached value and returns whether to cancel the promise. */\nexport type PromiseExValueFunc<V> = (value?: V) => boolean\n\n/**\n * An extended Promise that carries an optional attached value and supports cancellation.\n * The value can be inspected via the `then` or `value` methods to conditionally cancel.\n */\nexport class PromiseEx<T, V = void> extends Promise<T> {\n /** Whether the promise has been cancelled via a value callback. */\n cancelled?: boolean\n private _value?: V\n\n constructor(func: PromiseExFunc<T>, value?: V) {\n super(func)\n this._value = value\n }\n\n // eslint-disable-next-line unicorn/no-thenable\n override then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n onvalue?: (value?: V) => boolean,\n ): Promise<TResult1 | TResult2> {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return super.then(onfulfilled, onrejected)\n }\n\n /**\n * Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.\n * @param onvalue - A callback that receives the attached value and returns whether to cancel.\n * @returns This instance for chaining.\n */\n value(onvalue?: (value?: V) => boolean) {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return this\n }\n}\n","/**\n * For use with Promise.allSettled to filter only rejected results\n * @param val\n * @returns\n */\nexport const rejected = <T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult => {\n return val.status === 'rejected'\n}\n","import type { Promisable } from './types.ts'\n\n/**\n * Wraps a value in a Promise if it is not already one.\n * @param value - A value that may or may not be a Promise.\n * @returns A Promise resolving to the value.\n */\nexport function toPromise<T>(value: Promisable<T>): Promise<T> {\n return value instanceof Promise ? value : Promise.resolve(value)\n}\n"],"mappings":";AAKO,IAAM,YAAY,CAAI,QAAmE;AAC9F,SAAO,IAAI,WAAW;AACxB;;;ACWO,IAAM,kBAAkB,CAAI,eAAoB,iBAA+C;AACpG,MAAI,aAAa,WAAW,YAAa,eAAc,KAAK,aAAa,KAAK;AAC9E,SAAO;AACT;;;ACRO,IAAM,YAAN,cAAqC,QAAW;AAAA;AAAA,EAErD;AAAA,EACQ;AAAA,EAER,YAAY,MAAwB,OAAW;AAC7C,UAAM,IAAI;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGS,KACP,aACA,YACA,SAC8B;AAC9B,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO,MAAM,KAAK,aAAa,UAAU;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAkC;AACtC,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO;AAAA,EACT;AACF;;;ACzCO,IAAM,WAAW,CAAI,QAA+D;AACzF,SAAO,IAAI,WAAW;AACxB;;;ACAO,SAAS,UAAa,OAAkC;AAC7D,SAAO,iBAAiB,UAAU,QAAQ,QAAQ,QAAQ,KAAK;AACjE;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/promise",
3
- "version": "5.0.95",
3
+ "version": "5.0.97",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "promise",
@@ -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,19 +41,18 @@
43
41
  "README.md"
44
42
  ],
45
43
  "dependencies": {
46
- "@xylabs/typeof": "~5.0.95"
44
+ "@xylabs/typeof": "~5.0.97"
47
45
  },
48
46
  "devDependencies": {
49
- "@types/node": "^25.5.2",
50
- "@xylabs/ts-scripts-common": "~7.8.4",
51
- "@xylabs/ts-scripts-pnpm": "~7.8.4",
52
- "@xylabs/tsconfig": "~7.8.4",
47
+ "@types/node": "^25.6.0",
48
+ "@xylabs/toolchain": "~7.10.4",
49
+ "@xylabs/tsconfig": "~7.10.4",
53
50
  "esbuild": "^0.28.0",
54
51
  "typescript": "^5",
55
- "vite": "^8.0.5",
56
- "vitest": "^4.1.2",
57
- "@xylabs/vitest-extended": "~5.0.95",
58
- "@xylabs/vitest-matchers": "~5.0.95"
52
+ "vite": "^8.0.8",
53
+ "vitest": "^4.1.4",
54
+ "@xylabs/vitest-extended": "~5.0.97",
55
+ "@xylabs/vitest-matchers": "~5.0.97"
59
56
  },
60
57
  "engines": {
61
58
  "node": ">=18"