@oscarpalmer/atoms 0.184.2 → 0.185.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 (88) hide show
  1. package/dist/array/index.d.mts +2 -2
  2. package/dist/array/index.mjs +2 -2
  3. package/dist/array/{position.d.mts → match.d.mts} +9 -6
  4. package/dist/array/{position.mjs → match.mjs} +16 -16
  5. package/dist/array/move.mjs +1 -1
  6. package/dist/array/sort.d.mts +9 -4
  7. package/dist/array/sort.mjs +1 -1
  8. package/dist/array/swap.mjs +1 -1
  9. package/dist/beacon.d.mts +12 -0
  10. package/dist/beacon.mjs +9 -0
  11. package/dist/color/instance.d.mts +8 -0
  12. package/dist/color/instance.mjs +3 -0
  13. package/dist/color/models.d.mts +30 -0
  14. package/dist/function/assert.d.mts +29 -8
  15. package/dist/function/assert.mjs +29 -8
  16. package/dist/function/memoize.d.mts +3 -0
  17. package/dist/function/memoize.mjs +3 -0
  18. package/dist/function/retry.d.mts +3 -0
  19. package/dist/function/retry.mjs +3 -0
  20. package/dist/function/work.mjs +1 -1
  21. package/dist/index.d.mts +271 -158
  22. package/dist/index.mjs +230 -163
  23. package/dist/internal/value/compare.d.mts +2 -1
  24. package/dist/internal/value/equal.d.mts +5 -0
  25. package/dist/internal/value/get.d.mts +2 -2
  26. package/dist/internal/value/has.d.mts +3 -3
  27. package/dist/internal/value/has.mjs +1 -1
  28. package/dist/internal/value/misc.d.mts +2 -2
  29. package/dist/internal/value/misc.mjs +10 -4
  30. package/dist/logger.d.mts +11 -0
  31. package/dist/logger.mjs +11 -0
  32. package/dist/promise/helpers.mjs +1 -1
  33. package/dist/promise/index.d.mts +0 -6
  34. package/dist/promise/models.d.mts +36 -0
  35. package/dist/promise/models.mjs +6 -0
  36. package/dist/queue.d.mts +13 -1
  37. package/dist/queue.mjs +9 -0
  38. package/dist/result/index.d.mts +0 -8
  39. package/dist/result/index.mjs +0 -8
  40. package/dist/result/match.d.mts +4 -4
  41. package/dist/result/work/flow.d.mts +12 -36
  42. package/dist/result/work/pipe.d.mts +11 -33
  43. package/dist/sized/set.d.mts +3 -2
  44. package/dist/sized/set.mjs +3 -2
  45. package/dist/value/handle.mjs +1 -1
  46. package/dist/value/shake.d.mts +3 -0
  47. package/dist/value/smush.d.mts +3 -0
  48. package/dist/value/transform.d.mts +9 -0
  49. package/dist/value/unsmush.d.mts +3 -0
  50. package/package.json +2 -2
  51. package/src/array/difference.ts +4 -0
  52. package/src/array/from.ts +4 -0
  53. package/src/array/index.ts +1 -1
  54. package/src/array/intersection.ts +4 -0
  55. package/src/array/{position.ts → match.ts} +28 -25
  56. package/src/array/move.ts +5 -1
  57. package/src/array/reverse.ts +4 -0
  58. package/src/array/select.ts +2 -0
  59. package/src/array/sort.ts +9 -4
  60. package/src/array/swap.ts +5 -1
  61. package/src/array/toggle.ts +4 -0
  62. package/src/array/union.ts +4 -0
  63. package/src/beacon.ts +12 -0
  64. package/src/color/index.ts +0 -3
  65. package/src/color/instance.ts +9 -1
  66. package/src/color/models.ts +30 -0
  67. package/src/function/assert.ts +66 -7
  68. package/src/function/memoize.ts +3 -0
  69. package/src/function/once.ts +5 -1
  70. package/src/function/retry.ts +3 -0
  71. package/src/internal/value/compare.ts +2 -1
  72. package/src/internal/value/equal.ts +5 -0
  73. package/src/internal/value/get.ts +2 -2
  74. package/src/internal/value/has.ts +6 -6
  75. package/src/internal/value/misc.ts +24 -13
  76. package/src/logger.ts +11 -0
  77. package/src/promise/index.ts +0 -6
  78. package/src/promise/models.ts +36 -0
  79. package/src/queue.ts +13 -1
  80. package/src/result/index.ts +0 -8
  81. package/src/result/match.ts +4 -4
  82. package/src/result/work/flow.ts +12 -36
  83. package/src/result/work/pipe.ts +11 -33
  84. package/src/sized/set.ts +4 -3
  85. package/src/value/shake.ts +3 -0
  86. package/src/value/smush.ts +3 -0
  87. package/src/value/transform.ts +9 -0
  88. package/src/value/unsmush.ts +3 -0
@@ -11,7 +11,7 @@ import { shuffle } from "../internal/array/shuffle.mjs";
11
11
  import { insert } from "./insert.mjs";
12
12
  import { intersection } from "./intersection.mjs";
13
13
  import { partition } from "./partition.mjs";
14
- import { ArrayPosition, endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray } from "./position.mjs";
14
+ import { ArrayComparison, endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray } from "./match.mjs";
15
15
  import { push } from "./push.mjs";
16
16
  import { reverse } from "./reverse.mjs";
17
17
  import { select } from "./select.mjs";
@@ -23,4 +23,4 @@ import { toggle } from "./toggle.mjs";
23
23
  import { union } from "./union.mjs";
24
24
  import { unique } from "./unique.mjs";
25
25
  import { update } from "./update.mjs";
26
- export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
26
+ export { ArrayComparison, chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayComparison, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
@@ -11,7 +11,7 @@ import { getArray } from "./get.mjs";
11
11
  import { insert } from "./insert.mjs";
12
12
  import { intersection } from "./intersection.mjs";
13
13
  import { partition } from "./partition.mjs";
14
- import { endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray } from "./position.mjs";
14
+ import { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray } from "./match.mjs";
15
15
  import { push } from "./push.mjs";
16
16
  import { reverse } from "./reverse.mjs";
17
17
  import { select } from "./select.mjs";
@@ -23,4 +23,4 @@ import { toggle } from "./toggle.mjs";
23
23
  import { union } from "./union.mjs";
24
24
  import { unique } from "./unique.mjs";
25
25
  import { update } from "./update.mjs";
26
- export { chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
26
+ export { chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayComparison, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
@@ -1,7 +1,10 @@
1
1
  import { PlainObject } from "../models.mjs";
2
2
 
3
- //#region src/array/position.d.ts
4
- type ArrayPosition = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
3
+ //#region src/array/match.d.ts
4
+ /**
5
+ * Comparison of an array within another array
6
+ */
7
+ type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
5
8
  /**
6
9
  * Does the needle array end the haystack array?
7
10
  * @param haystack Haystack array
@@ -32,7 +35,7 @@ declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
32
35
  * @param key Key to get an item's value for matching
33
36
  * @returns Position of the needle within the haystack
34
37
  */
35
- declare function getArrayPosition<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayPosition;
38
+ declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
36
39
  /**
37
40
  * Get the position of an array within another array
38
41
  * @param haystack Haystack array
@@ -40,14 +43,14 @@ declare function getArrayPosition<Item extends PlainObject>(haystack: Item[], ne
40
43
  * @param callback Callback to get an item's value for matching
41
44
  * @returns Position of the needle within the haystack
42
45
  */
43
- declare function getArrayPosition<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayPosition;
46
+ declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
44
47
  /**
45
48
  * Get the position of an array within another array
46
49
  * @param haystack Haystack array
47
50
  * @param needle Needle array
48
51
  * @returns Position of the needle within the haystack
49
52
  */
50
- declare function getArrayPosition<Item>(haystack: Item[], needle: Item[]): ArrayPosition;
53
+ declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
51
54
  /**
52
55
  * Does the needle array exist within the haystack array?
53
56
  * @param haystack Haystack array
@@ -118,4 +121,4 @@ declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callbac
118
121
  */
119
122
  declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
120
123
  //#endregion
121
- export { ArrayPosition, endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray };
124
+ export { ArrayComparison, endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
@@ -1,14 +1,14 @@
1
1
  import { getArrayCallback } from "../internal/array/callbacks.mjs";
2
- //#region src/array/position.ts
2
+ //#region src/array/match.ts
3
3
  function endsWithArray(haystack, needle, key) {
4
4
  return endings.has(getPosition(haystack, needle, key)[1]);
5
5
  }
6
- function getArrayPosition(haystack, needle, key) {
6
+ function getArrayComparison(haystack, needle, key) {
7
7
  return getPosition(haystack, needle, key)[1];
8
8
  }
9
9
  function getName(start, haystack, needle) {
10
- if (start === 0) return haystack === needle ? POSITION_SAME : POSITION_START;
11
- return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
10
+ if (start === 0) return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
11
+ return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
12
12
  }
13
13
  function getPosition(haystack, needle, key) {
14
14
  if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
@@ -43,16 +43,16 @@ function indexOfArray(haystack, needle, key) {
43
43
  function startsWithArray(haystack, needle, key) {
44
44
  return starts.has(getPosition(haystack, needle, key)[1]);
45
45
  }
46
- const POSITION_END = "end";
47
- const POSITION_INSIDE = "inside";
48
- const POSITION_INVALID = "invalid";
49
- const POSITION_OUTSIDE = "outside";
50
- const POSITION_SAME = "same";
51
- const POSITION_START = "start";
52
- const endings = new Set([POSITION_END, POSITION_SAME]);
53
- const invalid = [-1, POSITION_INVALID];
54
- const outside = [-1, POSITION_OUTSIDE];
55
- const outsides = new Set([POSITION_INVALID, POSITION_OUTSIDE]);
56
- const starts = new Set([POSITION_START, POSITION_SAME]);
46
+ const COMPARISON_END = "end";
47
+ const COMPARISON_INSIDE = "inside";
48
+ const COMPARISON_INVALID = "invalid";
49
+ const COMPARISON_OUTSIDE = "outside";
50
+ const COMPARISON_SAME = "same";
51
+ const COMPARISON_START = "start";
52
+ const endings = new Set([COMPARISON_END, COMPARISON_SAME]);
53
+ const invalid = [-1, COMPARISON_INVALID];
54
+ const outside = [-1, COMPARISON_OUTSIDE];
55
+ const outsides = new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
56
+ const starts = new Set([COMPARISON_START, COMPARISON_SAME]);
57
57
  //#endregion
58
- export { endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray };
58
+ export { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
@@ -1,4 +1,4 @@
1
- import { indexOfArray } from "./position.mjs";
1
+ import { indexOfArray } from "./match.mjs";
2
2
  import { arraysOverlap } from "../internal/array/overlap.mjs";
3
3
  //#region src/array/move.ts
4
4
  function move(array, from, to, key) {
@@ -65,6 +65,11 @@ type ComparisonSorter<Item> = (first: Item, second: Item) => number;
65
65
  * Direction to sort by
66
66
  */
67
67
  type SortDirection = 'ascending' | 'descending';
68
+ /**
69
+ * Sorter for an array with predefined sorters
70
+ *
71
+ * Can be used to sort an array, get the predicted index for an item, and check if an array is sorted
72
+ */
68
73
  type Sorter<Item> = {
69
74
  /**
70
75
  * Sort an array of items
@@ -93,7 +98,7 @@ type Sorter<Item> = {
93
98
  *
94
99
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
95
100
  *
96
- * Available as `getSortedIndex` and `sort.index`
101
+ * Available as `getSortedIndex` and `sort.getIndex`
97
102
  * @param array Array to get the index from
98
103
  * @param item Item to get the index for
99
104
  * @param sorters Sorters to use to determine sorting
@@ -106,7 +111,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<
106
111
  *
107
112
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
108
113
  *
109
- * Available as `getSortedIndex` and `sort.index`
114
+ * Available as `getSortedIndex` and `sort.getIndex`
110
115
  * @param array Array to get the index from
111
116
  * @param item Item to get the index for
112
117
  * @param sorter Sorter to use to determine sorting
@@ -119,7 +124,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySo
119
124
  *
120
125
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
121
126
  *
122
- * Available as `getSortedIndex` and `sort.index`
127
+ * Available as `getSortedIndex` and `sort.getIndex`
123
128
  * @param array Array to get the index from
124
129
  * @param item Item to get the index for
125
130
  * @param descending Sorted in descending order? _(defaults to `false`)_
@@ -209,7 +214,7 @@ declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending
209
214
  */
210
215
  declare function sort<Item>(array: Item[], descending?: boolean): Item[];
211
216
  declare namespace sort {
212
- var index: typeof getSortedIndex;
217
+ var getIndex: typeof getSortedIndex;
213
218
  var initialize: typeof initializeSorter;
214
219
  var is: typeof isSorted;
215
220
  }
@@ -124,7 +124,7 @@ function sortArray(array, sorters) {
124
124
  const { length } = sorters;
125
125
  return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
126
126
  }
127
- sort.index = getSortedIndex;
127
+ sort.getIndex = getSortedIndex;
128
128
  sort.initialize = initializeSorter;
129
129
  sort.is = isSorted;
130
130
  const SORT_PEEK_PERCENTAGE = 10;
@@ -1,6 +1,6 @@
1
1
  import { getArrayCallback } from "../internal/array/callbacks.mjs";
2
2
  import { indexOf } from "../internal/array/index-of.mjs";
3
- import { indexOfArray } from "./position.mjs";
3
+ import { indexOfArray } from "./match.mjs";
4
4
  import { arraysOverlap } from "../internal/array/overlap.mjs";
5
5
  //#region src/array/swap.ts
6
6
  function swap(array, first, second, third) {
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);