@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
@@ -4,40 +4,45 @@ import type {GenericCallback} from './models';
4
4
  // #region Types
5
5
 
6
6
  class Events<Map extends Record<string, GenericCallback>> {
7
- readonly #kalas: Kalas<Map>;
7
+ readonly #herald: Herald<Map>;
8
8
 
9
- constructor(kalas: Kalas<Map>) {
10
- this.#kalas = kalas;
9
+ constructor(herald: Herald<Map>) {
10
+ this.#herald = herald;
11
11
  }
12
12
 
13
13
  /**
14
14
  * Subscribe to an event with a callback
15
+ *
15
16
  * @param event Event name
16
17
  * @param callback Callback function
17
18
  * @returns Unsubscriber function
18
19
  */
19
20
  subscribe<Event extends keyof Map>(event: Event, callback: Map[Event]): Unsubscriber {
20
- return this.#kalas.subscribe(event, callback);
21
+ return this.#herald.subscribe(event, callback);
21
22
  }
22
23
 
23
24
  /**
24
25
  * Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
26
+ *
25
27
  * @param event Event name
26
28
  * @param callback Callback function
27
29
  * @returns Unsubscriber function
28
30
  */
29
31
  unsubscribe<Event extends keyof Map>(event: Event, callback?: Map[Event]): void {
30
- return this.#kalas.unsubscribe(event, callback);
32
+ return this.#herald.unsubscribe(event, callback);
31
33
  }
32
34
  }
33
35
 
34
- class Kalas<Map extends Record<string, GenericCallback>> {
36
+ /**
37
+ * A _Herald_ is an announcer for named events, allowing emission, subscription, and unsubscription of events
38
+ */
39
+ class Herald<Map extends Record<string, GenericCallback>> {
35
40
  readonly #names: Set<keyof Map>;
36
41
 
37
42
  readonly #subscribers = new Map<keyof Map, Set<Map[keyof Map]>>();
38
43
 
39
44
  /**
40
- * Events interface for subscribing and unsubscribing to events
45
+ * Events interface for subscribing to and unsubscribing from events
41
46
  */
42
47
  declare readonly events: Events<Map>;
43
48
 
@@ -58,6 +63,7 @@ class Kalas<Map extends Record<string, GenericCallback>> {
58
63
 
59
64
  /**
60
65
  * Emit an event with parameters
66
+ *
61
67
  * @param event Event name
62
68
  * @param parameters Event parameters
63
69
  */
@@ -75,6 +81,7 @@ class Kalas<Map extends Record<string, GenericCallback>> {
75
81
 
76
82
  /**
77
83
  * Subscribe to an event with a callback
84
+ *
78
85
  * @param event Event name
79
86
  * @param callback Callback function
80
87
  * @returns Unsubscriber function
@@ -101,6 +108,7 @@ class Kalas<Map extends Record<string, GenericCallback>> {
101
108
 
102
109
  /**
103
110
  * Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
111
+ *
104
112
  * @param event Event name
105
113
  * @param callback Callback function
106
114
  */
@@ -134,13 +142,14 @@ export type Unsubscriber = () => void;
134
142
  // #region Functions
135
143
 
136
144
  /**
137
- * Create a Kalas _(party)_ for named events
145
+ * Create a _Herald_ for announcing named events
146
+ *
138
147
  * @param names Event names
139
- * @returns Kalas instance
148
+ * @returns _Herald_ instance
140
149
  */
141
- export function kalas<Events extends Record<string, GenericCallback>>(
150
+ export function herald<Events extends Record<string, GenericCallback>>(
142
151
  names: (keyof Events)[],
143
- ): Kalas<Events> {
152
+ ): Herald<Events> {
144
153
  if (
145
154
  !Array.isArray(names) ||
146
155
  names.length === 0 ||
@@ -149,19 +158,19 @@ export function kalas<Events extends Record<string, GenericCallback>>(
149
158
  throw new Error(MESSAGE);
150
159
  }
151
160
 
152
- return new Kalas<Events>(names);
161
+ return new Herald<Events>(names);
153
162
  }
154
163
 
155
164
  // #endregion
156
165
 
157
166
  // #region Variables
158
167
 
159
- const MESSAGE = 'Kalas requires an array of event names.';
168
+ const MESSAGE = 'Herald requires an array of event names.';
160
169
 
161
170
  // #endregion
162
171
 
163
172
  // #region Exports
164
173
 
165
- export {type Events, type Kalas};
174
+ export {type Events, type Herald};
166
175
 
167
176
  // #endregion
package/src/index.ts CHANGED
@@ -17,6 +17,8 @@ export * from './function/once';
17
17
  export * from './function/retry';
18
18
  export * from './function/work';
19
19
 
20
+ export * from './herald';
21
+
20
22
  export * from './internal/function/misc';
21
23
  export * from './internal/string';
22
24
  export * from './internal/value/compare';
@@ -25,8 +27,6 @@ export * from './internal/value/get';
25
27
  export * from './internal/value/has';
26
28
  export * from './internal/value/set';
27
29
 
28
- export * from './kalas';
29
-
30
30
  export * from './string/case';
31
31
  export * from './string/fuzzy';
32
32
  export * from './string/index';
@@ -37,6 +37,7 @@ export * from './string/template';
37
37
  export * from './value/clone';
38
38
  export * from './value/collection';
39
39
  export * from './value/diff';
40
+ export * from './value/freeze';
40
41
  export * from './value/index';
41
42
  export * from './value/merge';
42
43
  export * from './value/transform';
@@ -91,7 +91,7 @@ indexOf.last = lastIndexOf;
91
91
  /**
92
92
  * Get the index of the last matching item by callback
93
93
  *
94
- * Available as `lastIndexOf` and `indexOf.last`
94
+ * _Available as `lastIndexOf` and `indexOf.last`_
95
95
  *
96
96
  * @param array Array to search in
97
97
  * @param callback Callback to get an item's value
@@ -115,7 +115,7 @@ export function lastIndexOf<
115
115
  /**
116
116
  * Get the index of the last matching item by key
117
117
  *
118
- * Available as `lastIndexOf` and `indexOf.last`
118
+ * _Available as `lastIndexOf` and `indexOf.last`_
119
119
  *
120
120
  * @param array Array to search in
121
121
  * @param key Key to match items by
@@ -140,7 +140,7 @@ export function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Item
140
140
  /**
141
141
  * Get the index of the last item matching the filter
142
142
  *
143
- * Available as `lastIndexOf` and `indexOf.last`
143
+ * _Available as `lastIndexOf` and `indexOf.last`_
144
144
  *
145
145
  * @param array Array to search in
146
146
  * @param filter Filter callback to match items
@@ -162,7 +162,7 @@ export function lastIndexOf<Item>(
162
162
  /**
163
163
  * Get the index of the last item matching the given item
164
164
  *
165
- * Available as `lastIndexOf` and `indexOf.last`
165
+ * _Available as `lastIndexOf` and `indexOf.last`_
166
166
  *
167
167
  * @param array Array to search in
168
168
  * @param item Item to match against
@@ -20,7 +20,7 @@ function insertChunkedValues(
20
20
  const chunked = chunk(items);
21
21
  const lastIndex = chunked.length - 1;
22
22
 
23
- let index = Number(chunked.length);
23
+ let index = chunked.length;
24
24
  let returned: unknown[] | undefined;
25
25
 
26
26
  while (index > 0) {
@@ -4,6 +4,7 @@ import {getRandomInteger} from '../random';
4
4
 
5
5
  /**
6
6
  * Shuffle items in array
7
+ *
7
8
  * @param array Original array
8
9
  * @returns Shuffled array
9
10
  */
@@ -18,7 +19,7 @@ export function shuffle<Item>(array: Item[]): Item[] {
18
19
  return shuffled;
19
20
  }
20
21
 
21
- let index = Number(shuffled.length);
22
+ let index = shuffled.length;
22
23
 
23
24
  while (--index >= 0) {
24
25
  const random = getRandomInteger(0, index);
@@ -10,9 +10,10 @@ import type {
10
10
  // #region Functions
11
11
 
12
12
  /**
13
- * Is the value an array or a record?
13
+ * Is the value an array or a plain object?
14
+ *
14
15
  * @param value Value to check
15
- * @returns `true` if the value is an array or a record, otherwise `false`
16
+ * @returns `true` if the value is an array or a plain object, otherwise `false`
16
17
  */
17
18
  export function isArrayOrPlainObject(value: unknown): value is ArrayOrPlainObject {
18
19
  return Array.isArray(value) || isPlainObject(value);
@@ -20,6 +21,7 @@ export function isArrayOrPlainObject(value: unknown): value is ArrayOrPlainObjec
20
21
 
21
22
  /**
22
23
  * Is the value a constructor function?
24
+ *
23
25
  * @param value Value to check
24
26
  * @returns `true` if the value is a constructor function, otherwise `false`
25
27
  */
@@ -29,6 +31,7 @@ export function isConstructor(value: unknown): value is Constructor {
29
31
 
30
32
  /**
31
33
  * Is the value an instance of the constructor?
34
+ *
32
35
  * @param constructor Class constructor
33
36
  * @param value Value to check
34
37
  * @returns `true` if the value is an instance of the constructor, otherwise `false`
@@ -41,9 +44,10 @@ export function isInstanceOf<Instance>(
41
44
  }
42
45
 
43
46
  /**
44
- * Is the value a key?
47
+ * Is the value a _Key_?
48
+ *
45
49
  * @param value Value to check
46
- * @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
50
+ * @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false`
47
51
  */
48
52
  export function isKey(value: unknown): value is Key {
49
53
  return typeof value === 'number' || typeof value === 'string';
@@ -51,6 +55,7 @@ export function isKey(value: unknown): value is Key {
51
55
 
52
56
  /**
53
57
  * Is the value not an array or a plain object?
58
+ *
54
59
  * @param value Value to check
55
60
  * @returns `true` if the value is not an array or a plain object, otherwise `false`
56
61
  */
@@ -62,6 +67,7 @@ export function isNonArrayOrPlainObject<Value>(
62
67
 
63
68
  /**
64
69
  * Is the value not a constructor function?
70
+ *
65
71
  * @param value Value to check
66
72
  * @returns `true` if the value is not a constructor function, otherwise `false`
67
73
  */
@@ -71,6 +77,7 @@ export function isNonConstructor<Value>(value: Value): value is Exclude<Value, C
71
77
 
72
78
  /**
73
79
  * Is the value not an instance of the constructor?
80
+ *
74
81
  * @param constructor Class constructor
75
82
  * @param value Value to check
76
83
  * @returns `true` if the value is not an instance of the constructor, otherwise `false`
@@ -83,9 +90,10 @@ export function isNonInstanceOf<Instance, Value>(
83
90
  }
84
91
 
85
92
  /**
86
- * Is the value not a key?
93
+ * Is the value not a _Key_?
94
+ *
87
95
  * @param value Value to check
88
- * @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
96
+ * @returns `true` if the value is not a _Key_ _(`number` or `string`)_, otherwise `false`
89
97
  */
90
98
  export function isNonKey<Value>(value: Value): value is Exclude<Value, Key> {
91
99
  return !isKey(value);
@@ -93,6 +101,7 @@ export function isNonKey<Value>(value: Value): value is Exclude<Value, Key> {
93
101
 
94
102
  /**
95
103
  * Is the value not a number?
104
+ *
96
105
  * @param value Value to check
97
106
  * @returns `true` if the value is not a `number`, otherwise `false`
98
107
  */
@@ -102,6 +111,7 @@ export function isNonNumber<Value>(value: Value): value is Exclude<Value, number
102
111
 
103
112
  /**
104
113
  * Is the value not a plain object?
114
+ *
105
115
  * @param value Value to check
106
116
  * @returns `true` if the value is not a plain object, otherwise `false`
107
117
  */
@@ -111,6 +121,7 @@ export function isNonPlainObject<Value>(value: Value): value is Exclude<Value, P
111
121
 
112
122
  /**
113
123
  * Is the value not a primitive value?
124
+ *
114
125
  * @param value Value to check
115
126
  * @returns `true` if the value is not a primitive value, otherwise `false`
116
127
  */
@@ -120,6 +131,7 @@ export function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Pri
120
131
 
121
132
  /**
122
133
  * Is the value not a template strings array?
134
+ *
123
135
  * @param value Value to check
124
136
  * @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
125
137
  */
@@ -131,6 +143,7 @@ export function isNonTemplateStringsArray<Value>(
131
143
 
132
144
  /**
133
145
  * Is the value not a typed array?
146
+ *
134
147
  * @param value Value to check
135
148
  * @returns `true` if the value is not a typed array, otherwise `false`
136
149
  */
@@ -140,6 +153,7 @@ export function isNonTypedArray<Value>(value: Value): value is Exclude<Value, Ty
140
153
 
141
154
  /**
142
155
  * Is the value a number?
156
+ *
143
157
  * @param value Value to check
144
158
  * @returns `true` if the value is a `number`, otherwise `false`
145
159
  */
@@ -149,6 +163,7 @@ export function isNumber(value: unknown): value is number {
149
163
 
150
164
  /**
151
165
  * Is the value a plain object?
166
+ *
152
167
  * @param value Value to check
153
168
  * @returns `true` if the value is a plain object, otherwise `false`
154
169
  */
@@ -171,9 +186,10 @@ export function isPlainObject(value: unknown): value is PlainObject {
171
186
  }
172
187
 
173
188
  /**
174
- * - Is the value a primitive value?
189
+ * Is the value a primitive value?
190
+ *
175
191
  * @param value Value to check
176
- * @returns `true` if the value matches, otherwise `false`
192
+ * @returns `true` if the value is a primitive value, otherwise `false`
177
193
  */
178
194
  export function isPrimitive(value: unknown): value is Primitive {
179
195
  if (value == null) {
@@ -193,6 +209,7 @@ export function isPrimitive(value: unknown): value is Primitive {
193
209
 
194
210
  /**
195
211
  * Is the value a template strings array?
212
+ *
196
213
  * @param value Value to check
197
214
  * @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
198
215
  */
@@ -202,6 +219,7 @@ export function isTemplateStringsArray(value: unknown): value is TemplateStrings
202
219
 
203
220
  /**
204
221
  * Is the value a typed array?
222
+ *
205
223
  * @param value Value to check
206
224
  * @returns `true` if the value is a typed array, otherwise `false`
207
225
  */
@@ -72,14 +72,14 @@ export function getAggregateCallback(key: unknown): Function | undefined {
72
72
  * max(
73
73
  * [{id: 1, value: 10}, {id: 2, value: 20}],
74
74
  * item => item.value,
75
- * ); // 20
75
+ * ); // => 20
76
76
  *
77
- * max([], item => item.value); // Number.NaN
77
+ * max([], item => item.value); // => Number.NaN
78
78
  * ```
79
79
  *
80
80
  * @param items List of items
81
81
  * @param callback Callback to get an item's value
82
- * @returns Maximum value, or `NaN` if no maximum can be found
82
+ * @returns Maximum value, or `Number.NaN` if no maximum can be found
83
83
  */
84
84
  export function max<Item>(
85
85
  items: Item[],
@@ -94,14 +94,14 @@ export function max<Item>(
94
94
  * max(
95
95
  * [{id: 1, value: 10}, {id: 2, value: 20}],
96
96
  * 'value',
97
- * ); // 20
97
+ * ); // => 20
98
98
  *
99
- * max([], 'value'); // Number.NaN
99
+ * max([], 'value'); // => Number.NaN
100
100
  * ```
101
101
  *
102
102
  * @param items List of items
103
103
  * @param key Key to use for value
104
- * @returns Maximum value, or `NaN` if no maximum can be found
104
+ * @returns Maximum value, or `Number.NaN` if no maximum can be found
105
105
  */
106
106
  export function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(
107
107
  items: Item[],
@@ -113,12 +113,12 @@ export function max<Item extends PlainObject, ItemKey extends keyof NumericalVal
113
113
  *
114
114
  * @example
115
115
  * ```typescript
116
- * max([10, 20]); // 20
117
- * max([]); // Number.NaN
116
+ * max([10, 20]); // => 20
117
+ * max([]); // => Number.NaN
118
118
  * ```
119
119
  *
120
120
  * @param values List of numbers
121
- * @returns Maximum value, or `NaN` if no maximum can be found
121
+ * @returns Maximum value, or `Number.NaN` if no maximum can be found
122
122
  */
123
123
  export function max(values: number[]): number;
124
124
 
@@ -4,6 +4,7 @@ import {isNumber} from './is';
4
4
 
5
5
  /**
6
6
  * Is the number between a minimum and maximum value?
7
+ *
7
8
  * @param value Value to check
8
9
  * @param minimum Minimum value
9
10
  * @param maximum Maximum value
@@ -26,11 +27,18 @@ export function between(value: number, minimum: number, maximum: number): boolea
26
27
 
27
28
  /**
28
29
  * Clamp a number between a minimum and maximum value
30
+ *
29
31
  * @param value Value to clamp
30
32
  * @param minimum Minimum value
31
33
  * @param maximum Maximum value
32
34
  * @param loop If `true`, the value will loop around when smaller than the minimum or larger than the maximum _(defaults to `false`)_
33
35
  * @returns Clamped value
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * clamp(10, 0, 5); // => 5
40
+ * clamp(10, 0, 5, true); // => 0
41
+ * ```
34
42
  */
35
43
  export function clamp(value: number, minimum: number, maximum: number, loop?: boolean): number {
36
44
  if (![value, minimum, maximum].every(isNumber)) {
@@ -47,9 +55,12 @@ export function clamp(value: number, minimum: number, maximum: number, loop?: bo
47
55
  }
48
56
 
49
57
  /**
50
- * Get the number value from an unknown value _(based on Lodash)_
58
+ * Get the number value from an unknown value
59
+ *
60
+ * _(Based on Lodash)_
61
+ *
51
62
  * @param value Original value
52
- * @returns Original value as a number, or `NaN` if the value is unable to be parsed
63
+ * @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
53
64
  */
54
65
  export function getNumber(value: unknown): number {
55
66
  if (typeof value === 'number') {
@@ -2,7 +2,11 @@ import {isNumber} from './is';
2
2
 
3
3
  // #region Functions
4
4
 
5
- function _getRandomFloat(inclusive: boolean, minimum?: number, maximum?: number): number {
5
+ function getRandomFloatingNumberValue(
6
+ inclusive: boolean,
7
+ minimum?: number,
8
+ maximum?: number,
9
+ ): number {
6
10
  let maxFloat =
7
11
  isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
8
12
 
@@ -22,22 +26,24 @@ function _getRandomFloat(inclusive: boolean, minimum?: number, maximum?: number)
22
26
 
23
27
  /**
24
28
  * Get a random floating-point number
29
+ *
25
30
  * @param minimum Minimum value
26
31
  * @param maximum Maximum value
27
32
  * @returns Random floating-point number
28
33
  */
29
- export function getRandomFloat(minimum?: number, maximum?: number): number {
30
- return _getRandomFloat(false, minimum, maximum);
34
+ export function getRandomFloatingNumber(minimum?: number, maximum?: number): number {
35
+ return getRandomFloatingNumberValue(false, minimum, maximum);
31
36
  }
32
37
 
33
38
  /**
34
39
  * Get a random integer
40
+ *
35
41
  * @param minimum Minimum value
36
42
  * @param maximum Maximum value
37
43
  * @returns Random integer
38
44
  */
39
45
  export function getRandomInteger(minimum?: number, maximum?: number): number {
40
- return Math.floor(_getRandomFloat(true, minimum, maximum));
46
+ return Math.floor(getRandomFloatingNumberValue(true, minimum, maximum));
41
47
  }
42
48
 
43
49
  // #endregion
@@ -4,20 +4,11 @@ import {isNonPlainObject} from './is';
4
4
 
5
5
  // #region Functions
6
6
 
7
- function _isResult(value: unknown, okValue: boolean): value is Result<unknown, unknown> {
8
- if (isNonPlainObject(value)) {
9
- return false;
10
- }
11
-
12
- return (
13
- (value as PlainObject).ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value
14
- );
15
- }
16
-
17
7
  /**
18
- * Is the result an extended error?
19
- * @param result Result to check
20
- * @returns `true` if the result is an extended error, `false` otherwise
8
+ * Is the _Result_ an extended error?
9
+ *
10
+ * @param result _Result_ to check
11
+ * @returns `true` if the _Result_ is an extended error, `false` otherwise
21
12
  */
22
13
  export function isError<Value, E = Error>(
23
14
  result: ExtendedErr<E> | Result<Value, E>,
@@ -25,14 +16,16 @@ export function isError<Value, E = Error>(
25
16
  ): result is ExtendedErr<E>;
26
17
 
27
18
  /**
28
- * Is the result an error?
29
- * @param result Result to check
30
- * @returns `true` if the result is an error, `false` otherwise
19
+ * Is the _Result_ an error?
20
+ *
21
+ * @param result _Result_ to check
22
+ * @returns `true` if the _Result_ is an error, `false` otherwise
31
23
  */
32
24
  export function isError<Value, E = Error>(result: Result<Value, E>): result is Err<E>;
33
25
 
34
26
  /**
35
27
  * Is the value an error?
28
+ *
36
29
  * @param value Value to check
37
30
  * @returns `true` if the value is an error, `false` otherwise
38
31
  */
@@ -43,41 +36,49 @@ export function isError(
43
36
  extended?: boolean,
44
37
  ): value is Err<unknown> | ExtendedErr<unknown> {
45
38
  return (
46
- _isResult(value, false) &&
39
+ isResultValue(value, false) &&
47
40
  (extended === true ? (value as ExtendedErr<unknown>).original instanceof Error : true)
48
41
  );
49
42
  }
50
43
 
51
44
  /**
52
- * Is the result ok?
53
- * @param value Result to check
54
- * @returns `true` if the result is ok, `false` otherwise
45
+ * Is the _Result_ ok?
46
+ *
47
+ * @param value _Result_ to check
48
+ * @returns `true` if the _Result_ is ok, `false` otherwise
55
49
  */
56
50
  export function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
57
51
 
58
52
  /**
59
53
  * Is the value ok?
54
+ *
60
55
  * @param value Value to check
61
56
  * @returns `true` if the value is ok, `false` otherwise
62
57
  */
63
58
  export function isOk(value: unknown): value is Ok<unknown>;
64
59
 
65
- /**
66
- * Is the result ok?
67
- * @param result Result to check
68
- * @returns `true` if the result is ok, `false` otherwise
69
- */
70
60
  export function isOk(value: unknown): value is Ok<unknown> {
71
- return _isResult(value, true);
61
+ return isResultValue(value, true);
72
62
  }
73
63
 
74
64
  /**
75
- * Is the value a result?
65
+ * Is the value a _Result_?
66
+ *
76
67
  * @param value Value to check
77
- * @returns `true` if the value is a result, `false` otherwise
68
+ * @returns `true` if the value is a _Result_, `false` otherwise
78
69
  */
79
70
  export function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown> {
80
- return _isResult(value, true) || _isResult(value, false);
71
+ return isResultValue(value, true) || isResultValue(value, false);
72
+ }
73
+
74
+ function isResultValue(value: unknown, okValue: boolean): value is Result<unknown, unknown> {
75
+ if (isNonPlainObject(value)) {
76
+ return false;
77
+ }
78
+
79
+ return (
80
+ (value as PlainObject).ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value
81
+ );
81
82
  }
82
83
 
83
84
  // #endregion
@@ -2,8 +2,20 @@
2
2
 
3
3
  /**
4
4
  * Get the string value from any value
5
+ *
5
6
  * @param value Original value
6
7
  * @returns String representation of the value
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * getString(null) // => ''
12
+ * getString('foo') // => 'foo'
13
+ * getString(123) // => '123'
14
+ * getString(true) // => 'true'
15
+ * getString([1, 2, 3]) // => '1,2,3'
16
+ * getString({a: 1}) // => '{"a":1}'
17
+ * getString(() => 123) // => '123'
18
+ * ```
7
19
  */
8
20
  export function getString(value: unknown): string {
9
21
  if (typeof value === 'string') {
@@ -31,10 +43,25 @@ export function ignoreKey(key: string): boolean {
31
43
  return EXPRESSION_IGNORED.test(key);
32
44
  }
33
45
 
46
+ export function interpolate(strings: TemplateStringsArray, values: unknown[]): string {
47
+ const {length} = strings;
48
+
49
+ let interpolated = '';
50
+
51
+ for (let index = 0; index < length; index += 1) {
52
+ const value = values[index];
53
+
54
+ interpolated += `${strings[index]}${Array.isArray(value) ? join(value.map(getString)) : getString(value)}`;
55
+ }
56
+
57
+ return interpolated;
58
+ }
59
+
34
60
  /**
35
61
  * Join an array of values into a string _(while ignoring empty values)_
36
62
  *
37
63
  * _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_
64
+ *
38
65
  * @param array Array of values
39
66
  * @param delimiter Delimiter to use between values
40
67
  * @returns Joined string
@@ -81,6 +108,7 @@ export function tryEncode(value: boolean | number | string): unknown {
81
108
 
82
109
  /**
83
110
  * Split a string into words _(and other readable parts)_
111
+ *
84
112
  * @param value Original string
85
113
  * @returns Array of words found in the string
86
114
  */
@@ -19,6 +19,7 @@ const COMPARE_NAME: string = 'compare';
19
19
 
20
20
  /**
21
21
  * Compare two values _(for sorting purposes)_
22
+ *
22
23
  * @param first First value
23
24
  * @param second Second value
24
25
  * @returns `0` if equal; `-1` first comes before second; `1` first comes after second
@@ -124,7 +125,8 @@ function compareValue(
124
125
  /**
125
126
  * Deregister a custom comparison handler for a class
126
127
  *
127
- * Available as `deregisterComparator` and `compare.deregister`
128
+ * _Available as `deregisterComparator` and `compare.deregister`_
129
+ *
128
130
  * @param constructor Class constructor
129
131
  */
130
132
  export function deregisterComparator<Instance>(constructor: Constructor<Instance>): void {
@@ -142,7 +144,8 @@ function getComparisonParts(value: unknown): unknown[] {
142
144
  /**
143
145
  * Register a custom comparison handler for a class
144
146
  *
145
- * Available as `registerComparator` and `compare.register`
147
+ * _Available as `registerComparator` and `compare.register`_
148
+ *
146
149
  * @param constructor Class constructor
147
150
  * @param handler Method name or comparison function _(defaults to `compare`)_
148
151
  */