@oscarpalmer/atoms 0.184.2 → 0.186.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/array/difference.d.mts +29 -0
- package/dist/array/exists.d.mts +35 -0
- package/dist/array/filter.d.mts +72 -2
- package/dist/array/find.d.mts +70 -0
- package/dist/array/first.d.mts +77 -2
- package/dist/array/flatten.d.mts +6 -0
- package/dist/array/flatten.mjs +6 -0
- package/dist/array/from.d.mts +36 -0
- package/dist/array/get.d.mts +21 -13
- package/dist/array/group-by.d.mts +142 -0
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/{position.d.mts → match.d.mts} +168 -36
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +11 -1
- package/dist/array/partition.d.mts +35 -0
- package/dist/array/push.d.mts +8 -0
- package/dist/array/push.mjs +8 -0
- package/dist/array/reverse.d.mts +1 -0
- package/dist/array/reverse.mjs +1 -0
- package/dist/array/select.d.mts +94 -8
- package/dist/array/single.d.mts +29 -0
- package/dist/array/slice.d.mts +106 -16
- package/dist/array/sort.d.mts +30 -4
- package/dist/array/sort.mjs +1 -1
- package/dist/array/splice.d.mts +48 -0
- package/dist/array/splice.mjs +2 -1
- package/dist/array/swap.d.mts +113 -8
- package/dist/array/swap.mjs +2 -1
- package/dist/array/to-map.d.mts +124 -0
- package/dist/array/to-record.d.mts +124 -0
- package/dist/array/to-set.d.mts +24 -0
- package/dist/array/toggle.d.mts +38 -3
- package/dist/array/union.d.mts +29 -0
- package/dist/array/unique.d.mts +24 -0
- package/dist/array/update.d.mts +38 -3
- package/dist/beacon.d.mts +12 -0
- package/dist/beacon.mjs +9 -0
- package/dist/color/instance.d.mts +8 -0
- package/dist/color/instance.mjs +3 -0
- package/dist/color/models.d.mts +30 -0
- package/dist/function/assert.d.mts +29 -8
- package/dist/function/assert.mjs +29 -8
- package/dist/function/memoize.d.mts +3 -0
- package/dist/function/memoize.mjs +3 -0
- package/dist/function/retry.d.mts +3 -0
- package/dist/function/retry.mjs +3 -0
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +2158 -288
- package/dist/index.mjs +294 -181
- package/dist/internal/array/chunk.d.mts +6 -0
- package/dist/internal/array/chunk.mjs +6 -0
- package/dist/internal/array/compact.d.mts +12 -0
- package/dist/internal/array/index-of.d.mts +70 -0
- package/dist/internal/math/aggregate.d.mts +29 -0
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/get.d.mts +27 -5
- package/dist/internal/value/has.d.mts +7 -7
- package/dist/internal/value/has.mjs +1 -1
- package/dist/internal/value/misc.d.mts +2 -2
- package/dist/internal/value/misc.mjs +10 -4
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +11 -0
- package/dist/models.d.mts +14 -1
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.d.mts +0 -6
- package/dist/promise/models.d.mts +36 -0
- package/dist/promise/models.mjs +6 -0
- package/dist/queue.d.mts +13 -1
- package/dist/queue.mjs +9 -0
- package/dist/result/index.d.mts +0 -8
- package/dist/result/index.mjs +0 -8
- package/dist/result/match.d.mts +4 -4
- package/dist/result/work/flow.d.mts +12 -36
- package/dist/result/work/pipe.d.mts +11 -33
- package/dist/sized/set.d.mts +3 -2
- package/dist/sized/set.mjs +3 -2
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +10 -1
- package/dist/value/unsmush.d.mts +2 -3
- package/package.json +5 -5
- package/src/array/difference.ts +33 -0
- package/src/array/exists.ts +35 -0
- package/src/array/filter.ts +72 -2
- package/src/array/find.ts +70 -0
- package/src/array/first.ts +77 -3
- package/src/array/flatten.ts +6 -0
- package/src/array/from.ts +40 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/index.ts +1 -1
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +33 -0
- package/src/array/last.ts +75 -2
- package/src/array/{position.ts → match.ts} +197 -65
- package/src/array/move.ts +87 -13
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +96 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +30 -4
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +122 -13
- package/src/array/to-map.ts +124 -0
- package/src/array/to-record.ts +124 -0
- package/src/array/to-set.ts +24 -0
- package/src/array/toggle.ts +42 -3
- package/src/array/union.ts +33 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +9 -1
- package/src/color/models.ts +30 -0
- package/src/function/assert.ts +66 -7
- package/src/function/memoize.ts +3 -0
- package/src/function/once.ts +5 -1
- package/src/function/retry.ts +3 -0
- package/src/internal/array/chunk.ts +6 -0
- package/src/internal/array/compact.ts +12 -0
- package/src/internal/array/index-of.ts +70 -0
- package/src/internal/math/aggregate.ts +29 -0
- package/src/internal/string.ts +0 -2
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +5 -0
- package/src/internal/value/get.ts +27 -5
- package/src/internal/value/has.ts +10 -10
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +18 -0
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +13 -1
- package/src/result/index.ts +0 -8
- package/src/result/match.ts +4 -4
- package/src/result/work/flow.ts +12 -36
- package/src/result/work/pipe.ts +11 -33
- package/src/sized/set.ts +4 -3
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +10 -1
- package/src/value/unsmush.ts +2 -8
package/dist/array/to-set.d.mts
CHANGED
|
@@ -3,22 +3,46 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/to-set.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create a Set from an array of items using a callback
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to convert
|
|
7
8
|
* @param callback Callback to get an item's value
|
|
8
9
|
* @returns Set of values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* toSet(
|
|
14
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
15
|
+
* item => item.id,
|
|
16
|
+
* ); // => Set { 1, 2, 3 }
|
|
17
|
+
* ```
|
|
9
18
|
*/
|
|
10
19
|
declare function toSet<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback): Set<ReturnType<Callback>>;
|
|
11
20
|
/**
|
|
12
21
|
* Create a Set from an array of items using a key
|
|
22
|
+
*
|
|
13
23
|
* @param array Array to convert
|
|
14
24
|
* @param key Key to use for value
|
|
15
25
|
* @returns Set of values
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* toSet(
|
|
30
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
31
|
+
* 'id',
|
|
32
|
+
* ); // => Set { 1, 2, 3 }
|
|
33
|
+
* ```
|
|
16
34
|
*/
|
|
17
35
|
declare function toSet<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Set<Item[ItemKey]>;
|
|
18
36
|
/**
|
|
19
37
|
* Create a Set from an array of items
|
|
38
|
+
*
|
|
20
39
|
* @param array Array to convert
|
|
21
40
|
* @returns Set of items
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* toSet([1, 2, 3]); // => Set { 1, 2, 3 }
|
|
45
|
+
* ```
|
|
22
46
|
*/
|
|
23
47
|
declare function toSet<Item>(array: Item[]): Set<Item>;
|
|
24
48
|
//#endregion
|
package/dist/array/toggle.d.mts
CHANGED
|
@@ -2,26 +2,61 @@ import { PlainObject } from "../models.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/array/toggle.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Toggle an item in an array
|
|
5
|
+
* Toggle an item in an array
|
|
6
|
+
*
|
|
7
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
8
|
+
*
|
|
6
9
|
* @param destination Array to toggle within
|
|
7
10
|
* @param toggled Toggled items
|
|
8
11
|
* @param callback Callback to find existing item
|
|
9
12
|
* @returns Original array
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* toggle(
|
|
17
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
18
|
+
* [{id: 2}, {id: 4}],
|
|
19
|
+
* item => item.id,
|
|
20
|
+
* ); // => [{id: 1}, {id: 3}, {id: 4}]
|
|
21
|
+
* ```
|
|
10
22
|
*/
|
|
11
23
|
declare function toggle<Item>(destination: Item[], toggled: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
12
24
|
/**
|
|
13
|
-
* Toggle an item in an array
|
|
25
|
+
* Toggle an item in an array
|
|
26
|
+
*
|
|
27
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
28
|
+
*
|
|
14
29
|
* @param destination Array to toggle within
|
|
15
30
|
* @param toggled Toggled items
|
|
16
31
|
* @param key Key to find existing item
|
|
17
32
|
* @returns Original array
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* toggle(
|
|
37
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
38
|
+
* [{id: 2}, {id: 4}],
|
|
39
|
+
* 'id',
|
|
40
|
+
* ); // => [{id: 1}, {id: 3}, {id: 4}]
|
|
41
|
+
* ```
|
|
18
42
|
*/
|
|
19
43
|
declare function toggle<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], toggled: Item[], key: ItemKey): Item[];
|
|
20
44
|
/**
|
|
21
|
-
* Toggle an item in an array
|
|
45
|
+
* Toggle an item in an array
|
|
46
|
+
*
|
|
47
|
+
* If the item exists, it will be removed; if it doesn't, it will be added
|
|
48
|
+
*
|
|
22
49
|
* @param destination Array to toggle within
|
|
23
50
|
* @param toggled Toggled items
|
|
24
51
|
* @returns Original array
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* toggle(
|
|
56
|
+
* [1, 2, 3],
|
|
57
|
+
* [2, 4],
|
|
58
|
+
* ); // => [1, 3, 4]
|
|
59
|
+
* ```
|
|
25
60
|
*/
|
|
26
61
|
declare function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
|
|
27
62
|
//#endregion
|
package/dist/array/union.d.mts
CHANGED
|
@@ -1,25 +1,54 @@
|
|
|
1
1
|
//#region src/array/union.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Get the combined, unique values from two arrays
|
|
4
|
+
*
|
|
4
5
|
* @param first First array
|
|
5
6
|
* @param second Second array
|
|
6
7
|
* @param callback Callback to get an item's value for comparison
|
|
7
8
|
* @returns Combined, unique values from both arrays
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* union(
|
|
13
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
14
|
+
* [{id: 2}, {id: 4}],
|
|
15
|
+
* item => item.id,
|
|
16
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
|
|
17
|
+
* ```
|
|
8
18
|
*/
|
|
9
19
|
declare function union<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): (First | Second)[];
|
|
10
20
|
/**
|
|
11
21
|
* Get the combined, unique values from two arrays
|
|
22
|
+
*
|
|
12
23
|
* @param first First array
|
|
13
24
|
* @param second Second array
|
|
14
25
|
* @param key Key to get an item's value for comparison
|
|
15
26
|
* @returns Combined, unique values from both arrays
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* union(
|
|
31
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
32
|
+
* [{id: 2}, {id: 4}],
|
|
33
|
+
* 'id',
|
|
34
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
|
|
35
|
+
* ```
|
|
16
36
|
*/
|
|
17
37
|
declare function union<First extends Record<string, unknown>, Second extends Record<string, unknown>, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): (First | Second)[];
|
|
18
38
|
/**
|
|
19
39
|
* Get the combined, unique values from two arrays
|
|
40
|
+
*
|
|
20
41
|
* @param first First array
|
|
21
42
|
* @param second Second array
|
|
22
43
|
* @returns Combined, unique values from both arrays
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* union(
|
|
48
|
+
* [1, 2, 3],
|
|
49
|
+
* [2, 4],
|
|
50
|
+
* ); // => [1, 2, 3, 4]
|
|
51
|
+
* ```
|
|
23
52
|
*/
|
|
24
53
|
declare function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
|
|
25
54
|
//#endregion
|
package/dist/array/unique.d.mts
CHANGED
|
@@ -3,22 +3,46 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/unique.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get an array of unique items
|
|
6
|
+
*
|
|
6
7
|
* @param array Original array
|
|
7
8
|
* @param callback Callback to get an item's value
|
|
8
9
|
* @returns Array of unique items
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* unique(
|
|
14
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
15
|
+
* item => item.id,
|
|
16
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
17
|
+
* ```
|
|
9
18
|
*/
|
|
10
19
|
declare function unique<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
11
20
|
/**
|
|
12
21
|
* Get an array of unique items
|
|
22
|
+
*
|
|
13
23
|
* @param array Original array
|
|
14
24
|
* @param key Key to use for unique value
|
|
15
25
|
* @returns Array of unique items
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* unique(
|
|
30
|
+
* [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
|
|
31
|
+
* 'id',
|
|
32
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
33
|
+
* ```
|
|
16
34
|
*/
|
|
17
35
|
declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
|
|
18
36
|
/**
|
|
19
37
|
* Get an array of unique items
|
|
38
|
+
*
|
|
20
39
|
* @param array Original array
|
|
21
40
|
* @returns Array of unique items
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* unique([1, 2, 3, 2]); // => [1, 2, 3]
|
|
45
|
+
* ```
|
|
22
46
|
*/
|
|
23
47
|
declare function unique<Item>(array: Item[]): Item[];
|
|
24
48
|
//#endregion
|
package/dist/array/update.d.mts
CHANGED
|
@@ -2,26 +2,61 @@ import { PlainObject } from "../models.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/array/update.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Update an item in an array
|
|
5
|
+
* Update an item in an array
|
|
6
|
+
*
|
|
7
|
+
* If the item exists, it will be updated; if it doesn't, it will be added
|
|
8
|
+
*
|
|
6
9
|
* @param destination Array to update within
|
|
7
10
|
* @param updated Updated items
|
|
8
11
|
* @param callback Callback to find existing item
|
|
9
12
|
* @returns Original array
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* update(
|
|
17
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
18
|
+
* [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
|
|
19
|
+
* item => item.id,
|
|
20
|
+
* ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
|
|
21
|
+
* ```
|
|
10
22
|
*/
|
|
11
23
|
declare function update<Item>(destination: Item[], updated: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
12
24
|
/**
|
|
13
|
-
* Update an item in an array
|
|
25
|
+
* Update an item in an array
|
|
26
|
+
*
|
|
27
|
+
* If the item exists, it will be updated; if it doesn't, it will be added
|
|
28
|
+
*
|
|
14
29
|
* @param destination Array to update within
|
|
15
30
|
* @param updated Updated items
|
|
16
31
|
* @param key Key to find existing item
|
|
17
32
|
* @returns Original array
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* update(
|
|
37
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
38
|
+
* [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
|
|
39
|
+
* 'id',
|
|
40
|
+
* ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
|
|
41
|
+
* ```
|
|
18
42
|
*/
|
|
19
43
|
declare function update<Item extends PlainObject, ItemKey extends keyof Item>(destination: Item[], updated: Item[], key: ItemKey): Item[];
|
|
20
44
|
/**
|
|
21
|
-
* Update an item in an array
|
|
45
|
+
* Update an item in an array
|
|
46
|
+
*
|
|
47
|
+
* If the item exists, it will be updated; if it doesn't, it will be added
|
|
48
|
+
*
|
|
22
49
|
* @param destination Array to update within
|
|
23
50
|
* @param updated Updated items
|
|
24
51
|
* @returns Original array
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* update(
|
|
56
|
+
* [1, 2, 3],
|
|
57
|
+
* [2, 4],
|
|
58
|
+
* ); // => [1, 2, 3, 4]
|
|
59
|
+
* ```
|
|
25
60
|
*/
|
|
26
61
|
declare function update<Item>(destination: Item[], updated: Item[]): Item[];
|
|
27
62
|
//#endregion
|
package/dist/beacon.d.mts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
//#region src/beacon.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
|
|
4
|
+
*/
|
|
2
5
|
declare class Beacon<Value> {
|
|
3
6
|
#private;
|
|
4
7
|
/**
|
|
@@ -48,6 +51,9 @@ type BeaconOptions<Value> = {
|
|
|
48
51
|
*/
|
|
49
52
|
equal?: (first: Value, second: Value) => boolean;
|
|
50
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* An observable holds a value and allows observers to subscribe to changes in that value
|
|
56
|
+
*/
|
|
51
57
|
declare class Observable<Value> {
|
|
52
58
|
#private;
|
|
53
59
|
constructor(instance: Beacon<Value>, observers: Map<Subscription<Value>, Observer<Value>>);
|
|
@@ -75,6 +81,9 @@ type ObservableState<Value> = {
|
|
|
75
81
|
closed: boolean;
|
|
76
82
|
observers: Map<Subscription<Value>, Observer<Value>>;
|
|
77
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* An observer receives notifications from an observable
|
|
86
|
+
*/
|
|
78
87
|
type Observer<Value> = {
|
|
79
88
|
/**
|
|
80
89
|
* Callback for when the observable is completed
|
|
@@ -89,6 +98,9 @@ type Observer<Value> = {
|
|
|
89
98
|
*/
|
|
90
99
|
next?: (value: Value) => void;
|
|
91
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
|
|
103
|
+
*/
|
|
92
104
|
declare class Subscription<Value> {
|
|
93
105
|
#private;
|
|
94
106
|
constructor(state: ObservableState<Value>);
|
package/dist/beacon.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { noop } from "./internal/function/misc.mjs";
|
|
2
2
|
import { isPlainObject } from "./internal/is.mjs";
|
|
3
3
|
//#region src/beacon.ts
|
|
4
|
+
/**
|
|
5
|
+
* A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
|
|
6
|
+
*/
|
|
4
7
|
var Beacon = class {
|
|
5
8
|
#options;
|
|
6
9
|
#state;
|
|
@@ -71,6 +74,9 @@ var Beacon = class {
|
|
|
71
74
|
if (finish === true) finishBeacon(this.#state, true);
|
|
72
75
|
}
|
|
73
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* An observable holds a value and allows observers to subscribe to changes in that value
|
|
79
|
+
*/
|
|
74
80
|
var Observable = class {
|
|
75
81
|
#state;
|
|
76
82
|
constructor(instance, observers) {
|
|
@@ -95,6 +101,9 @@ var Observable = class {
|
|
|
95
101
|
return instance;
|
|
96
102
|
}
|
|
97
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
|
|
106
|
+
*/
|
|
98
107
|
var Subscription = class {
|
|
99
108
|
#state;
|
|
100
109
|
constructor(state) {
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "./models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/color/instance.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A color that is represented in multiple color formats
|
|
6
|
+
*/
|
|
4
7
|
declare class Color {
|
|
5
8
|
#private;
|
|
9
|
+
/**
|
|
10
|
+
* A property to identify this as a Color instance, used for type checking
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
6
14
|
private readonly $color;
|
|
7
15
|
/**
|
|
8
16
|
* Get the alpha channel
|
package/dist/color/instance.mjs
CHANGED
|
@@ -3,6 +3,9 @@ import { formatColor } from "./misc/index.mjs";
|
|
|
3
3
|
import { getAlpha } from "./misc/alpha.mjs";
|
|
4
4
|
import { getColorState, setHSLColor, setHexColor, setRGBColor } from "./misc/state.mjs";
|
|
5
5
|
//#region src/color/instance.ts
|
|
6
|
+
/**
|
|
7
|
+
* A color that is represented in multiple color formats
|
|
8
|
+
*/
|
|
6
9
|
var Color = class {
|
|
7
10
|
#state;
|
|
8
11
|
/**
|
package/dist/color/models.d.mts
CHANGED
|
@@ -6,16 +6,46 @@ type Alpha = {
|
|
|
6
6
|
type ColorWithAlpha = {
|
|
7
7
|
alpha: number;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* An _HSL_-color with an alpha channel
|
|
11
|
+
*/
|
|
9
12
|
type HSLAColor = HSLColor & ColorWithAlpha;
|
|
13
|
+
/**
|
|
14
|
+
* An _HSL_-color
|
|
15
|
+
*/
|
|
10
16
|
type HSLColor = {
|
|
17
|
+
/**
|
|
18
|
+
* Hue of the color _(in degrees; 0-360)_
|
|
19
|
+
*/
|
|
11
20
|
hue: number;
|
|
21
|
+
/**
|
|
22
|
+
* Lightness of the color _(in percentage; 0-100)_
|
|
23
|
+
*/
|
|
12
24
|
lightness: number;
|
|
25
|
+
/**
|
|
26
|
+
* Saturation of the color _(in percentage; 0-100)_
|
|
27
|
+
*/
|
|
13
28
|
saturation: number;
|
|
14
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* An _RGB_-color with an alpha channel
|
|
32
|
+
*/
|
|
15
33
|
type RGBAColor = RGBColor & ColorWithAlpha;
|
|
34
|
+
/**
|
|
35
|
+
* An _RGB_-color
|
|
36
|
+
*/
|
|
16
37
|
type RGBColor = {
|
|
38
|
+
/**
|
|
39
|
+
* Blue channel of the color _(in hexadecimal; 0-255)_
|
|
40
|
+
*/
|
|
17
41
|
blue: number;
|
|
42
|
+
/**
|
|
43
|
+
* Green channel of the color _(in hexadecimal; 0-255)_
|
|
44
|
+
*/
|
|
18
45
|
green: number;
|
|
46
|
+
/**
|
|
47
|
+
* Red channel of the color _(in hexadecimal; 0-255)_
|
|
48
|
+
*/
|
|
19
49
|
red: number;
|
|
20
50
|
};
|
|
21
51
|
type ColorProperty = 'alpha' | 'blue' | 'green' | 'hue' | 'lightness' | 'red' | 'saturation';
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { Constructor } from "../models.mjs";
|
|
1
|
+
import { Constructor, NestedKeys, NestedValue, PlainObject } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/function/assert.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Asserter for a nested property of a value
|
|
6
|
+
*/
|
|
7
|
+
type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted extends NestedPick<Value, Path> = NestedPick<Value, Path>> = Asserter<Asserted>;
|
|
8
|
+
/**
|
|
9
|
+
* A function that asserts a value is of a specific type, throwing an error if it is not
|
|
10
|
+
*/
|
|
4
11
|
type Asserter<Value> = (value: unknown) => asserts value is Value;
|
|
12
|
+
type NestedPick<Value, Path extends string> = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: NestedPick<Value[Key], Rest> } : never : Path extends keyof Value ? { [Key in Path]: Value[Key] } : never : never;
|
|
5
13
|
/**
|
|
6
14
|
* Asserts that a condition is true, throwing an error if it is not
|
|
7
15
|
* @param condition Condition to assert
|
|
8
16
|
* @param message Error message
|
|
9
|
-
* @param error Error constructor
|
|
17
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
10
18
|
*/
|
|
11
19
|
declare function assert<Condition extends () => boolean>(condition: Condition, message: string, error?: ErrorConstructor): asserts condition;
|
|
12
20
|
declare namespace assert {
|
|
@@ -14,6 +22,7 @@ declare namespace assert {
|
|
|
14
22
|
var defined: typeof assertDefined;
|
|
15
23
|
var instanceOf: typeof assertInstanceOf;
|
|
16
24
|
var is: typeof assertIs;
|
|
25
|
+
var property: typeof assertProperty;
|
|
17
26
|
}
|
|
18
27
|
/**
|
|
19
28
|
* Creates an asserter that asserts a condition is true, throwing an error if it is not
|
|
@@ -21,25 +30,26 @@ declare namespace assert {
|
|
|
21
30
|
* Available as `assertCondition` and `assert.condition`
|
|
22
31
|
* @param condition Condition to assert
|
|
23
32
|
* @param message Error message
|
|
24
|
-
* @param error Error constructor
|
|
33
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
25
34
|
* @returns Asserter
|
|
26
35
|
*/
|
|
27
36
|
declare function assertCondition<Value>(condition: (value: unknown) => boolean, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
28
37
|
/**
|
|
29
|
-
* Asserts that a value is defined throwing an error if it is not
|
|
38
|
+
* Asserts that a value is defined, throwing an error if it is not
|
|
30
39
|
*
|
|
31
40
|
* Available as `assertDefined` and `assert.defined`
|
|
32
41
|
* @param value Value to assert
|
|
33
42
|
* @param message Error message
|
|
43
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
34
44
|
*/
|
|
35
|
-
declare function assertDefined<Value>(value: unknown, message?: string): asserts value is Exclude<Value, null | undefined>;
|
|
45
|
+
declare function assertDefined<Value>(value: unknown, message?: string, error?: ErrorConstructor): asserts value is Exclude<Value, null | undefined>;
|
|
36
46
|
/**
|
|
37
47
|
* Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
38
48
|
*
|
|
39
49
|
* Available as `assertInstanceOf` and `assert.instanceOf`
|
|
40
50
|
* @param constructor Constructor to check against
|
|
41
51
|
* @param message Error message
|
|
42
|
-
* @param error Error constructor
|
|
52
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
43
53
|
* @returns Asserter
|
|
44
54
|
*/
|
|
45
55
|
declare function assertInstanceOf<Value>(constructor: Constructor<Value>, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
@@ -49,9 +59,20 @@ declare function assertInstanceOf<Value>(constructor: Constructor<Value>, messag
|
|
|
49
59
|
* Available as `assertIs` and `assert.is`
|
|
50
60
|
* @param condition Type guard function to check the value
|
|
51
61
|
* @param message Error message
|
|
52
|
-
* @param error Error constructor
|
|
62
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
53
63
|
* @returns Asserter
|
|
54
64
|
*/
|
|
55
65
|
declare function assertIs<Value>(condition: (value: unknown) => value is Value, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
66
|
+
/**
|
|
67
|
+
* Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
68
|
+
*
|
|
69
|
+
* Available as `assertProperty` and `assert.property`
|
|
70
|
+
* @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
|
|
71
|
+
* @param condition Condition to assert for the property
|
|
72
|
+
* @param message Error message
|
|
73
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
74
|
+
* @returns Asserter
|
|
75
|
+
*/
|
|
76
|
+
declare function assertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted = NestedPick<Value, Path>>(path: Path, condition: (value: NestedValue<Value, Path>) => boolean, message: string, error?: ErrorConstructor): Asserter<Asserted>;
|
|
56
77
|
//#endregion
|
|
57
|
-
export { Asserter, assert, assertCondition, assertDefined, assertInstanceOf, assertIs };
|
|
78
|
+
export { AssertProperty, Asserter, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty };
|
package/dist/function/assert.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { hasValueResult } from "../internal/value/has.mjs";
|
|
1
2
|
//#region src/function/assert.ts
|
|
2
3
|
/**
|
|
3
4
|
* Asserts that a condition is true, throwing an error if it is not
|
|
4
5
|
* @param condition Condition to assert
|
|
5
6
|
* @param message Error message
|
|
6
|
-
* @param error Error constructor
|
|
7
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
7
8
|
*/
|
|
8
9
|
function assert(condition, message, error) {
|
|
9
10
|
if (!condition()) throw new (error ?? Error)(message);
|
|
@@ -12,13 +13,14 @@ assert.condition = assertCondition;
|
|
|
12
13
|
assert.defined = assertDefined;
|
|
13
14
|
assert.instanceOf = assertInstanceOf;
|
|
14
15
|
assert.is = assertIs;
|
|
16
|
+
assert.property = assertProperty;
|
|
15
17
|
/**
|
|
16
18
|
* Creates an asserter that asserts a condition is true, throwing an error if it is not
|
|
17
19
|
*
|
|
18
20
|
* Available as `assertCondition` and `assert.condition`
|
|
19
21
|
* @param condition Condition to assert
|
|
20
22
|
* @param message Error message
|
|
21
|
-
* @param error Error constructor
|
|
23
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
22
24
|
* @returns Asserter
|
|
23
25
|
*/
|
|
24
26
|
function assertCondition(condition, message, error) {
|
|
@@ -27,14 +29,15 @@ function assertCondition(condition, message, error) {
|
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
|
-
* Asserts that a value is defined throwing an error if it is not
|
|
32
|
+
* Asserts that a value is defined, throwing an error if it is not
|
|
31
33
|
*
|
|
32
34
|
* Available as `assertDefined` and `assert.defined`
|
|
33
35
|
* @param value Value to assert
|
|
34
36
|
* @param message Error message
|
|
37
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
35
38
|
*/
|
|
36
|
-
function assertDefined(value, message) {
|
|
37
|
-
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
|
|
39
|
+
function assertDefined(value, message, error) {
|
|
40
|
+
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED, error);
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
@@ -42,7 +45,7 @@ function assertDefined(value, message) {
|
|
|
42
45
|
* Available as `assertInstanceOf` and `assert.instanceOf`
|
|
43
46
|
* @param constructor Constructor to check against
|
|
44
47
|
* @param message Error message
|
|
45
|
-
* @param error Error constructor
|
|
48
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
46
49
|
* @returns Asserter
|
|
47
50
|
*/
|
|
48
51
|
function assertInstanceOf(constructor, message, error) {
|
|
@@ -56,7 +59,7 @@ function assertInstanceOf(constructor, message, error) {
|
|
|
56
59
|
* Available as `assertIs` and `assert.is`
|
|
57
60
|
* @param condition Type guard function to check the value
|
|
58
61
|
* @param message Error message
|
|
59
|
-
* @param error Error constructor
|
|
62
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
60
63
|
* @returns Asserter
|
|
61
64
|
*/
|
|
62
65
|
function assertIs(condition, message, error) {
|
|
@@ -64,6 +67,24 @@ function assertIs(condition, message, error) {
|
|
|
64
67
|
assert(() => condition(value), message, error);
|
|
65
68
|
};
|
|
66
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
72
|
+
*
|
|
73
|
+
* Available as `assertProperty` and `assert.property`
|
|
74
|
+
* @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
|
|
75
|
+
* @param condition Condition to assert for the property
|
|
76
|
+
* @param message Error message
|
|
77
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
78
|
+
* @returns Asserter
|
|
79
|
+
*/
|
|
80
|
+
function assertProperty(path, condition, message, error) {
|
|
81
|
+
return (value) => {
|
|
82
|
+
assert(() => {
|
|
83
|
+
const result = hasValueResult(value, path, false);
|
|
84
|
+
return result.ok && condition(result.value);
|
|
85
|
+
}, message, error);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
67
88
|
const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
68
89
|
//#endregion
|
|
69
|
-
export { assert, assertCondition, assertDefined, assertInstanceOf, assertIs };
|
|
90
|
+
export { assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { GenericCallback } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/function/memoize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
6
|
+
*/
|
|
4
7
|
declare class Memoized<Callback extends GenericCallback> {
|
|
5
8
|
#private;
|
|
6
9
|
/**
|
|
@@ -2,6 +2,9 @@ import { isPlainObject } from "../internal/is.mjs";
|
|
|
2
2
|
import { getString, join } from "../internal/string.mjs";
|
|
3
3
|
import { SizedMap } from "../sized/map.mjs";
|
|
4
4
|
//#region src/function/memoize.ts
|
|
5
|
+
/**
|
|
6
|
+
* A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
7
|
+
*/
|
|
5
8
|
var Memoized = class {
|
|
6
9
|
#state;
|
|
7
10
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { GenericAsyncCallback, GenericCallback } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/function/retry.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* An error thrown when a retry fails
|
|
6
|
+
*/
|
|
4
7
|
declare class RetryError extends Error {
|
|
5
8
|
readonly original: unknown;
|
|
6
9
|
constructor(message: string, original: unknown);
|
package/dist/function/retry.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isPlainObject } from "../internal/is.mjs";
|
|
2
2
|
import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
|
|
3
3
|
//#region src/function/retry.ts
|
|
4
|
+
/**
|
|
5
|
+
* An error thrown when a retry fails
|
|
6
|
+
*/
|
|
4
7
|
var RetryError = class extends Error {
|
|
5
8
|
constructor(message, original) {
|
|
6
9
|
super(message);
|