@oscarpalmer/atoms 0.186.2 → 0.187.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 (229) hide show
  1. package/dist/array/filter.d.mts +4 -4
  2. package/dist/array/find.d.mts +4 -4
  3. package/dist/array/first.d.mts +4 -4
  4. package/dist/array/get.d.mts +27 -1
  5. package/dist/array/get.mjs +5 -3
  6. package/dist/array/group-by.d.mts +6 -6
  7. package/dist/array/last.d.mts +4 -4
  8. package/dist/array/match.d.mts +7 -6
  9. package/dist/array/move.d.mts +7 -7
  10. package/dist/array/move.mjs +1 -1
  11. package/dist/array/select.d.mts +1 -0
  12. package/dist/array/slice.d.mts +3 -3
  13. package/dist/array/sort.d.mts +10 -7
  14. package/dist/array/sort.mjs +4 -3
  15. package/dist/array/swap.d.mts +1 -1
  16. package/dist/array/swap.mjs +1 -1
  17. package/dist/array/to-map.d.mts +32 -32
  18. package/dist/array/to-record.d.mts +6 -6
  19. package/dist/array/to-set.d.mts +6 -6
  20. package/dist/beacon.d.mts +6 -0
  21. package/dist/beacon.mjs +3 -0
  22. package/dist/color/index.d.mts +6 -2
  23. package/dist/color/index.mjs +6 -2
  24. package/dist/color/instance.d.mts +78 -14
  25. package/dist/color/instance.mjs +78 -14
  26. package/dist/color/misc/get.d.mts +39 -11
  27. package/dist/color/misc/get.mjs +39 -11
  28. package/dist/color/misc/is.d.mts +26 -11
  29. package/dist/color/misc/is.mjs +26 -11
  30. package/dist/color/misc/state.mjs +1 -1
  31. package/dist/color/models.d.mts +7 -4
  32. package/dist/color/space/hex.d.mts +15 -6
  33. package/dist/color/space/hex.mjs +15 -6
  34. package/dist/color/space/hsl.d.mts +10 -4
  35. package/dist/color/space/hsl.mjs +10 -4
  36. package/dist/color/space/rgb.d.mts +21 -12
  37. package/dist/color/space/rgb.mjs +21 -12
  38. package/dist/function/assert.d.mts +20 -14
  39. package/dist/function/assert.mjs +19 -13
  40. package/dist/function/limit.d.mts +8 -6
  41. package/dist/function/limit.mjs +8 -6
  42. package/dist/function/memoize.d.mts +15 -4
  43. package/dist/function/memoize.mjs +18 -4
  44. package/dist/function/once.d.mts +5 -3
  45. package/dist/function/once.mjs +5 -3
  46. package/dist/function/retry.d.mts +5 -2
  47. package/dist/function/retry.mjs +3 -1
  48. package/dist/function/work.d.mts +146 -98
  49. package/dist/{kalas.d.mts → herald.d.mts} +17 -8
  50. package/dist/{kalas.mjs → herald.mjs} +22 -13
  51. package/dist/index.d.mts +1464 -708
  52. package/dist/index.mjs +677 -324
  53. package/dist/internal/array/index-of.d.mts +4 -4
  54. package/dist/internal/array/insert.mjs +1 -1
  55. package/dist/internal/array/shuffle.d.mts +1 -0
  56. package/dist/internal/array/shuffle.mjs +2 -1
  57. package/dist/internal/is.d.mts +26 -8
  58. package/dist/internal/is.mjs +26 -8
  59. package/dist/internal/math/aggregate.d.mts +9 -9
  60. package/dist/internal/number.d.mts +13 -2
  61. package/dist/internal/number.mjs +13 -2
  62. package/dist/internal/random.d.mts +4 -2
  63. package/dist/internal/random.mjs +7 -5
  64. package/dist/internal/result.d.mts +17 -11
  65. package/dist/internal/result.mjs +10 -14
  66. package/dist/internal/string.d.mts +16 -1
  67. package/dist/internal/string.mjs +24 -1
  68. package/dist/internal/value/compare.d.mts +5 -2
  69. package/dist/internal/value/compare.mjs +5 -2
  70. package/dist/internal/value/equal.d.mts +12 -3
  71. package/dist/internal/value/equal.mjs +7 -4
  72. package/dist/internal/value/get.d.mts +17 -17
  73. package/dist/internal/value/has.d.mts +55 -11
  74. package/dist/internal/value/set.d.mts +24 -0
  75. package/dist/is.d.mts +12 -0
  76. package/dist/is.mjs +16 -1
  77. package/dist/logger.d.mts +7 -6
  78. package/dist/logger.mjs +6 -5
  79. package/dist/math.d.mts +36 -18
  80. package/dist/math.mjs +6 -3
  81. package/dist/models.d.mts +3 -3
  82. package/dist/promise/delay.d.mts +2 -0
  83. package/dist/promise/helpers.d.mts +6 -4
  84. package/dist/promise/helpers.mjs +6 -4
  85. package/dist/promise/index.d.mts +49 -38
  86. package/dist/promise/misc.d.mts +10 -7
  87. package/dist/promise/misc.mjs +4 -3
  88. package/dist/promise/models.d.mts +18 -19
  89. package/dist/promise/models.mjs +4 -3
  90. package/dist/promise/timed.d.mts +8 -6
  91. package/dist/query.d.mts +2 -0
  92. package/dist/query.mjs +2 -0
  93. package/dist/queue.d.mts +15 -4
  94. package/dist/queue.mjs +10 -3
  95. package/dist/random.d.mts +9 -2
  96. package/dist/random.mjs +7 -2
  97. package/dist/result/index.d.mts +14 -8
  98. package/dist/result/match.d.mts +18 -10
  99. package/dist/result/misc.d.mts +14 -7
  100. package/dist/result/misc.mjs +4 -2
  101. package/dist/result/models.d.mts +2 -0
  102. package/dist/result/work/flow.d.mts +86 -62
  103. package/dist/result/work/pipe.d.mts +55 -33
  104. package/dist/sized/map.d.mts +19 -16
  105. package/dist/sized/map.mjs +4 -4
  106. package/dist/sized/set.d.mts +20 -16
  107. package/dist/sized/set.mjs +8 -7
  108. package/dist/string/case.d.mts +8 -0
  109. package/dist/string/case.mjs +8 -0
  110. package/dist/string/fuzzy.d.mts +19 -5
  111. package/dist/string/fuzzy.mjs +7 -0
  112. package/dist/string/index.d.mts +17 -2
  113. package/dist/string/index.mjs +7 -9
  114. package/dist/string/match.d.mts +3 -0
  115. package/dist/string/match.mjs +3 -0
  116. package/dist/string/normalize.d.mts +6 -2
  117. package/dist/string/normalize.mjs +5 -2
  118. package/dist/string/template.d.mts +38 -9
  119. package/dist/string/template.mjs +19 -19
  120. package/dist/value/clone.d.mts +25 -4
  121. package/dist/value/clone.mjs +36 -22
  122. package/dist/value/collection.d.mts +9 -6
  123. package/dist/value/collection.mjs +3 -2
  124. package/dist/value/diff.d.mts +3 -1
  125. package/dist/value/diff.mjs +1 -0
  126. package/dist/value/freeze.d.mts +118 -9
  127. package/dist/value/freeze.mjs +56 -14
  128. package/dist/value/index.d.mts +1 -2
  129. package/dist/value/index.mjs +1 -2
  130. package/dist/value/merge.d.mts +11 -5
  131. package/dist/value/merge.mjs +2 -2
  132. package/dist/value/omit.d.mts +1 -0
  133. package/dist/value/omit.mjs +1 -0
  134. package/dist/value/pick.d.mts +1 -0
  135. package/dist/value/pick.mjs +1 -0
  136. package/dist/value/shake.d.mts +1 -0
  137. package/dist/value/shake.mjs +1 -0
  138. package/dist/value/smush.d.mts +1 -0
  139. package/dist/value/smush.mjs +1 -0
  140. package/dist/value/transform.d.mts +7 -3
  141. package/dist/value/unsmush.d.mts +1 -0
  142. package/dist/value/unsmush.mjs +1 -0
  143. package/package.json +11 -7
  144. package/src/array/filter.ts +4 -4
  145. package/src/array/find.ts +4 -4
  146. package/src/array/first.ts +4 -4
  147. package/src/array/get.ts +40 -5
  148. package/src/array/group-by.ts +6 -6
  149. package/src/array/last.ts +4 -4
  150. package/src/array/match.ts +7 -6
  151. package/src/array/move.ts +7 -7
  152. package/src/array/select.ts +1 -0
  153. package/src/array/slice.ts +3 -3
  154. package/src/array/sort.ts +15 -10
  155. package/src/array/swap.ts +1 -1
  156. package/src/array/to-map.ts +32 -32
  157. package/src/array/to-record.ts +6 -6
  158. package/src/array/to-set.ts +6 -6
  159. package/src/beacon.ts +6 -0
  160. package/src/color/index.ts +6 -2
  161. package/src/color/instance.ts +78 -14
  162. package/src/color/misc/get.ts +39 -11
  163. package/src/color/misc/is.ts +26 -11
  164. package/src/color/misc/state.ts +1 -1
  165. package/src/color/models.ts +7 -4
  166. package/src/color/space/hex.ts +15 -6
  167. package/src/color/space/hsl.ts +10 -4
  168. package/src/color/space/rgb.ts +21 -12
  169. package/src/function/assert.ts +20 -14
  170. package/src/function/limit.ts +8 -6
  171. package/src/function/memoize.ts +24 -5
  172. package/src/function/once.ts +5 -3
  173. package/src/function/retry.ts +7 -3
  174. package/src/function/work.ts +146 -98
  175. package/src/{kalas.ts → herald.ts} +23 -14
  176. package/src/index.ts +3 -2
  177. package/src/internal/array/index-of.ts +4 -4
  178. package/src/internal/array/insert.ts +1 -1
  179. package/src/internal/array/shuffle.ts +2 -1
  180. package/src/internal/is.ts +26 -8
  181. package/src/internal/math/aggregate.ts +9 -9
  182. package/src/internal/number.ts +13 -2
  183. package/src/internal/random.ts +10 -4
  184. package/src/internal/result.ts +30 -29
  185. package/src/internal/string.ts +28 -0
  186. package/src/internal/value/compare.ts +5 -2
  187. package/src/internal/value/equal.ts +13 -4
  188. package/src/internal/value/get.ts +17 -17
  189. package/src/internal/value/has.ts +54 -11
  190. package/src/internal/value/set.ts +24 -0
  191. package/src/is.ts +15 -1
  192. package/src/logger.ts +8 -7
  193. package/src/math.ts +36 -18
  194. package/src/models.ts +3 -3
  195. package/src/promise/delay.ts +2 -0
  196. package/src/promise/helpers.ts +6 -4
  197. package/src/promise/index.ts +49 -38
  198. package/src/promise/misc.ts +10 -7
  199. package/src/promise/models.ts +18 -19
  200. package/src/promise/timed.ts +8 -6
  201. package/src/query.ts +2 -0
  202. package/src/queue.ts +15 -4
  203. package/src/random.ts +8 -1
  204. package/src/result/index.ts +14 -8
  205. package/src/result/match.ts +18 -10
  206. package/src/result/misc.ts +17 -9
  207. package/src/result/models.ts +2 -0
  208. package/src/result/work/flow.ts +86 -62
  209. package/src/result/work/pipe.ts +55 -33
  210. package/src/sized/map.ts +20 -17
  211. package/src/sized/set.ts +21 -17
  212. package/src/string/case.ts +8 -0
  213. package/src/string/fuzzy.ts +19 -5
  214. package/src/string/index.ts +18 -15
  215. package/src/string/match.ts +3 -0
  216. package/src/string/normalize.ts +6 -2
  217. package/src/string/template.ts +69 -18
  218. package/src/value/clone.ts +51 -26
  219. package/src/value/collection.ts +9 -6
  220. package/src/value/diff.ts +3 -1
  221. package/src/value/freeze.ts +239 -25
  222. package/src/value/index.ts +0 -1
  223. package/src/value/merge.ts +11 -5
  224. package/src/value/omit.ts +1 -0
  225. package/src/value/pick.ts +1 -0
  226. package/src/value/shake.ts +1 -0
  227. package/src/value/smush.ts +1 -0
  228. package/src/value/transform.ts +7 -3
  229. package/src/value/unsmush.ts +1 -0
@@ -31,9 +31,12 @@ function hslToHex(hsl, alpha) {
31
31
  return convertRgbToHex(convertHslToRgba(hsl), alpha ?? false);
32
32
  }
33
33
  /**
34
- * Convert an HSL(A) color to an RGB color
34
+ * Convert an _HSL(A)_ color to an _RGB_ color
35
+ *
36
+ * _If the value is unable to be converted, a black RGB color will be returned_
37
+ *
38
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
35
39
  *
36
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
37
40
  * @param hsl HSL(A) color
38
41
  * @returns RGB color
39
42
  */
@@ -46,9 +49,12 @@ function hslToRgb(hsl) {
46
49
  };
47
50
  }
48
51
  /**
49
- * Convert an HSL(A) color to an RGBA color
52
+ * Convert an _HSL(A)_ color to an _RGBA_ color
53
+ *
54
+ * _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
55
+ *
56
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
50
57
  *
51
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
52
58
  * @param hsl HSL(A) color
53
59
  * @returns RGBA color
54
60
  */
@@ -5,26 +5,35 @@ declare function convertRgbToHex(rgb: RGBAColor | RGBColor, alpha: boolean): str
5
5
  declare function convertRgbToHsla(value: unknown): HSLAColor;
6
6
  declare function getRgbValue(value: Record<keyof RGBColor, unknown>): RGBColor;
7
7
  /**
8
- * Convert an RGB(A) color to a hex color _(with optional alpha channel)_
9
- * @param rgb RGB(A) color
10
- * @param alpha Include alpha channel? _(defaults to `false`)_
11
- * @returns Hex color
8
+ * Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
9
+ *
10
+ * _If the value is unable to be converted, a black hex color will be returned_
11
+ *
12
+ * @param rgb _RGB(A)_ color
13
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
14
+ * @returns Hex color string
12
15
  */
13
16
  declare function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string;
14
17
  /**
15
- * Convert an RGB(A) color to an HSL color
18
+ * Convert an _RGB(A)_ color to an _HSL_ color
19
+ *
20
+ * _If the value is unable to be converted, a black HSL color will be returned_
16
21
  *
17
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26
18
- * @param rgb RGB(A) color
19
- * @returns HSL color
22
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
23
+ *
24
+ * @param rgb _RGB(A)_ color
25
+ * @returns _HSL_ color
20
26
  */
21
27
  declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor;
22
28
  /**
23
- * Convert an RGB(A) color to an HSLA color
29
+ * Convert an _RGB(A)_ color to an _HSLA_ color
30
+ *
31
+ * _If the value is unable to be converted, a black _HSLA_ color with an alpha channel (opacity) of `0` will be returned_
32
+ *
33
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
24
34
  *
25
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26
26
- * @param rgb RGB(A) color
27
- * @returns HSLA color
35
+ * @param rgb _RGB(A)_ color
36
+ * @returns _HSLA_ color
28
37
  */
29
38
  declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
30
39
  //#endregion
@@ -58,20 +58,26 @@ function getRgbValue(value) {
58
58
  };
59
59
  }
60
60
  /**
61
- * Convert an RGB(A) color to a hex color _(with optional alpha channel)_
62
- * @param rgb RGB(A) color
63
- * @param alpha Include alpha channel? _(defaults to `false`)_
64
- * @returns Hex color
61
+ * Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
62
+ *
63
+ * _If the value is unable to be converted, a black hex color will be returned_
64
+ *
65
+ * @param rgb _RGB(A)_ color
66
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
67
+ * @returns Hex color string
65
68
  */
66
69
  function rgbToHex(rgb, alpha) {
67
70
  return convertRgbToHex(isRgbLike(rgb) ? getRgbValue(rgb) : { ...DEFAULT_RGB }, alpha ?? false);
68
71
  }
69
72
  /**
70
- * Convert an RGB(A) color to an HSL color
73
+ * Convert an _RGB(A)_ color to an _HSL_ color
74
+ *
75
+ * _If the value is unable to be converted, a black HSL color will be returned_
71
76
  *
72
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26
73
- * @param rgb RGB(A) color
74
- * @returns HSL color
77
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
78
+ *
79
+ * @param rgb _RGB(A)_ color
80
+ * @returns _HSL_ color
75
81
  */
76
82
  function rgbToHsl(rgb) {
77
83
  const { hue, lightness, saturation } = convertRgbToHsla(rgb);
@@ -82,11 +88,14 @@ function rgbToHsl(rgb) {
82
88
  };
83
89
  }
84
90
  /**
85
- * Convert an RGB(A) color to an HSLA color
91
+ * Convert an _RGB(A)_ color to an _HSLA_ color
92
+ *
93
+ * _If the value is unable to be converted, a black _HSLA_ color with an alpha channel (opacity) of `0` will be returned_
94
+ *
95
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
86
96
  *
87
- * Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26
88
- * @param rgb RGB(A) color
89
- * @returns HSLA color
97
+ * @param rgb _RGB(A)_ color
98
+ * @returns _HSLA_ color
90
99
  */
91
100
  function rgbToHsla(rgb) {
92
101
  return convertRgbToHsla(rgb);
@@ -2,7 +2,7 @@ import { Constructor, NestedKeys, NestedValue, PlainObject } from "../models.mjs
2
2
 
3
3
  //#region src/function/assert.d.ts
4
4
  /**
5
- * Asserter for a nested property of a value
5
+ * Asserter for a property of a value
6
6
  */
7
7
  type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted extends NestedPick<Value, Path> = NestedPick<Value, Path>> = Asserter<Asserted>;
8
8
  /**
@@ -12,6 +12,7 @@ type Asserter<Value> = (value: unknown) => asserts value is Value;
12
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;
13
13
  /**
14
14
  * Asserts that a condition is true, throwing an error if it is not
15
+ *
15
16
  * @param condition Condition to assert
16
17
  * @param message Error message
17
18
  * @param error Error constructor _(defaults to `Error`)_
@@ -25,53 +26,58 @@ declare namespace assert {
25
26
  var property: typeof assertProperty;
26
27
  }
27
28
  /**
28
- * Creates an asserter that asserts a condition is true, throwing an error if it is not
29
+ * Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not
30
+ *
31
+ * _Available as `assertCondition` and `assert.condition`_
29
32
  *
30
- * Available as `assertCondition` and `assert.condition`
31
33
  * @param condition Condition to assert
32
34
  * @param message Error message
33
35
  * @param error Error constructor _(defaults to `Error`)_
34
- * @returns Asserter
36
+ * @returns _Asserter_
35
37
  */
36
38
  declare function assertCondition<Value>(condition: (value: unknown) => boolean, message: string, error?: ErrorConstructor): Asserter<Value>;
37
39
  /**
38
40
  * Asserts that a value is defined, throwing an error if it is not
39
41
  *
40
- * Available as `assertDefined` and `assert.defined`
42
+ * _Available as `assertDefined` and `assert.defined`_
43
+ *
41
44
  * @param value Value to assert
42
45
  * @param message Error message
43
46
  * @param error Error constructor _(defaults to `Error`)_
44
47
  */
45
48
  declare function assertDefined<Value>(value: unknown, message?: string, error?: ErrorConstructor): asserts value is Exclude<Value, null | undefined>;
46
49
  /**
47
- * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
50
+ * Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
51
+ *
52
+ * _Available as `assertInstanceOf` and `assert.instanceOf`_
48
53
  *
49
- * Available as `assertInstanceOf` and `assert.instanceOf`
50
54
  * @param constructor Constructor to check against
51
55
  * @param message Error message
52
56
  * @param error Error constructor _(defaults to `Error`)_
53
- * @returns Asserter
57
+ * @returns _Asserter_
54
58
  */
55
59
  declare function assertInstanceOf<Value>(constructor: Constructor<Value>, message: string, error?: ErrorConstructor): Asserter<Value>;
56
60
  /**
57
- * Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
61
+ * Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not
62
+ *
63
+ * _Available as `assertIs` and `assert.is`_
58
64
  *
59
- * Available as `assertIs` and `assert.is`
60
65
  * @param condition Type guard function to check the value
61
66
  * @param message Error message
62
67
  * @param error Error constructor _(defaults to `Error`)_
63
- * @returns Asserter
68
+ * @returns _Asserter_
64
69
  */
65
70
  declare function assertIs<Value>(condition: (value: unknown) => value is Value, message: string, error?: ErrorConstructor): Asserter<Value>;
66
71
  /**
67
- * Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
72
+ * Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
73
+ *
74
+ * _Available as `assertProperty` and `assert.property`_
68
75
  *
69
- * Available as `assertProperty` and `assert.property`
70
76
  * @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
71
77
  * @param condition Condition to assert for the property
72
78
  * @param message Error message
73
79
  * @param error Error constructor _(defaults to `Error`)_
74
- * @returns Asserter
80
+ * @returns _Asserter_
75
81
  */
76
82
  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>;
77
83
  //#endregion
@@ -2,6 +2,7 @@ import { hasValueResult } from "../internal/value/has.mjs";
2
2
  //#region src/function/assert.ts
3
3
  /**
4
4
  * Asserts that a condition is true, throwing an error if it is not
5
+ *
5
6
  * @param condition Condition to assert
6
7
  * @param message Error message
7
8
  * @param error Error constructor _(defaults to `Error`)_
@@ -15,13 +16,14 @@ assert.instanceOf = assertInstanceOf;
15
16
  assert.is = assertIs;
16
17
  assert.property = assertProperty;
17
18
  /**
18
- * Creates an asserter that asserts a condition is true, throwing an error if it is not
19
+ * Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not
20
+ *
21
+ * _Available as `assertCondition` and `assert.condition`_
19
22
  *
20
- * Available as `assertCondition` and `assert.condition`
21
23
  * @param condition Condition to assert
22
24
  * @param message Error message
23
25
  * @param error Error constructor _(defaults to `Error`)_
24
- * @returns Asserter
26
+ * @returns _Asserter_
25
27
  */
26
28
  function assertCondition(condition, message, error) {
27
29
  return (value) => {
@@ -31,7 +33,8 @@ function assertCondition(condition, message, error) {
31
33
  /**
32
34
  * Asserts that a value is defined, throwing an error if it is not
33
35
  *
34
- * Available as `assertDefined` and `assert.defined`
36
+ * _Available as `assertDefined` and `assert.defined`_
37
+ *
35
38
  * @param value Value to assert
36
39
  * @param message Error message
37
40
  * @param error Error constructor _(defaults to `Error`)_
@@ -40,13 +43,14 @@ function assertDefined(value, message, error) {
40
43
  assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED, error);
41
44
  }
42
45
  /**
43
- * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
46
+ * Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
47
+ *
48
+ * _Available as `assertInstanceOf` and `assert.instanceOf`_
44
49
  *
45
- * Available as `assertInstanceOf` and `assert.instanceOf`
46
50
  * @param constructor Constructor to check against
47
51
  * @param message Error message
48
52
  * @param error Error constructor _(defaults to `Error`)_
49
- * @returns Asserter
53
+ * @returns _Asserter_
50
54
  */
51
55
  function assertInstanceOf(constructor, message, error) {
52
56
  return (value) => {
@@ -54,13 +58,14 @@ function assertInstanceOf(constructor, message, error) {
54
58
  };
55
59
  }
56
60
  /**
57
- * Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
61
+ * Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not
62
+ *
63
+ * _Available as `assertIs` and `assert.is`_
58
64
  *
59
- * Available as `assertIs` and `assert.is`
60
65
  * @param condition Type guard function to check the value
61
66
  * @param message Error message
62
67
  * @param error Error constructor _(defaults to `Error`)_
63
- * @returns Asserter
68
+ * @returns _Asserter_
64
69
  */
65
70
  function assertIs(condition, message, error) {
66
71
  return (value) => {
@@ -68,14 +73,15 @@ function assertIs(condition, message, error) {
68
73
  };
69
74
  }
70
75
  /**
71
- * Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
76
+ * Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
77
+ *
78
+ * _Available as `assertProperty` and `assert.property`_
72
79
  *
73
- * Available as `assertProperty` and `assert.property`
74
80
  * @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
75
81
  * @param condition Condition to assert for the property
76
82
  * @param message Error message
77
83
  * @param error Error constructor _(defaults to `Error`)_
78
- * @returns Asserter
84
+ * @returns _Asserter_
79
85
  */
80
86
  function assertProperty(path, condition, message, error) {
81
87
  return (value) => {
@@ -4,11 +4,11 @@ import { AsyncCancelableCallback, CancelableCallback, GenericAsyncCallback, Gene
4
4
  /**
5
5
  * Debounce a function, ensuring it is only called after `time` milliseconds have passed
6
6
  *
7
- * When called, successful _(finished)_ results will resolve and errors will reject.
7
+ * - When called, successful _(finished)_ results will resolve and errors will reject
8
+ * - On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
8
9
  *
9
- * On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
10
+ * _Available as `asyncDebounce` and `debounce.async`_
10
11
  *
11
- * Available as `asyncDebounce` and `debounce.async`
12
12
  * @param callback Callback to debounce
13
13
  * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
14
14
  * @returns Debounced callback handler with a `cancel` method
@@ -17,11 +17,11 @@ declare function asyncDebounce<Callback extends GenericAsyncCallback | GenericCa
17
17
  /**
18
18
  * Throttle a function, ensuring it is only called once every `time` milliseconds
19
19
  *
20
- * When called, successful _(finished)_ results will resolve and errors will reject.
20
+ * - When called, successful _(finished)_ results will resolve and errors will reject
21
+ * - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
21
22
  *
22
- * On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
23
+ * _Available as `asyncThrottle` and `throttle.async`_
23
24
  *
24
- * Available as `asyncThrottle` and `throttle.async`
25
25
  * @param callback Callback to throttle
26
26
  * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
27
27
  * @returns Throttled callback handler with a `cancel` method
@@ -31,6 +31,7 @@ declare function asyncThrottle<Callback extends GenericAsyncCallback | GenericCa
31
31
  * Debounce a function, ensuring it is only called after `time` milliseconds have passed
32
32
  *
33
33
  * On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
34
+ *
34
35
  * @param callback Callback to debounce
35
36
  * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
36
37
  * @returns Debounced callback handler with a `cancel` method
@@ -41,6 +42,7 @@ declare namespace debounce {
41
42
  }
42
43
  /**
43
44
  * Throttle a function, ensuring it is only called once every `time` milliseconds
45
+ *
44
46
  * @param callback Callback to throttle
45
47
  * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
46
48
  * @returns Throttled callback handler with a `cancel` method
@@ -3,11 +3,11 @@ import { TIMER_DEBOUNCE, TIMER_THROTTLE, getAsyncTimer, getTimer } from "../inte
3
3
  /**
4
4
  * Debounce a function, ensuring it is only called after `time` milliseconds have passed
5
5
  *
6
- * When called, successful _(finished)_ results will resolve and errors will reject.
6
+ * - When called, successful _(finished)_ results will resolve and errors will reject
7
+ * - On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
7
8
  *
8
- * On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
9
+ * _Available as `asyncDebounce` and `debounce.async`_
9
10
  *
10
- * Available as `asyncDebounce` and `debounce.async`
11
11
  * @param callback Callback to debounce
12
12
  * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
13
13
  * @returns Debounced callback handler with a `cancel` method
@@ -18,11 +18,11 @@ function asyncDebounce(callback, time) {
18
18
  /**
19
19
  * Throttle a function, ensuring it is only called once every `time` milliseconds
20
20
  *
21
- * When called, successful _(finished)_ results will resolve and errors will reject.
21
+ * - When called, successful _(finished)_ results will resolve and errors will reject
22
+ * - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
22
23
  *
23
- * On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
24
+ * _Available as `asyncThrottle` and `throttle.async`_
24
25
  *
25
- * Available as `asyncThrottle` and `throttle.async`
26
26
  * @param callback Callback to throttle
27
27
  * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
28
28
  * @returns Throttled callback handler with a `cancel` method
@@ -34,6 +34,7 @@ function asyncThrottle(callback, time) {
34
34
  * Debounce a function, ensuring it is only called after `time` milliseconds have passed
35
35
  *
36
36
  * On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
37
+ *
37
38
  * @param callback Callback to debounce
38
39
  * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
39
40
  * @returns Debounced callback handler with a `cancel` method
@@ -44,6 +45,7 @@ function debounce(callback, time) {
44
45
  debounce.async = asyncDebounce;
45
46
  /**
46
47
  * Throttle a function, ensuring it is only called once every `time` milliseconds
48
+ *
47
49
  * @param callback Callback to throttle
48
50
  * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
49
51
  * @returns Throttled callback handler with a `cancel` method
@@ -2,16 +2,20 @@ import { GenericCallback } from "../models.mjs";
2
2
 
3
3
  //#region src/function/memoize.d.ts
4
4
  /**
5
- * A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
5
+ * A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
6
6
  */
7
7
  declare class Memoized<Callback extends GenericCallback> {
8
8
  #private;
9
9
  /**
10
10
  * Maximum cache size
11
+ *
12
+ * @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
11
13
  */
12
14
  get maximum(): number;
13
15
  /**
14
16
  * Current cache size
17
+ *
18
+ * @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
15
19
  */
16
20
  get size(): number;
17
21
  constructor(callback: Callback, options: Options);
@@ -21,35 +25,41 @@ declare class Memoized<Callback extends GenericCallback> {
21
25
  clear(): void;
22
26
  /**
23
27
  * Delete a result from the cache
28
+ *
24
29
  * @param key Key to delete
25
30
  * @returns `true` if the key existed and was removed, otherwise `false`
26
31
  */
27
32
  delete(key: unknown): boolean;
28
33
  /**
29
- * Destroy the instance _(clearing its cache and removing its callback)_
34
+ * Destroy the instance
35
+ *
36
+ * _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
30
37
  */
31
38
  destroy(): void;
32
39
  /**
33
40
  * Get a result from the cache
41
+ *
34
42
  * @param key Key to get
35
43
  * @returns Cached result or `undefined` if it does not exist
36
44
  */
37
45
  get(key: unknown): ReturnType<Callback> | undefined;
38
46
  /**
39
47
  * Does the result exist?
48
+ *
40
49
  * @param key Key to check
41
50
  * @returns `true` if the result exists, otherwise `false`
42
51
  */
43
52
  has(key: unknown): boolean;
44
53
  /**
45
54
  * Run the callback with the provided parameters
55
+ *
46
56
  * @param parameters Parameters to pass to the callback
47
57
  * @returns Cached or computed _(then cached)_ result
48
58
  */
49
59
  run(...parameters: Parameters<Callback>): ReturnType<Callback>;
50
60
  }
51
61
  /**
52
- * Options for memoized functions
62
+ * Options for a _Memoized_ function
53
63
  */
54
64
  type MemoizedOptions<Callback extends GenericCallback> = {
55
65
  /**
@@ -67,9 +77,10 @@ type Options = {
67
77
  };
68
78
  /**
69
79
  * Memoize a function, caching and retrieving results based on the first parameter
80
+ *
70
81
  * @param callback Callback to memoize
71
82
  * @param options Memoization options
72
- * @returns Memoized instance
83
+ * @returns _Memoized_ instance
73
84
  */
74
85
  declare function memoize<Callback extends GenericCallback>(callback: Callback, options?: MemoizedOptions<Callback>): Memoized<Callback>;
75
86
  //#endregion
@@ -3,18 +3,22 @@ import { getString, join } from "../internal/string.mjs";
3
3
  import { SizedMap } from "../sized/map.mjs";
4
4
  //#region src/function/memoize.ts
5
5
  /**
6
- * A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
6
+ * A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
7
7
  */
8
8
  var Memoized = class {
9
9
  #state;
10
10
  /**
11
11
  * Maximum cache size
12
+ *
13
+ * @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
12
14
  */
13
15
  get maximum() {
14
16
  return this.#state.cache?.maximum ?? NaN;
15
17
  }
16
18
  /**
17
19
  * Current cache size
20
+ *
21
+ * @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
18
22
  */
19
23
  get size() {
20
24
  return this.#state.cache?.size ?? NaN;
@@ -41,6 +45,7 @@ var Memoized = class {
41
45
  }
42
46
  /**
43
47
  * Delete a result from the cache
48
+ *
44
49
  * @param key Key to delete
45
50
  * @returns `true` if the key existed and was removed, otherwise `false`
46
51
  */
@@ -48,7 +53,9 @@ var Memoized = class {
48
53
  return this.#state.cache?.delete(key) ?? false;
49
54
  }
50
55
  /**
51
- * Destroy the instance _(clearing its cache and removing its callback)_
56
+ * Destroy the instance
57
+ *
58
+ * _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
52
59
  */
53
60
  destroy() {
54
61
  this.#state.cache?.clear();
@@ -57,6 +64,7 @@ var Memoized = class {
57
64
  }
58
65
  /**
59
66
  * Get a result from the cache
67
+ *
60
68
  * @param key Key to get
61
69
  * @returns Cached result or `undefined` if it does not exist
62
70
  */
@@ -65,6 +73,7 @@ var Memoized = class {
65
73
  }
66
74
  /**
67
75
  * Does the result exist?
76
+ *
68
77
  * @param key Key to check
69
78
  * @returns `true` if the result exists, otherwise `false`
70
79
  */
@@ -73,11 +82,12 @@ var Memoized = class {
73
82
  }
74
83
  /**
75
84
  * Run the callback with the provided parameters
85
+ *
76
86
  * @param parameters Parameters to pass to the callback
77
87
  * @returns Cached or computed _(then cached)_ result
78
88
  */
79
89
  run(...parameters) {
80
- if (this.#state.cache == null || this.#state.getter == null) throw new Error("The Memoized instance has been destroyed");
90
+ if (this.#state.cache == null || this.#state.getter == null) throw new Error(MEMOIZED_ERROR_DESTROYED);
81
91
  return this.#state.getter(...parameters);
82
92
  }
83
93
  };
@@ -90,14 +100,18 @@ function getMemoizationOptions(input) {
90
100
  }
91
101
  /**
92
102
  * Memoize a function, caching and retrieving results based on the first parameter
103
+ *
93
104
  * @param callback Callback to memoize
94
105
  * @param options Memoization options
95
- * @returns Memoized instance
106
+ * @returns _Memoized_ instance
96
107
  */
97
108
  function memoize(callback, options) {
109
+ if (typeof callback !== "function") throw new TypeError(MEMOIZED_ERROR_CALLBACK);
98
110
  return new Memoized(callback, getMemoizationOptions(options));
99
111
  }
100
112
  const DEFAULT_CACHE_SIZE = 1024;
113
+ const MEMOIZED_ERROR_CALLBACK = "Memoized requires a callback function";
114
+ const MEMOIZED_ERROR_DESTROYED = "The Memoized instance has been destroyed";
101
115
  const SEPARATOR = "_";
102
116
  //#endregion
103
117
  export { memoize };
@@ -4,15 +4,17 @@ import { GenericAsyncCallback, GenericCallback, OnceAsyncCallback, OnceCallback
4
4
  /**
5
5
  * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
6
6
  *
7
- * Available as `asyncOnce` and `once.async`
7
+ * _Available as `asyncOnce` and `once.async`_
8
+ *
8
9
  * @param callback Callback to use once
9
- * @returns Once callback
10
+ * @returns _Once_ callback
10
11
  */
11
12
  declare function asyncOnce<Callback extends GenericAsyncCallback>(callback: Callback): OnceAsyncCallback<Callback>;
12
13
  /**
13
14
  * Create a function that can only be called once, returning the same value on subsequent calls
15
+ *
14
16
  * @param callback Callback to use once
15
- * @returns Once callback
17
+ * @returns _Once_ callback
16
18
  */
17
19
  declare function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback>;
18
20
  declare namespace once {
@@ -3,9 +3,10 @@ import { assert } from "./assert.mjs";
3
3
  /**
4
4
  * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
5
5
  *
6
- * Available as `asyncOnce` and `once.async`
6
+ * _Available as `asyncOnce` and `once.async`_
7
+ *
7
8
  * @param callback Callback to use once
8
- * @returns Once callback
9
+ * @returns _Once_ callback
9
10
  */
10
11
  function asyncOnce(callback) {
11
12
  assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
@@ -66,8 +67,9 @@ function handleOnceResult(state, value, error) {
66
67
  }
67
68
  /**
68
69
  * Create a function that can only be called once, returning the same value on subsequent calls
70
+ *
69
71
  * @param callback Callback to use once
70
- * @returns Once callback
72
+ * @returns _Once_ callback
71
73
  */
72
74
  function once(callback) {
73
75
  assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
@@ -16,7 +16,8 @@ type RetryOptions = {
16
16
  /**
17
17
  * Retry a callback a specified number of times, with a delay between attempts
18
18
  *
19
- * Available as `asyncRetry` and `retry.async`
19
+ * _Available as `asyncRetry` and `retry.async`_
20
+ *
20
21
  * @param callback Callback to retry
21
22
  * @param options Retry options
22
23
  * @returns Callback result
@@ -25,7 +26,8 @@ declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Cal
25
26
  /**
26
27
  * Retry a callback a specified number of times, with a delay between attempts
27
28
  *
28
- * Available as `asyncRetry` and `retry.async`
29
+ * _Available as `asyncRetry` and `retry.async`_
30
+ *
29
31
  * @param callback Callback to retry
30
32
  * @param options Retry options
31
33
  * @returns Callback result
@@ -33,6 +35,7 @@ declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Cal
33
35
  declare function asyncRetry<Callback extends GenericCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
34
36
  /**
35
37
  * Retry a callback a specified number of times
38
+ *
36
39
  * @param callback Callback to retry
37
40
  * @param options Retry options
38
41
  * @returns Callback result
@@ -14,7 +14,8 @@ var RetryError = class extends Error {
14
14
  /**
15
15
  * Retry a callback a specified number of times, with a delay between attempts
16
16
  *
17
- * Available as `asyncRetry` and `retry.async`
17
+ * _Available as `asyncRetry` and `retry.async`_
18
+ *
18
19
  * @param callback Callback to retry
19
20
  * @param options Retry options
20
21
  * @returns Callback result
@@ -57,6 +58,7 @@ function getRetryOptions(input) {
57
58
  }
58
59
  /**
59
60
  * Retry a callback a specified number of times
61
+ *
60
62
  * @param callback Callback to retry
61
63
  * @param options Retry options
62
64
  * @returns Callback result