@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.
Files changed (156) hide show
  1. package/dist/array/difference.d.mts +29 -0
  2. package/dist/array/exists.d.mts +35 -0
  3. package/dist/array/filter.d.mts +72 -2
  4. package/dist/array/find.d.mts +70 -0
  5. package/dist/array/first.d.mts +77 -2
  6. package/dist/array/flatten.d.mts +6 -0
  7. package/dist/array/flatten.mjs +6 -0
  8. package/dist/array/from.d.mts +36 -0
  9. package/dist/array/get.d.mts +21 -13
  10. package/dist/array/group-by.d.mts +142 -0
  11. package/dist/array/index.d.mts +2 -2
  12. package/dist/array/index.mjs +2 -2
  13. package/dist/array/insert.d.mts +16 -0
  14. package/dist/array/intersection.d.mts +29 -0
  15. package/dist/array/last.d.mts +75 -2
  16. package/dist/array/{position.d.mts → match.d.mts} +168 -36
  17. package/dist/array/{position.mjs → match.mjs} +16 -16
  18. package/dist/array/move.d.mts +78 -8
  19. package/dist/array/move.mjs +11 -1
  20. package/dist/array/partition.d.mts +35 -0
  21. package/dist/array/push.d.mts +8 -0
  22. package/dist/array/push.mjs +8 -0
  23. package/dist/array/reverse.d.mts +1 -0
  24. package/dist/array/reverse.mjs +1 -0
  25. package/dist/array/select.d.mts +94 -8
  26. package/dist/array/single.d.mts +29 -0
  27. package/dist/array/slice.d.mts +106 -16
  28. package/dist/array/sort.d.mts +30 -4
  29. package/dist/array/sort.mjs +1 -1
  30. package/dist/array/splice.d.mts +48 -0
  31. package/dist/array/splice.mjs +2 -1
  32. package/dist/array/swap.d.mts +113 -8
  33. package/dist/array/swap.mjs +2 -1
  34. package/dist/array/to-map.d.mts +124 -0
  35. package/dist/array/to-record.d.mts +124 -0
  36. package/dist/array/to-set.d.mts +24 -0
  37. package/dist/array/toggle.d.mts +38 -3
  38. package/dist/array/union.d.mts +29 -0
  39. package/dist/array/unique.d.mts +24 -0
  40. package/dist/array/update.d.mts +38 -3
  41. package/dist/beacon.d.mts +12 -0
  42. package/dist/beacon.mjs +9 -0
  43. package/dist/color/instance.d.mts +8 -0
  44. package/dist/color/instance.mjs +3 -0
  45. package/dist/color/models.d.mts +30 -0
  46. package/dist/function/assert.d.mts +29 -8
  47. package/dist/function/assert.mjs +29 -8
  48. package/dist/function/memoize.d.mts +3 -0
  49. package/dist/function/memoize.mjs +3 -0
  50. package/dist/function/retry.d.mts +3 -0
  51. package/dist/function/retry.mjs +3 -0
  52. package/dist/function/work.mjs +1 -1
  53. package/dist/index.d.mts +2158 -288
  54. package/dist/index.mjs +294 -181
  55. package/dist/internal/array/chunk.d.mts +6 -0
  56. package/dist/internal/array/chunk.mjs +6 -0
  57. package/dist/internal/array/compact.d.mts +12 -0
  58. package/dist/internal/array/index-of.d.mts +70 -0
  59. package/dist/internal/math/aggregate.d.mts +29 -0
  60. package/dist/internal/value/compare.d.mts +2 -1
  61. package/dist/internal/value/equal.d.mts +5 -0
  62. package/dist/internal/value/get.d.mts +27 -5
  63. package/dist/internal/value/has.d.mts +7 -7
  64. package/dist/internal/value/has.mjs +1 -1
  65. package/dist/internal/value/misc.d.mts +2 -2
  66. package/dist/internal/value/misc.mjs +10 -4
  67. package/dist/logger.d.mts +11 -0
  68. package/dist/logger.mjs +11 -0
  69. package/dist/models.d.mts +14 -1
  70. package/dist/promise/helpers.mjs +1 -1
  71. package/dist/promise/index.d.mts +0 -6
  72. package/dist/promise/models.d.mts +36 -0
  73. package/dist/promise/models.mjs +6 -0
  74. package/dist/queue.d.mts +13 -1
  75. package/dist/queue.mjs +9 -0
  76. package/dist/result/index.d.mts +0 -8
  77. package/dist/result/index.mjs +0 -8
  78. package/dist/result/match.d.mts +4 -4
  79. package/dist/result/work/flow.d.mts +12 -36
  80. package/dist/result/work/pipe.d.mts +11 -33
  81. package/dist/sized/set.d.mts +3 -2
  82. package/dist/sized/set.mjs +3 -2
  83. package/dist/value/collection.d.mts +1 -1
  84. package/dist/value/handle.mjs +1 -1
  85. package/dist/value/merge.d.mts +28 -25
  86. package/dist/value/merge.mjs +29 -18
  87. package/dist/value/shake.d.mts +3 -0
  88. package/dist/value/smush.d.mts +3 -0
  89. package/dist/value/transform.d.mts +10 -1
  90. package/dist/value/unsmush.d.mts +2 -3
  91. package/package.json +5 -5
  92. package/src/array/difference.ts +33 -0
  93. package/src/array/exists.ts +35 -0
  94. package/src/array/filter.ts +72 -2
  95. package/src/array/find.ts +70 -0
  96. package/src/array/first.ts +77 -3
  97. package/src/array/flatten.ts +6 -0
  98. package/src/array/from.ts +40 -0
  99. package/src/array/get.ts +21 -15
  100. package/src/array/group-by.ts +142 -0
  101. package/src/array/index.ts +1 -1
  102. package/src/array/insert.ts +16 -2
  103. package/src/array/intersection.ts +33 -0
  104. package/src/array/last.ts +75 -2
  105. package/src/array/{position.ts → match.ts} +197 -65
  106. package/src/array/move.ts +87 -13
  107. package/src/array/partition.ts +35 -0
  108. package/src/array/push.ts +8 -2
  109. package/src/array/reverse.ts +5 -0
  110. package/src/array/select.ts +96 -13
  111. package/src/array/single.ts +29 -0
  112. package/src/array/slice.ts +114 -24
  113. package/src/array/sort.ts +30 -4
  114. package/src/array/splice.ts +52 -4
  115. package/src/array/swap.ts +122 -13
  116. package/src/array/to-map.ts +124 -0
  117. package/src/array/to-record.ts +124 -0
  118. package/src/array/to-set.ts +24 -0
  119. package/src/array/toggle.ts +42 -3
  120. package/src/array/union.ts +33 -0
  121. package/src/array/unique.ts +24 -0
  122. package/src/array/update.ts +38 -3
  123. package/src/beacon.ts +12 -0
  124. package/src/color/index.ts +0 -3
  125. package/src/color/instance.ts +9 -1
  126. package/src/color/models.ts +30 -0
  127. package/src/function/assert.ts +66 -7
  128. package/src/function/memoize.ts +3 -0
  129. package/src/function/once.ts +5 -1
  130. package/src/function/retry.ts +3 -0
  131. package/src/internal/array/chunk.ts +6 -0
  132. package/src/internal/array/compact.ts +12 -0
  133. package/src/internal/array/index-of.ts +70 -0
  134. package/src/internal/math/aggregate.ts +29 -0
  135. package/src/internal/string.ts +0 -2
  136. package/src/internal/value/compare.ts +2 -1
  137. package/src/internal/value/equal.ts +5 -0
  138. package/src/internal/value/get.ts +27 -5
  139. package/src/internal/value/has.ts +10 -10
  140. package/src/internal/value/misc.ts +24 -13
  141. package/src/logger.ts +11 -0
  142. package/src/models.ts +18 -0
  143. package/src/promise/index.ts +0 -6
  144. package/src/promise/models.ts +36 -0
  145. package/src/queue.ts +13 -1
  146. package/src/result/index.ts +0 -8
  147. package/src/result/match.ts +4 -4
  148. package/src/result/work/flow.ts +12 -36
  149. package/src/result/work/pipe.ts +11 -33
  150. package/src/sized/set.ts +4 -3
  151. package/src/value/collection.ts +1 -1
  152. package/src/value/merge.ts +88 -66
  153. package/src/value/shake.ts +3 -0
  154. package/src/value/smush.ts +3 -0
  155. package/src/value/transform.ts +10 -1
  156. package/src/value/unsmush.ts +2 -8
@@ -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
@@ -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: if the item exists, it will be removed; if it doesn't, it will be added
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: if the item exists, it will be removed; if it doesn't, it will be added
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: if the item exists, it will be removed; if it doesn't, it will be added
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
@@ -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
@@ -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
@@ -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: if the item exists, it will be updated; if it doesn't, it will be added
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: if the item exists, it will be updated; if it doesn't, it will be added
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: if the item exists, it will be updated; if it doesn't, it will be added
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
@@ -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
  /**
@@ -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 };
@@ -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);
@@ -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);
@@ -1,5 +1,5 @@
1
- import { assert } from "./assert.mjs";
2
1
  import { isError, isOk } from "../internal/result.mjs";
2
+ import { assert } from "./assert.mjs";
3
3
  //#region src/function/work.ts
4
4
  function asyncFlow(...fns) {
5
5
  assertFlowFunctions(fns);