@xylabs/promise 5.0.79 → 5.0.81

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
@@ -34,7 +34,6 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
34
34
  - [PromiseExSubFunc](#type-aliases/PromiseExSubFunc)
35
35
  - [PromiseExFunc](#type-aliases/PromiseExFunc)
36
36
  - [PromiseExValueFunc](#type-aliases/PromiseExValueFunc)
37
- - [AnyNonPromise](#type-aliases/AnyNonPromise)
38
37
  - [Promisable](#type-aliases/Promisable)
39
38
  - [PromisableArray](#type-aliases/PromisableArray)
40
39
  - [OptionalPromisable](#type-aliases/OptionalPromisable)
@@ -42,14 +41,15 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
42
41
  - [NullablePromisable](#type-aliases/NullablePromisable)
43
42
  - [NullablePromisableArray](#type-aliases/NullablePromisableArray)
44
43
  - [AsyncMutex](#type-aliases/AsyncMutex)
44
+ - [AnyNonPromise](#type-aliases/AnyNonPromise)
45
45
 
46
46
  ## Functions
47
47
 
48
48
  - [fulfilled](#functions/fulfilled)
49
49
  - [fulfilledValues](#functions/fulfilledValues)
50
- - [isPromise](#functions/isPromise)
51
50
  - [rejected](#functions/rejected)
52
51
  - [toPromise](#functions/toPromise)
52
+ - [isPromise](#functions/isPromise)
53
53
 
54
54
  ### classes
55
55
 
@@ -138,13 +138,13 @@ Attaches callbacks for the resolution and/or rejection of the Promise.
138
138
 
139
139
  The callback to execute when the Promise is resolved.
140
140
 
141
- `null` | (`value`) => `TResult1` \| `PromiseLike`\<`TResult1`\>
141
+ (`value`) => `TResult1` \| `PromiseLike`\<`TResult1`\> | `null`
142
142
 
143
143
  #### onrejected?
144
144
 
145
145
  The callback to execute when the Promise is rejected.
146
146
 
147
- `null` | (`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\>
147
+ (`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\> | `null`
148
148
 
149
149
  #### onvalue?
150
150
 
@@ -266,20 +266,44 @@ const results = settled.reduce<string[]>(fulfilledValues, [])
266
266
 
267
267
  ***
268
268
 
269
+ ## Call Signature
270
+
269
271
  ```ts
270
272
  function isPromise(value): value is Promise<unknown>;
271
273
  ```
272
274
 
273
- ## Parameters
275
+ ### Parameters
274
276
 
275
277
  ### value
276
278
 
277
279
  `unknown`
278
280
 
279
- ## Returns
281
+ ### Returns
280
282
 
281
283
  `value is Promise<unknown>`
282
284
 
285
+ ## Call Signature
286
+
287
+ ```ts
288
+ function isPromise<T>(value): value is Extract<T, Promise<unknown>>;
289
+ ```
290
+
291
+ ### Type Parameters
292
+
293
+ ### T
294
+
295
+ `T`
296
+
297
+ ### Parameters
298
+
299
+ ### value
300
+
301
+ `T`
302
+
303
+ ### Returns
304
+
305
+ `value is Extract<T, Promise<unknown>>`
306
+
283
307
  ### <a id="rejected"></a>rejected
284
308
 
285
309
  [**@xylabs/promise**](#../README)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/promise",
3
- "version": "5.0.79",
3
+ "version": "5.0.81",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "promise",
@@ -29,28 +29,25 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/neutral/index.d.ts",
32
- "source": "./src/index.ts",
33
32
  "default": "./dist/neutral/index.mjs"
34
33
  },
35
34
  "./package.json": "./package.json"
36
35
  },
37
36
  "module": "./dist/neutral/index.mjs",
38
- "source": "./src/index.ts",
39
37
  "types": "./dist/neutral/index.d.ts",
40
38
  "files": [
41
39
  "dist",
42
- "src",
43
40
  "!**/*.bench.*",
44
41
  "!**/*.spec.*",
45
42
  "!**/*.test.*"
46
43
  ],
47
44
  "dependencies": {
48
- "@xylabs/typeof": "~5.0.79"
45
+ "@xylabs/typeof": "~5.0.81",
46
+ "@xylabs/vitest-extended": "~5.0.81"
49
47
  },
50
48
  "devDependencies": {
51
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
52
- "@xylabs/tsconfig": "~7.3.2",
53
- "@xylabs/vitest-extended": "~5.0.79",
49
+ "@xylabs/ts-scripts-yarn3": "~7.4.11",
50
+ "@xylabs/tsconfig": "~7.4.11",
54
51
  "typescript": "~5.9.3",
55
52
  "vitest": "~4.0.18"
56
53
  },
package/src/PromiseEx.ts DELETED
@@ -1,32 +0,0 @@
1
- export type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult
2
- export type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void
3
- export type PromiseExValueFunc<V> = (value?: V) => boolean
4
-
5
- export class PromiseEx<T, V = void> extends Promise<T> {
6
- cancelled?: boolean
7
- private _value?: V
8
-
9
- constructor(func: PromiseExFunc<T>, value?: V) {
10
- super(func)
11
- this._value = value
12
- }
13
-
14
- // eslint-disable-next-line unicorn/no-thenable
15
- override then<TResult1 = T, TResult2 = never>(
16
- onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,
17
- onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,
18
- onvalue?: (value?: V) => boolean,
19
- ): Promise<TResult1 | TResult2> {
20
- if (onvalue?.(this._value)) {
21
- this.cancelled = true
22
- }
23
- return super.then(onfulfilled, onrejected)
24
- }
25
-
26
- value(onvalue?: (value?: V) => boolean) {
27
- if (onvalue?.(this._value)) {
28
- this.cancelled = true
29
- }
30
- return this
31
- }
32
- }
package/src/fulfilled.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * For use with Promise.allSettled to filter only successful results
3
- * @param val
4
- * @returns
5
- */
6
- export const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {
7
- return val.status === 'fulfilled'
8
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * For use with Promise.allSettled to reduce to only successful result values
3
- * @example <caption>Casting the initialValue provided to reduce</caption>
4
- * const resolved = Promise.resolve('resolved')
5
- * const rejected = Promise.reject('rejected')
6
- * const settled = await Promise.allSettled([resolved, rejected])
7
- * const results = settled.reduce(fulfilledValues, [] as string[])
8
- * // results === [ 'resolved' ]
9
- * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>
10
- * const resolved = Promise.resolve('resolved')
11
- * const rejected = Promise.reject('rejected')
12
- * const settled = await Promise.allSettled([resolved, rejected])
13
- * const results = settled.reduce<string[]>(fulfilledValues, [])
14
- * // results === [ 'resolved' ]
15
- * @param previousValue
16
- * @param currentValue
17
- * @returns
18
- */
19
- export const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {
20
- if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)
21
- return previousValue
22
- }
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export { fulfilled } from './fulfilled.ts'
2
- export { fulfilledValues } from './fulfilledValues.ts'
3
- export * from './PromiseEx.ts'
4
- export { rejected } from './rejected.ts'
5
- export * from './toPromise.ts'
6
- export * from './types.ts'
7
- export { isPromise } from '@xylabs/typeof'
package/src/rejected.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * For use with Promise.allSettled to filter only rejected results
3
- * @param val
4
- * @returns
5
- */
6
- export const rejected = <T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult => {
7
- return val.status === 'rejected'
8
- }
@@ -1,18 +0,0 @@
1
- // vitest.customMatchers.d.ts
2
- import 'vitest'
3
-
4
- // Extend the expect Matchers interface
5
- declare module 'vitest' {
6
- interface Assertion<T = unknown> {
7
- toBeNumber(): T
8
- }
9
- interface Assertion<T = unknown> {
10
- toBeFunction(): T
11
- }
12
- interface Assertion<T = unknown> {
13
- toBeString(): T
14
- }
15
- interface Assertion<T = unknown> {
16
- toBeArrayOfSize(size: number): T
17
- }
18
- }
package/src/toPromise.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { Promisable } from './types.ts'
2
-
3
- export function toPromise<T>(value: Promisable<T>): Promise<T> {
4
- return value instanceof Promise ? value : Promise.resolve(value)
5
- }
package/src/types.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { TypedValue } from '@xylabs/typeof'
2
-
3
- import type { PromiseEx } from './PromiseEx.ts'
4
-
5
- export type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T
6
- export type PromisableArray<T, V = never> = Promisable<T[], V>
7
- export type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>
8
- export type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>
9
- export type NullablePromisable<T, V = never> = Promisable<T | null, V>
10
- export type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>
11
-
12
- /** @description Used to document promises that are being used as Mutexes */
13
- export type AsyncMutex<T> = Promise<T>
14
-
15
- export interface PromiseType {
16
- then: () => unknown
17
- }
18
-
19
- export type AnyNonPromise = Exclude<TypedValue, PromiseType>