@oscarpalmer/atoms 0.75.0 → 0.76.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 (215) hide show
  1. package/dist/js/array/chunk.cjs +2 -1
  2. package/dist/js/array/chunk.js +2 -1
  3. package/dist/js/array/count.cjs +10 -3
  4. package/dist/js/array/count.js +10 -3
  5. package/dist/js/array/exists.cjs +10 -3
  6. package/dist/js/array/exists.js +10 -3
  7. package/dist/js/array/filter.cjs +10 -3
  8. package/dist/js/array/filter.js +10 -3
  9. package/dist/js/array/find.cjs +10 -3
  10. package/dist/js/array/find.js +10 -3
  11. package/dist/js/array/group-by.cjs +18 -16
  12. package/dist/js/array/group-by.js +18 -16
  13. package/dist/js/array/index-of.cjs +10 -3
  14. package/dist/js/array/index-of.js +10 -3
  15. package/dist/js/array/index.cjs +2 -2
  16. package/dist/js/array/index.js +2 -2
  17. package/dist/js/array/insert.cjs +10 -4
  18. package/dist/js/array/insert.js +10 -4
  19. package/dist/js/array/splice.cjs +4 -4
  20. package/dist/js/array/splice.js +4 -4
  21. package/dist/js/array/to-map.cjs +11 -11
  22. package/dist/js/array/to-map.js +11 -11
  23. package/dist/js/array/to-record.cjs +3 -3
  24. package/dist/js/array/to-record.js +3 -3
  25. package/dist/js/array/unique.cjs +2 -2
  26. package/dist/js/array/unique.js +2 -2
  27. package/dist/js/colour/base.cjs +1 -1
  28. package/dist/js/colour/base.js +1 -1
  29. package/dist/js/colour/hex.cjs +2 -2
  30. package/dist/js/colour/hex.js +2 -2
  31. package/dist/js/colour/hsl.cjs +13 -7
  32. package/dist/js/colour/hsl.js +13 -7
  33. package/dist/js/colour/rgb.cjs +12 -6
  34. package/dist/js/colour/rgb.js +12 -6
  35. package/dist/js/emitter.cjs +8 -5
  36. package/dist/js/emitter.js +8 -5
  37. package/dist/js/function.cjs +6 -6
  38. package/dist/js/function.js +6 -6
  39. package/dist/js/index.cjs +0 -1
  40. package/dist/js/index.js +1 -2
  41. package/dist/js/internal/array/callbacks.cjs +23 -0
  42. package/dist/js/internal/array/callbacks.js +23 -0
  43. package/dist/js/internal/{array-find.cjs → array/find.cjs} +11 -12
  44. package/dist/js/internal/{array-find.js → array/find.js} +11 -12
  45. package/dist/js/logger.cjs +13 -13
  46. package/dist/js/logger.js +13 -13
  47. package/dist/js/query.cjs +0 -3
  48. package/dist/js/query.js +1 -4
  49. package/dist/js/random.cjs +0 -6
  50. package/dist/js/random.js +0 -6
  51. package/dist/js/sized.cjs +1 -1
  52. package/dist/js/sized.js +1 -1
  53. package/dist/js/string/index.cjs +7 -1
  54. package/dist/js/string/index.js +7 -1
  55. package/dist/js/value/compare.cjs +0 -1
  56. package/dist/js/value/compare.js +0 -1
  57. package/dist/js/value/get.cjs +3 -3
  58. package/dist/js/value/get.js +2 -2
  59. package/dist/js/value/set.cjs +4 -4
  60. package/dist/js/value/set.js +2 -2
  61. package/package.json +3 -2
  62. package/src/js/array/chunk.ts +6 -5
  63. package/src/js/array/compact.ts +8 -10
  64. package/src/js/array/count.ts +39 -19
  65. package/src/js/array/exists.ts +40 -16
  66. package/src/js/array/filter.ts +42 -20
  67. package/src/js/array/find.ts +45 -20
  68. package/src/js/array/group-by.ts +158 -27
  69. package/src/js/array/index-of.ts +40 -18
  70. package/src/js/array/index.ts +10 -9
  71. package/src/js/array/insert.ts +28 -14
  72. package/src/js/array/models.ts +18 -15
  73. package/src/js/array/shuffle.ts +3 -3
  74. package/src/js/array/sort.ts +28 -34
  75. package/src/js/array/splice.ts +22 -26
  76. package/src/js/array/to-map.ts +133 -45
  77. package/src/js/array/to-record.ts +137 -39
  78. package/src/js/array/unique.ts +20 -15
  79. package/src/js/colour/base.ts +3 -3
  80. package/src/js/colour/functions.ts +4 -6
  81. package/src/js/colour/hex.ts +5 -5
  82. package/src/js/colour/hsl.ts +18 -12
  83. package/src/js/colour/index.ts +1 -1
  84. package/src/js/colour/is.ts +3 -3
  85. package/src/js/colour/rgb.ts +17 -11
  86. package/src/js/emitter.ts +12 -9
  87. package/src/js/function.ts +12 -12
  88. package/src/js/index.ts +16 -16
  89. package/src/js/internal/array/callbacks.ts +33 -0
  90. package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
  91. package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
  92. package/src/js/is.ts +2 -2
  93. package/src/js/logger.ts +14 -14
  94. package/src/js/math.ts +1 -1
  95. package/src/js/models.ts +5 -5
  96. package/src/js/number.ts +2 -2
  97. package/src/js/query.ts +6 -10
  98. package/src/js/queue.ts +1 -1
  99. package/src/js/random.ts +9 -19
  100. package/src/js/sized.ts +145 -145
  101. package/src/js/string/case.ts +1 -1
  102. package/src/js/string/index.ts +13 -7
  103. package/src/js/string/template.ts +6 -3
  104. package/src/js/value/clone.ts +3 -7
  105. package/src/js/value/compare.ts +3 -5
  106. package/src/js/value/diff.ts +4 -4
  107. package/src/js/value/equal.ts +2 -2
  108. package/src/js/value/get.ts +3 -3
  109. package/src/js/value/index.ts +2 -2
  110. package/src/js/value/merge.ts +3 -3
  111. package/src/js/value/set.ts +3 -4
  112. package/src/js/value/smush.ts +4 -4
  113. package/src/js/value/unsmush.ts +4 -4
  114. package/types/array/chunk.d.cts +2 -2
  115. package/types/array/chunk.d.ts +2 -2
  116. package/types/array/compact.d.cts +4 -4
  117. package/types/array/compact.d.ts +4 -4
  118. package/types/array/count.d.cts +15 -8
  119. package/types/array/count.d.ts +13 -7
  120. package/types/array/exists.d.cts +14 -5
  121. package/types/array/exists.d.ts +12 -4
  122. package/types/array/filter.d.cts +16 -7
  123. package/types/array/filter.d.ts +14 -6
  124. package/types/array/find.d.cts +16 -7
  125. package/types/array/find.d.ts +14 -6
  126. package/types/array/group-by.d.cts +51 -5
  127. package/types/array/group-by.d.ts +49 -5
  128. package/types/array/index-of.d.cts +16 -7
  129. package/types/array/index-of.d.ts +14 -6
  130. package/types/array/index.d.cts +239 -95
  131. package/types/array/index.d.ts +7 -6
  132. package/types/array/insert.d.cts +9 -4
  133. package/types/array/insert.d.ts +10 -5
  134. package/types/array/models.d.cts +14 -11
  135. package/types/array/models.d.ts +14 -12
  136. package/types/array/shuffle.d.cts +2 -2
  137. package/types/array/shuffle.d.ts +2 -2
  138. package/types/array/sort.d.cts +11 -11
  139. package/types/array/sort.d.ts +10 -10
  140. package/types/array/splice.d.cts +4 -4
  141. package/types/array/splice.d.ts +4 -4
  142. package/types/array/to-map.d.cts +44 -20
  143. package/types/array/to-map.d.ts +42 -20
  144. package/types/array/to-record.d.cts +44 -20
  145. package/types/array/to-record.d.ts +42 -20
  146. package/types/array/unique.d.cts +11 -6
  147. package/types/array/unique.d.ts +10 -6
  148. package/types/colour/base.d.cts +28 -16
  149. package/types/colour/base.d.ts +2 -2
  150. package/types/colour/functions.d.cts +28 -16
  151. package/types/colour/functions.d.ts +3 -3
  152. package/types/colour/hex.d.cts +28 -16
  153. package/types/colour/hex.d.ts +4 -4
  154. package/types/colour/hsl.d.cts +28 -16
  155. package/types/colour/hsl.d.ts +16 -10
  156. package/types/colour/index.d.cts +28 -16
  157. package/types/colour/index.d.ts +1 -1
  158. package/types/colour/is.d.cts +28 -16
  159. package/types/colour/is.d.ts +3 -3
  160. package/types/colour/rgb.d.cts +28 -16
  161. package/types/colour/rgb.d.ts +15 -9
  162. package/types/emitter.d.cts +11 -8
  163. package/types/emitter.d.ts +11 -8
  164. package/types/function.d.cts +10 -10
  165. package/types/function.d.ts +11 -11
  166. package/types/index.d.cts +1061 -669
  167. package/types/index.d.ts +16 -16
  168. package/types/internal/array/callbacks.d.cts +11 -0
  169. package/types/internal/array/callbacks.d.ts +2 -0
  170. package/types/internal/array/find.d.cts +7 -0
  171. package/types/internal/array/find.d.ts +3 -0
  172. package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
  173. package/types/is.d.ts +1 -1
  174. package/types/logger.d.cts +13 -13
  175. package/types/logger.d.ts +13 -13
  176. package/types/math.d.cts +1 -1
  177. package/types/math.d.ts +1 -1
  178. package/types/models.d.cts +4 -4
  179. package/types/models.d.ts +1 -4
  180. package/types/number.d.cts +2 -2
  181. package/types/number.d.ts +2 -2
  182. package/types/query.d.cts +2 -2
  183. package/types/query.d.ts +3 -3
  184. package/types/queue.d.cts +1 -1
  185. package/types/queue.d.ts +1 -1
  186. package/types/random.d.cts +8 -12
  187. package/types/random.d.ts +8 -12
  188. package/types/sized.d.cts +6 -6
  189. package/types/sized.d.ts +6 -6
  190. package/types/string/index.d.cts +6 -3
  191. package/types/string/index.d.ts +3 -3
  192. package/types/string/template.d.cts +3 -0
  193. package/types/string/template.d.ts +4 -1
  194. package/types/value/clone.d.cts +4 -2
  195. package/types/value/clone.d.ts +4 -2
  196. package/types/value/get.d.ts +1 -1
  197. package/types/value/index.d.cts +8 -6
  198. package/types/value/index.d.ts +2 -2
  199. package/types/value/merge.d.cts +1 -1
  200. package/types/value/merge.d.ts +2 -2
  201. package/types/value/set.d.ts +1 -1
  202. package/types/value/smush.d.cts +1 -1
  203. package/types/value/smush.d.ts +2 -2
  204. package/types/value/unsmush.d.cts +1 -1
  205. package/types/value/unsmush.d.ts +2 -2
  206. package/dist/js/internal/array-callbacks.cjs +0 -18
  207. package/dist/js/internal/array-callbacks.js +0 -18
  208. package/src/js/internal/array-callbacks.ts +0 -28
  209. package/types/internal/array-callbacks.d.cts +0 -13
  210. package/types/internal/array-callbacks.d.ts +0 -2
  211. package/types/internal/array-find.d.cts +0 -11
  212. package/types/internal/array-find.d.ts +0 -4
  213. /package/dist/js/internal/{value-handle.cjs → value/handle.cjs} +0 -0
  214. /package/dist/js/internal/{value-handle.js → value/handle.js} +0 -0
  215. /package/types/internal/{value-handle.d.cts → value/handle.d.cts} +0 -0
package/types/index.d.cts CHANGED
@@ -1,91 +1,130 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- export declare class Emitter<Value> {
4
- private readonly state;
3
+ /**
4
+ * A Map with a maximum size
5
+ * - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
6
+ * - Behaviour is similar to a _LRU_-cache, where the least recently used entries are removed
7
+ */
8
+ export declare class SizedMap<Key = unknown, Value = unknown> extends Map<
9
+ Key,
10
+ Value
11
+ > {
12
+ private readonly maximumSize;
5
13
  /**
6
- * Is the emitter active?
14
+ * Is the Map full?
7
15
  */
8
- get active(): boolean;
16
+ get full(): boolean;
9
17
  /**
10
- * The observable that can be subscribed to
18
+ * The maximum size of the Map
11
19
  */
12
- get observable(): Observable<Value>;
20
+ get maximum(): number;
13
21
  /**
14
- * The current value
22
+ * Create a new Map with entries and a maximum size _(2^20)_
15
23
  */
16
- get value(): Value;
17
- constructor(value: Value);
24
+ constructor(entries: Array<[Key, Value]>);
18
25
  /**
19
- * Destroys the emitter
26
+ * Create a new Map with a maximum size _(but clamped at 2^24)_
20
27
  */
21
- destroy(): void;
28
+ constructor(maximum: number);
22
29
  /**
23
- * Emits a new value _(and optionally finishes the emitter)_
30
+ * Create a new Map with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
24
31
  */
25
- emit(value: Value, finish?: boolean): void;
32
+ constructor(entries?: Array<[Key, Value]>, maximum?: number);
26
33
  /**
27
- * Emits an error _(and optionally finishes the emitter)_
34
+ * @inheritdoc
28
35
  */
29
- error(error: Error, finish?: boolean): void;
36
+ get(key: Key): Value | undefined;
30
37
  /**
31
- * Finishes the emitter
38
+ * @inheritdoc
32
39
  */
33
- finish(): void;
40
+ set(key: Key, value: Value): this;
34
41
  }
35
- export declare class Observable<Value> {
36
- private readonly state;
37
- constructor(
38
- emitter: Emitter<Value>,
39
- observers: Map<Subscription<Value>, Observer<Value>>,
40
- );
42
+ /**
43
+ * A Set with a maximum size
44
+ * - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
45
+ * - Behaviour is similar to a _LRU_-cache, where the oldest values are removed
46
+ */
47
+ export declare class SizedSet<Value = unknown> extends Set<Value> {
48
+ private readonly maximumSize;
41
49
  /**
42
- * Subscribes to value changes
50
+ * Is the Set full?
43
51
  */
44
- subscribe(observer: Observer<Value>): Subscription<Value>;
52
+ get full(): boolean;
45
53
  /**
46
- * Subscribes to value changes
54
+ * The maximum size of the Set
47
55
  */
48
- subscribe(
49
- onNext: (value: Value) => void,
50
- onError?: (error: Error) => void,
51
- onComplete?: () => void,
52
- ): Subscription<Value>;
53
- }
54
- export type ObservableState<Value> = {
55
- emitter: Emitter<Value>;
56
- observers: Map<Subscription<Value>, Observer<Value>>;
57
- };
58
- export type Observer<Value> = {
56
+ get maximum(): number;
59
57
  /**
60
- * Callback for when the observable is complete
58
+ * Create a new Set with values and a maximum size _(2^20)_
61
59
  */
62
- complete?: () => void;
60
+ constructor(values: Value[]);
63
61
  /**
64
- * Callback for when the observable has an error
62
+ * Create a new Set with a maximum size _(but clamped at 2^24)_
65
63
  */
66
- error?: (error: Error) => void;
64
+ constructor(maximum: number);
67
65
  /**
68
- * Callback for when the observable has a new value
66
+ * Create a new Set with _(optional)_ values and a maximum size _(defaults to 2^20; clamped at 2^24)_
69
67
  */
70
- next?: (value: Value) => void;
71
- };
72
- export declare class Subscription<Value> {
73
- private readonly state;
74
- constructor(state: ObservableState<Value>);
68
+ constructor(values?: Value[], maximum?: number);
75
69
  /**
76
- * Is the subscription closed?
70
+ * @inheritdoc
77
71
  */
78
- get closed(): boolean;
79
- destroy(): void;
72
+ add(value: Value): this;
80
73
  /**
81
- * Unsubscribes from the observable
74
+ * Get a value from an index in the Set, if it exists
75
+ * - Negative indices are counted from the end
76
+ * - Optionally move the value to the end with `update`
82
77
  */
83
- unsubscribe(): void;
78
+ at(index: number, update?: boolean): Value | undefined;
79
+ /**
80
+ * Get a value from the Set, if it exists _(and move it to the end)_
81
+ */
82
+ get(value: Value, update?: boolean): Value | undefined;
84
83
  }
85
84
  /**
86
- * Creates a new emitter
85
+ * Get a random boolean
87
86
  */
88
- export declare function emitter<Value>(value: Value): Emitter<Value>;
87
+ export declare function getRandomBoolean(): boolean;
88
+ /**
89
+ * Get a random string of characters with a specified length
90
+ * - `selection` defaults to all lowercase letters in the English alphabet
91
+ */
92
+ export declare function getRandomCharacters(
93
+ length: number,
94
+ selection?: string,
95
+ ): string;
96
+ /**
97
+ * Get a random hexadecimal colour
98
+ */
99
+ export declare function getRandomColour(): string;
100
+ /**
101
+ * Get a random floating-point number
102
+ */
103
+ export declare function getRandomFloat(min?: number, max?: number): number;
104
+ /**
105
+ * Get a random hexadecimal character
106
+ */
107
+ export declare function getRandomHex(): string;
108
+ /**
109
+ * Get a random integer
110
+ */
111
+ export declare function getRandomInteger(min?: number, max?: number): number;
112
+ /**
113
+ * Get a random item from an array
114
+ */
115
+ export declare function getRandomItem<Value>(array: Value[]): Value;
116
+ /**
117
+ * - Get an amount of random items from an array
118
+ * - If `amount` is not specified, a shuffled array will be returned instead
119
+ */
120
+ export declare function getRandomItems<Value>(
121
+ array: Value[],
122
+ amount?: number,
123
+ ): Value[];
124
+ /**
125
+ * Queue a callback to be executed at the next best time
126
+ */
127
+ export declare function queue(callback: () => void): void;
89
128
  /**
90
129
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
91
130
 
@@ -1485,382 +1524,882 @@ export type EventPosition = {
1485
1524
  x: number;
1486
1525
  y: number;
1487
1526
  };
1527
+ export type KeyedValue<
1528
+ Item,
1529
+ Key extends keyof Item,
1530
+ > = Item[Key] extends PropertyKey ? Item[Key] : never;
1488
1531
  export type NestedArrayType<Value> = Value extends Array<infer NestedValue>
1489
1532
  ? NestedArrayType<NestedValue>
1490
1533
  : Value;
1491
1534
  export type GenericCallback = (...args: any[]) => any;
1492
- export type GetterSetter<Value> = {
1493
- get(): Value;
1494
- set(value: Value): void;
1495
- };
1496
1535
  export type Key = number | string;
1497
1536
  export type PlainObject = UnknownRecord;
1498
1537
  export type UnknownArrayOrRecord = UnknownArray | UnknownRecord;
1499
- export type Debounced<Callback extends GenericCallback> = Callback & {
1500
- /**
1501
- * Cancels the debounce
1502
- */
1503
- cancel: () => void;
1504
- };
1505
- declare class Memoised<Callback extends GenericCallback> {
1506
- readonly state: MemoisedState<Callback>;
1507
- constructor(callback: Callback);
1508
- /**
1509
- * Clears the cache
1510
- */
1511
- clear(): void;
1512
- /**
1513
- * Deletes a result from the cache
1514
- */
1515
- delete(key: Parameters<Callback>[0]): boolean;
1516
- /**
1517
- * Destroys the instance, clearing its cache and removing its callback
1518
- */
1519
- destroy(): void;
1520
- /**
1521
- * Retrieves the result from the cache if it exists, or `undefined` otherwise
1522
- */
1523
- get(key: Parameters<Callback>[0]): ReturnType<Callback> | undefined;
1524
- /**
1525
- * Checks if the cache has a result for a given key
1526
- */
1527
- has(key: Parameters<Callback>[0]): boolean;
1528
- /**
1529
- * Retrieves the result from the cache if it exists, otherwise runs the callback, caches the result, and returns it
1530
- */
1531
- run(...parameters: Parameters<Callback>): ReturnType<Callback>;
1532
- }
1533
- export type MemoisedState<Callback extends GenericCallback> = {
1534
- cache: Map<Parameters<Callback>[0], ReturnType<Callback>>;
1535
- getter: (...parameters: Parameters<Callback>) => ReturnType<Callback>;
1536
- };
1537
- /**
1538
- * - Debounces a function, ensuring it is only called after `time` milliseconds have passed
1539
- * - On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
1540
- * - Time is clamped between _0_ and _1000_ milliseconds
1541
- * - Returns the callback with an added `cancel`-method for manually cancelling the debounce
1542
- */
1543
- export declare function debounce<Callback extends GenericCallback>(
1544
- callback: Callback,
1545
- time?: number,
1546
- ): Debounced<Callback>;
1547
- /**
1548
- * Memoises a function, caching and retrieving results based on the first parameter
1549
- */
1550
- export declare function memoise<Callback extends GenericCallback>(
1551
- callback: Callback,
1552
- ): Memoised<Callback>;
1553
- /**
1554
- * A function that does nothing, which can be useful, I guess…
1555
- */
1556
- export declare function noop(): void;
1557
- /**
1558
- * - Throttles a function, ensuring it is only called once every `time` milliseconds
1559
- * - Time is clamped between _0_ and _1000_ milliseconds
1560
- */
1561
- export declare function throttle<Callback extends GenericCallback>(
1562
- callback: Callback,
1563
- time?: number,
1564
- ): Callback;
1565
- /**
1566
- * Chunks an array into smaller arrays of a specified size
1567
- */
1568
- export declare function chunk<Value>(array: Value[], size?: number): Value[][];
1569
- /**
1570
- * Compacts and returns an array with all falsey values removed
1571
- */
1572
- export declare function compact<Value>(
1573
- array: Value[],
1574
- strict: true,
1575
- ): Exclude<Value, 0 | '' | false | null | undefined>[];
1576
- /**
1577
- * Compacts and returns an array with all `null` and `undefined` values removed
1578
- */
1579
- export declare function compact<Value>(
1580
- array: Value[],
1581
- ): Exclude<Value, null | undefined>[];
1582
- export type ArrayCallback<Value, Returned> = (
1583
- value: Value,
1584
- index: number,
1585
- array: Value[],
1586
- ) => Returned;
1587
- export type BooleanCallback<Value> = ArrayCallback<Value, boolean>;
1588
- export type KeyCallback<Value> = ArrayCallback<Value, Key>;
1589
- export type SortKey<Value> = {
1590
- direction: 'asc' | 'desc';
1591
- value: Key | SortKeyCallback<Value>;
1592
- };
1593
- export type SortKeyCallback<Value> = (value: Value) => Key;
1594
- /**
1595
- * Returns the number of items _(count)_ that match the given value
1596
- */
1597
- export declare function count<Model, Value>(
1598
- array: Model[],
1599
- value: Value | BooleanCallback<Model>,
1600
- ): number;
1601
1538
  /**
1602
- * - Returns the number of items _(count)_ that match the given value
1603
- * - Use `key` to find a comparison value to match with `value`
1539
+ * Convert a query string to a plain _(nested)_ object
1604
1540
  */
1605
- export declare function count<Model, Value = Model>(
1606
- array: Model[],
1607
- value: Value,
1608
- key: Key | KeyCallback<Model>,
1609
- ): number;
1541
+ export declare function fromQuery(query: string): PlainObject;
1610
1542
  /**
1611
- * Does the value exist in array?
1543
+ * Convert a plain _(nested)_ object to a query string
1612
1544
  */
1613
- export declare function exists<Model, Value>(
1614
- array: Model[],
1615
- value: Value | BooleanCallback<Model>,
1616
- ): boolean;
1545
+ export declare function toQuery(parameters: PlainObject): string;
1617
1546
  /**
1618
- * - Does the value exist in array?
1619
- * - Use `key` to find a comparison value to match with `value`
1547
+ * Is the number between a minimum and maximum value?
1620
1548
  */
1621
- export declare function exists<Model, Value = Model>(
1622
- array: Model[],
1623
- value: Value,
1624
- key: Key | KeyCallback<Model>,
1549
+ export declare function between(
1550
+ value: number,
1551
+ min: number,
1552
+ max: number,
1625
1553
  ): boolean;
1626
1554
  /**
1627
- * Returns a filtered array of items matching `value`
1628
- */
1629
- export declare function filter<Model, Value>(
1630
- array: Model[],
1631
- value: Value | BooleanCallback<Model>,
1632
- ): Model[];
1633
- /**
1634
- * - Returns a filtered array of items
1635
- * - Use `key` to find a comparison value to match with `value`
1636
- */
1637
- export declare function filter<Model, Value = Model>(
1638
- array: Model[],
1639
- value: Value,
1640
- key: Key | KeyCallback<Model>,
1641
- ): Model[];
1642
- /**
1643
- * Returns the first item matching `value`, or `undefined` if no match is found
1644
- */
1645
- export declare function find<Model, Value>(
1646
- array: Model[],
1647
- value: Value | BooleanCallback<Model>,
1648
- ): Model | undefined;
1649
- /**
1650
- * - Returns the first matching item, or `undefined` if no match is found
1651
- * - Use `key` to find a comparison value to match with `value`
1652
- */
1653
- export declare function find<Model, Value = Model>(
1654
- array: Model[],
1655
- value: Value,
1656
- key: Key | KeyCallback<Model>,
1657
- ): Model | undefined;
1658
- /**
1659
- * Groups an array of items using a key or callback
1555
+ * - Clamp a number between a minimum and maximum value
1556
+ * - If `loop` is `true`, when the value is less than the minimum, it will be clamped as the maximum, and vice versa
1660
1557
  */
1661
- export declare function groupBy<Value>(
1662
- array: Value[],
1663
- key: Key | KeyCallback<Value>,
1664
- ): Record<Key, Value[]>;
1558
+ export declare function clamp(
1559
+ value: number,
1560
+ min: number,
1561
+ max: number,
1562
+ loop?: boolean,
1563
+ ): number;
1665
1564
  /**
1666
- * Returns the index for the first item matching `value`, or `-1` if no match is found
1565
+ * - Get the number value from an unknown value
1566
+ * - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
1567
+ * - Based on Lodash :-)
1667
1568
  */
1668
- export declare function indexOf<Model, Value>(
1669
- array: Model[],
1670
- value: Value | BooleanCallback<Model>,
1671
- ): number;
1569
+ export declare function getNumber(value: unknown): number;
1672
1570
  /**
1673
- * - Returns the index for the first matching item, or `-1` if no match is found
1674
- * - Use `key` to find a comparison value to match with `value`
1571
+ * Get the average value from a list of numbers
1675
1572
  */
1676
- export declare function indexOf<Model, Value = Model>(
1677
- array: Model[],
1678
- value: Value,
1679
- key: Key | KeyCallback<Model>,
1680
- ): number;
1573
+ export declare function average(values: number[]): number;
1681
1574
  /**
1682
- * - Inserts values into an array at a specified index
1683
- * - Uses chunking to avoid stack overflow
1575
+ * Get the maximum value from a list of numbers
1684
1576
  */
1685
- export declare function insert<Value>(
1686
- array: Value[],
1687
- index: number,
1688
- values: Value[],
1689
- ): void;
1577
+ export declare function max(values: number[]): number;
1690
1578
  /**
1691
- * Shuffles an array
1579
+ * Get the minimum value from a list of numbers
1692
1580
  */
1693
- export declare function shuffle<Value>(array: Value[]): Value[];
1581
+ export declare function min(values: number[]): number;
1694
1582
  /**
1695
- * Sorts an array of items _(ascending by default)_
1583
+ * Round a number to a specific number of decimal places _(defaults to 0)_
1696
1584
  */
1697
- export declare function sort<Value>(
1698
- array: Value[],
1699
- descending?: boolean,
1700
- ): Value[];
1585
+ export declare function round(value: number, decimals?: number): number;
1701
1586
  /**
1702
- * - Sorts an array of items, using a `key` to sort by a specific value
1703
- * - Ascending by default, but can be changed by setting `descending` to `true`, or using a `SortKey`
1587
+ * Get the sum of a list of numbers
1704
1588
  */
1705
- export declare function sort<Value>(
1706
- array: Value[],
1707
- key: Key | SortKey<Value> | SortKeyCallback<Value>,
1589
+ export declare function sum(values: number[]): number;
1590
+ declare class Logger {
1591
+ /**
1592
+ * Log any number of values at the "debug" log level
1593
+ */
1594
+ get debug(): {
1595
+ (...data: any[]): void;
1596
+ (message?: any, ...optionalParams: any[]): void;
1597
+ };
1598
+ /**
1599
+ * Log the value and shows all its properties
1600
+ */
1601
+ get dir(): {
1602
+ (item?: any, options?: any): void;
1603
+ (obj: any, options?: import('util').InspectOptions): void;
1604
+ };
1605
+ /**
1606
+ * Is logging to the console enabled? _(defaults to `true`)_
1607
+ */
1608
+ get enabled(): boolean;
1609
+ /**
1610
+ * Enable or disable logging to the console
1611
+ */
1612
+ set enabled(value: boolean);
1613
+ /**
1614
+ * Log any number of values at the "error" log level
1615
+ */
1616
+ get error(): {
1617
+ (...data: any[]): void;
1618
+ (message?: any, ...optionalParams: any[]): void;
1619
+ };
1620
+ /**
1621
+ * Log any number of values at the "info" log level
1622
+ */
1623
+ get info(): {
1624
+ (...data: any[]): void;
1625
+ (message?: any, ...optionalParams: any[]): void;
1626
+ };
1627
+ /**
1628
+ * Log any number of values at the "log" log level
1629
+ */
1630
+ get log(): {
1631
+ (...data: any[]): void;
1632
+ (message?: any, ...optionalParams: any[]): void;
1633
+ };
1634
+ /**
1635
+ * Log data as a table, with optional properties to use as columns
1636
+ */
1637
+ get table(): {
1638
+ (tabularData?: any, properties?: string[]): void;
1639
+ (tabularData: any, properties?: readonly string[]): void;
1640
+ };
1641
+ /**
1642
+ * Log any number of values together with a trace from where it was called
1643
+ */
1644
+ get trace(): {
1645
+ (...data: any[]): void;
1646
+ (message?: any, ...optionalParams: any[]): void;
1647
+ };
1648
+ /**
1649
+ * Log any number of values at the "warn" log level
1650
+ */
1651
+ get warn(): {
1652
+ (...data: any[]): void;
1653
+ (message?: any, ...optionalParams: any[]): void;
1654
+ };
1655
+ /**
1656
+ * - Start a logged timer with a label
1657
+ * - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
1658
+ */
1659
+ time(label: string): Time;
1660
+ }
1661
+ declare class Time {
1662
+ private readonly state;
1663
+ constructor(label: string);
1664
+ /**
1665
+ * - Log the current duration of the timer
1666
+ * - _(Ignored if logging is disabled)_
1667
+ */
1668
+ log(): void;
1669
+ /**
1670
+ * - Stop the timer and logs the total duration
1671
+ * - _(Will always log the total duration, even if logging is disabled)_
1672
+ */
1673
+ stop(): void;
1674
+ }
1675
+ export declare const logger: Logger;
1676
+ /**
1677
+ * Is the value an array or a record?
1678
+ */
1679
+ export declare function isArrayOrPlainObject(
1680
+ value: unknown,
1681
+ ): value is ArrayOrPlainObject;
1682
+ /**
1683
+ * Is the array or object completely empty or only containing `null` or `undefined` values?
1684
+ */
1685
+ export declare function isEmpty(value: ArrayOrPlainObject): boolean;
1686
+ /**
1687
+ * Is the value a key?
1688
+ */
1689
+ export declare function isKey(value: unknown): value is Key;
1690
+ /**
1691
+ * Is the value undefined or null?
1692
+ */
1693
+ export declare function isNullable(value: unknown): value is undefined | null;
1694
+ /**
1695
+ * Is the value undefined, null, or an empty string?
1696
+ */
1697
+ export declare function isNullableOrEmpty(
1698
+ value: unknown,
1699
+ ): value is undefined | null | '';
1700
+ /**
1701
+ * Is the value undefined, null, or a whitespace-only string?
1702
+ */
1703
+ export declare function isNullableOrWhitespace(
1704
+ value: unknown,
1705
+ ): value is undefined | null | '';
1706
+ /**
1707
+ * Is the value a number?
1708
+ */
1709
+ export declare function isNumber(value: unknown): value is number;
1710
+ /**
1711
+ * Is the value a number, or a number-like string?
1712
+ */
1713
+ export declare function isNumerical(
1714
+ value: unknown,
1715
+ ): value is number | `${number}`;
1716
+ /**
1717
+ * Is the value an object?
1718
+ */
1719
+ export declare function isObject(value: unknown): value is object;
1720
+ /**
1721
+ * Is the value a plain object?
1722
+ */
1723
+ export declare function isPlainObject(value: unknown): value is PlainObject;
1724
+ /**
1725
+ * Is the value a primitive value?
1726
+ */
1727
+ export declare function isPrimitive(value: unknown): value is Primitive;
1728
+ /**
1729
+ * Chunk an array _(into smaller arrays of a specified size)_
1730
+ */
1731
+ export declare function chunk<Item>(array: Item[], size?: number): Item[][];
1732
+ /**
1733
+ * Compact an array _(removing all `null` and `undefined` values)_
1734
+ */
1735
+ export declare function compact<Item>(
1736
+ array: Item[],
1737
+ ): Exclude<Item, null | undefined>[];
1738
+ /**
1739
+ * Compact an array _(removing all falsey values)_
1740
+ */
1741
+ export declare function compact<Item>(
1742
+ array: Item[],
1743
+ strict: true,
1744
+ ): Exclude<Item, 0 | '' | false | null | undefined>[];
1745
+ export type ArrayCallback<Item, Value> = (
1746
+ item: Item,
1747
+ index: number,
1748
+ array: Item[],
1749
+ ) => Value;
1750
+ export type BooleanCallback<Item> = ArrayCallback<Item, boolean>;
1751
+ export type KeyCallback<Item> = ArrayCallback<Item, Key>;
1752
+ export type SortKey<Item> = {
1753
+ direction: 'asc' | 'desc';
1754
+ value: Key | SortKeyCallback<Item>;
1755
+ };
1756
+ export type SortKeyCallback<Item> = (item: Item) => unknown;
1757
+ export type ValueCallback<Item> = ArrayCallback<Item, unknown>;
1758
+ /**
1759
+ * Get the number of items _(count)_ that match the given value
1760
+ */
1761
+ export declare function count<Item>(array: Item[], value: Item): number;
1762
+ /**
1763
+ * Get the number of items _(count)_ that match the given value
1764
+ */
1765
+ export declare function count<Item>(
1766
+ array: Item[],
1767
+ matches: BooleanCallback<Item>,
1768
+ ): number;
1769
+ /**
1770
+ * Get the number of items _(count)_ that match the given value
1771
+ */
1772
+ export declare function count<Item, Key extends keyof Item>(
1773
+ array: Item[],
1774
+ key: Key,
1775
+ value: Item[Key],
1776
+ ): number;
1777
+ /**
1778
+ * Get the number of items _(count)_ that match the given value
1779
+ */
1780
+ export declare function count<Item, Key extends KeyCallback<Item>>(
1781
+ array: Item[],
1782
+ key: Key,
1783
+ value: ReturnType<Key>,
1784
+ ): number;
1785
+ /**
1786
+ * Does the value exist in array?
1787
+ */
1788
+ export declare function exists<Item>(array: Item[], value: Item): boolean;
1789
+ /**
1790
+ * Does the value exist in array?
1791
+ */
1792
+ export declare function exists<Item>(
1793
+ array: Item[],
1794
+ matches: BooleanCallback<Item>,
1795
+ ): boolean;
1796
+ /**
1797
+ * - Does the value exist in array?
1798
+ * - Use `key` to find a comparison value to match with `value`
1799
+ */
1800
+ export declare function exists<Item, Key extends keyof Item>(
1801
+ array: Item[],
1802
+ key: Key,
1803
+ value: Item[Key],
1804
+ ): boolean;
1805
+ /**
1806
+ * - Does the value exist in array?
1807
+ * - Use `key` to find a comparison value to match with `value`
1808
+ */
1809
+ export declare function exists<Item, Key extends KeyCallback<Item>>(
1810
+ array: Item[],
1811
+ key: Key,
1812
+ value: ReturnType<Key>,
1813
+ ): boolean;
1814
+ /**
1815
+ * Get a filtered array of items matching `value`
1816
+ */
1817
+ export declare function filter<Item>(array: Item[], value: Item): Item[];
1818
+ /**
1819
+ * Get a filtered array of items matching `value`
1820
+ */
1821
+ export declare function filter<Item>(
1822
+ array: Item[],
1823
+ matches: BooleanCallback<Item>,
1824
+ ): Item[];
1825
+ /**
1826
+ * - Get a filtered array of items
1827
+ * - Use `key` to find a comparison value to match with `value`
1828
+ */
1829
+ export declare function filter<Item, Key extends keyof Item>(
1830
+ array: Item[],
1831
+ key: Key,
1832
+ value: Item[Key],
1833
+ ): Item[];
1834
+ /**
1835
+ * - Get a filtered array of items
1836
+ * - Use `key` to find a comparison value to match with `value`
1837
+ */
1838
+ export declare function filter<Item, Key extends KeyCallback<Item>>(
1839
+ array: Item[],
1840
+ key: Key,
1841
+ value: ReturnType<Key>,
1842
+ ): Item[];
1843
+ /**
1844
+ * Get the first item matching `value` _(or `undefined` if no match is found)_
1845
+ */
1846
+ export declare function find<Item>(
1847
+ array: Item[],
1848
+ value: Item,
1849
+ ): Item | undefined;
1850
+ /**
1851
+ * Get the first item matching `value` _(or `undefined` if no match is found)_
1852
+ */
1853
+ export declare function find<Item>(
1854
+ array: Item[],
1855
+ matches: BooleanCallback<Item>,
1856
+ ): Item | undefined;
1857
+ /**
1858
+ * - Get the first matching item _(or `undefined` if no match is found)_
1859
+ * - Use `key` to find a comparison value to match with `value`
1860
+ */
1861
+ export declare function find<Item, Key extends keyof Item>(
1862
+ array: Item[],
1863
+ key: Key,
1864
+ value: Item[Key],
1865
+ ): Item | undefined;
1866
+ /**
1867
+ * - Get the first matching item _(or `undefined` if no match is found)_
1868
+ * - Use `key` to find a comparison value to match with `value`
1869
+ */
1870
+ export declare function find<Item, Key extends KeyCallback<Item>>(
1871
+ array: Item[],
1872
+ key: Key,
1873
+ value: ReturnType<Key>,
1874
+ ): Item | undefined;
1875
+ /**
1876
+ * Create a record from an array of items using a specific key
1877
+ */
1878
+ export declare function groupBy<Item, Key extends keyof Item>(
1879
+ array: Item[],
1880
+ key: Key,
1881
+ ): Record<KeyedValue<Item, Key>, Item>;
1882
+ /**
1883
+ * Create a record from an array of items using a specific key, and grouping them into arrays
1884
+ */
1885
+ export declare function groupBy<Item, Key extends keyof Item>(
1886
+ array: Item[],
1887
+ key: Key,
1888
+ arrays: true,
1889
+ ): Record<KeyedValue<Item, Key>, Item[]>;
1890
+ /**
1891
+ * Create a record from an array of items using a specific key
1892
+ */
1893
+ export declare function groupBy<Item, Key extends KeyCallback<Item>>(
1894
+ array: Item[],
1895
+ key: Key,
1896
+ ): Record<ReturnType<Key>, Item>;
1897
+ /**
1898
+ * Create a record from an array of items using a specific key, and grouping them into arrays
1899
+ */
1900
+ export declare function groupBy<Item, Key extends KeyCallback<Item>>(
1901
+ array: Item[],
1902
+ key: Key,
1903
+ arrays: true,
1904
+ ): Record<ReturnType<Key>, Item[]>;
1905
+ /**
1906
+ * Create a record from an array of items using a specific key and value
1907
+ */
1908
+ export declare function groupBy<
1909
+ Item,
1910
+ Key extends keyof Item,
1911
+ Value extends keyof Item,
1912
+ >(
1913
+ array: Item[],
1914
+ key: Key,
1915
+ value: Value,
1916
+ ): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
1917
+ /**
1918
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
1919
+ */
1920
+ export declare function groupBy<
1921
+ Item,
1922
+ Key extends keyof Item,
1923
+ Value extends keyof Item,
1924
+ >(
1925
+ array: Item[],
1926
+ key: Key,
1927
+ value: Value,
1928
+ arrays: true,
1929
+ ): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
1930
+ /**
1931
+ * Create a record from an array of items using a specific key and value
1932
+ */
1933
+ export declare function groupBy<
1934
+ Item,
1935
+ Key extends keyof Item,
1936
+ Value extends ValueCallback<Item>,
1937
+ >(
1938
+ array: Item[],
1939
+ key: Key,
1940
+ value: Value,
1941
+ ): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
1942
+ /**
1943
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
1944
+ */
1945
+ export declare function groupBy<
1946
+ Item,
1947
+ Key extends keyof Item,
1948
+ Value extends ValueCallback<Item>,
1949
+ >(
1950
+ array: Item[],
1951
+ key: Key,
1952
+ value: Value,
1953
+ arrays: true,
1954
+ ): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
1955
+ /**
1956
+ * Create a record from an array of items using a specific key and value
1957
+ */
1958
+ export declare function groupBy<
1959
+ Item,
1960
+ Key extends KeyCallback<Item>,
1961
+ Value extends keyof Item,
1962
+ >(
1963
+ array: Item[],
1964
+ key: Key,
1965
+ value: Value,
1966
+ ): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
1967
+ /**
1968
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
1969
+ */
1970
+ export declare function groupBy<
1971
+ Item,
1972
+ Key extends KeyCallback<Item>,
1973
+ Value extends keyof Item,
1974
+ >(
1975
+ array: Item[],
1976
+ key: Key,
1977
+ value: Value,
1978
+ arrays: true,
1979
+ ): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
1980
+ /**
1981
+ * Create a record from an array of items using a specific key and value
1982
+ */
1983
+ export declare function groupBy<
1984
+ Item,
1985
+ Key extends KeyCallback<Item>,
1986
+ Value extends ValueCallback<Item>,
1987
+ >(
1988
+ array: Item[],
1989
+ key: Key,
1990
+ value: Value,
1991
+ ): Record<ReturnType<Key>, ReturnType<Value>>;
1992
+ /**
1993
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
1994
+ */
1995
+ export declare function groupBy<
1996
+ Item,
1997
+ Key extends KeyCallback<Item>,
1998
+ Value extends ValueCallback<Item>,
1999
+ >(
2000
+ array: Item[],
2001
+ key: Key,
2002
+ value: Value,
2003
+ arrays: true,
2004
+ ): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
2005
+ /**
2006
+ * Get the index for the first item matching `value` _(or `-1` if no match is found)_
2007
+ */
2008
+ export declare function indexOf<Item>(array: Item[], value: Item): number;
2009
+ /**
2010
+ * Get the index for the first item matching `value` _(or `-1` if no match is found)_
2011
+ */
2012
+ export declare function indexOf<Item>(
2013
+ array: Item[],
2014
+ matches: BooleanCallback<Item>,
2015
+ ): number;
2016
+ /**
2017
+ * - Get the index for the first matching item _(or `-1` if no match is found)_
2018
+ * - Use `key` to find a comparison value to match with `value`
2019
+ */
2020
+ export declare function indexOf<Item, Key extends keyof Item>(
2021
+ array: Item[],
2022
+ key: Key,
2023
+ value: Item[Key],
2024
+ ): number;
2025
+ /**
2026
+ * - Get the index for the first matching item _(or `-1` if no match is found)_
2027
+ * - Use `key` to find a comparison value to match with `value`
2028
+ */
2029
+ export declare function indexOf<Item, Key extends KeyCallback<Item>>(
2030
+ array: Item[],
2031
+ key: Key,
2032
+ value: ReturnType<Key>,
2033
+ ): number;
2034
+ /**
2035
+ * - Insert values into an array _(at the end)_
2036
+ * - _(Uses chunking to avoid stack overflow_)
2037
+ */
2038
+ export declare function insert<Item>(array: Item[], items: Item[]): void;
2039
+ /**
2040
+ * - Insert values into an array at a specified index
2041
+ * - _(Uses chunking to avoid stack overflow_)
2042
+ */
2043
+ export declare function insert<Item>(
2044
+ array: Item[],
2045
+ index: number,
2046
+ items: Item[],
2047
+ ): void;
2048
+ /**
2049
+ * Shuffle an array
2050
+ */
2051
+ export declare function shuffle<Item>(array: Item[]): Item[];
2052
+ /**
2053
+ * Sort an array of items _(defaults to ascending)_
2054
+ */
2055
+ export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
2056
+ /**
2057
+ * - Sort an array of items, using a `key` to sort by a specific value
2058
+ * - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
2059
+ */
2060
+ export declare function sort<Item>(
2061
+ array: Item[],
2062
+ key: Key | SortKey<Item> | SortKeyCallback<Item>,
1708
2063
  descending?: boolean,
1709
- ): Value[];
2064
+ ): Item[];
1710
2065
  /**
1711
- * - Sorts an array of items, using multiple `keys` to sort by specific values
1712
- * - Ascending by default, but can be changed by setting `descending` to `true`, or using `SortKey`
2066
+ * - Sort an array of items, using multiple `keys` to sort by specific values
2067
+ * - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
1713
2068
  */
1714
- export declare function sort<Value>(
1715
- array: Value[],
1716
- keys: Array<Key | SortKey<Value> | SortKeyCallback<Value>>,
2069
+ export declare function sort<Item>(
2070
+ array: Item[],
2071
+ keys: Array<Key | SortKey<Item> | SortKeyCallback<Item>>,
1717
2072
  descending?: boolean,
1718
- ): Value[];
2073
+ ): Item[];
1719
2074
  /**
1720
2075
  * Removes and returns all items from an array starting from a specific index
1721
2076
  */
1722
- export declare function splice<Value>(array: Value[], start: number): Value[];
2077
+ export declare function splice<Item>(array: Item[], start: number): Item[];
1723
2078
  /**
1724
2079
  * Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
1725
2080
  */
1726
- export declare function splice<Value>(
1727
- array: Value[],
2081
+ export declare function splice<Item>(
2082
+ array: Item[],
1728
2083
  start: number,
1729
2084
  amount: number,
1730
- ): Value[];
2085
+ ): Item[];
1731
2086
  /**
1732
2087
  * - Splices values into an array and returns any removed values
1733
2088
  * - Uses chunking to avoid stack overflow
1734
2089
  */
1735
- export declare function splice<Value>(
1736
- array: Value[],
2090
+ export declare function splice<Item>(
2091
+ array: Item[],
1737
2092
  start: number,
1738
- values: Value[],
1739
- ): Value[];
2093
+ added: Item[],
2094
+ ): Item[];
1740
2095
  /**
1741
2096
  * - Splices values into an array and returns any removed values
1742
2097
  * - Uses chunking to avoid stack overflow
1743
2098
  */
1744
- export declare function splice<Value>(
1745
- array: Value[],
2099
+ export declare function splice<Item>(
2100
+ array: Item[],
1746
2101
  start: number,
1747
2102
  amount: number,
1748
- values: Value[],
1749
- ): Value[];
2103
+ added: Item[],
2104
+ ): Item[];
1750
2105
  /**
1751
- * Converts an array into a map, using indices as keys
2106
+ * Create a map from an array of items _(using their indices as keys)_
1752
2107
  */
1753
- export declare function toMap<Value>(array: Value[]): Map<number, Value>;
2108
+ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
1754
2109
  /**
1755
- * Converts an array into a map, using indices as keys and grouping values into arrays
2110
+ * Create a map from an array of items using a specific key
1756
2111
  */
1757
- export declare function toMap<Value>(
1758
- array: Value[],
2112
+ export declare function toMap<Item, Key extends keyof Item>(
2113
+ array: Item[],
2114
+ key: Key,
2115
+ ): Map<KeyedValue<Item, Key>, Item>;
2116
+ /**
2117
+ * Create a map from an array of items using a specific key, and grouping them into arrays
2118
+ */
2119
+ export declare function toMap<Item, Key extends keyof Item>(
2120
+ array: Item[],
2121
+ key: Key,
1759
2122
  arrays: true,
1760
- ): Map<number, Value[]>;
2123
+ ): Map<KeyedValue<Item, Key>, Item[]>;
1761
2124
  /**
1762
- * - Converts an array into a map
1763
- * - Uses `key` to find an identifcation value to use as keys
2125
+ * Create a map from an array of items using a specific key
1764
2126
  */
1765
- export declare function toMap<Value>(array: Value[], key: Key): Map<Key, Value>;
2127
+ export declare function toMap<Item, Key extends KeyCallback<Item>>(
2128
+ array: Item[],
2129
+ key: Key,
2130
+ ): Map<ReturnType<Key>, Item>;
1766
2131
  /**
1767
- * - Converts an array into a map
1768
- * - Uses `key` to find an identifcation value to use as keys
1769
- * - Groups values into arrays
2132
+ * Create a map from an array of items using a specific key, and grouping them into arrays
1770
2133
  */
1771
- export declare function toMap<Value>(
1772
- array: Value[],
2134
+ export declare function toMap<Item, Key extends KeyCallback<Item>>(
2135
+ array: Item[],
1773
2136
  key: Key,
1774
2137
  arrays: true,
1775
- ): Map<Key, Value[]>;
2138
+ ): Map<ReturnType<Key>, Item[]>;
1776
2139
  /**
1777
- * - Converts an array into a map
1778
- * - Uses `key` to find an identifcation value to use as keys
2140
+ * Create a map from an array of items using a specific key and value
1779
2141
  */
1780
- export declare function toMap<Value>(
1781
- array: Value[],
1782
- key: KeyCallback<Value>,
1783
- ): Map<Key, Value>;
2142
+ export declare function toMap<
2143
+ Item,
2144
+ Key extends keyof Item,
2145
+ Value extends keyof Item,
2146
+ >(
2147
+ array: Item[],
2148
+ key: Key,
2149
+ value: Value,
2150
+ ): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
1784
2151
  /**
1785
- * - Converts an array into a map
1786
- * - Uses `key` to find an identifcation value to use as keys
1787
- * - Groups values into arrays
2152
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
1788
2153
  */
1789
- export declare function toMap<Value>(
1790
- array: Value[],
1791
- key: KeyCallback<Value>,
2154
+ export declare function toMap<
2155
+ Item,
2156
+ Key extends keyof Item,
2157
+ Value extends keyof Item,
2158
+ >(
2159
+ array: Item[],
2160
+ key: Key,
2161
+ value: Value,
1792
2162
  arrays: true,
1793
- ): Map<Key, Value[]>;
2163
+ ): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
1794
2164
  /**
1795
- * Converts an array into a record, using indices as keys
2165
+ * Create a map from an array of items using a specific key and value
1796
2166
  */
1797
- export declare function toRecord<Value>(array: Value[]): Record<number, Value>;
2167
+ export declare function toMap<
2168
+ Item,
2169
+ Key extends keyof Item,
2170
+ Value extends ValueCallback<Item>,
2171
+ >(
2172
+ array: Item[],
2173
+ key: Key,
2174
+ value: Value,
2175
+ ): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
1798
2176
  /**
1799
- * Converts an array into a record, using indices as keys and grouping values into arrays
2177
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
1800
2178
  */
1801
- export declare function toRecord<Value>(
1802
- array: Value[],
2179
+ export declare function toMap<
2180
+ Item,
2181
+ Key extends keyof Item,
2182
+ Value extends ValueCallback<Item>,
2183
+ >(
2184
+ array: Item[],
2185
+ key: Key,
2186
+ value: Value,
1803
2187
  arrays: true,
1804
- ): Record<number, Value[]>;
2188
+ ): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
1805
2189
  /**
1806
- * - Converts an array into a record
1807
- * - Uses `key` to find an identifcation value to use as keys
2190
+ * Create a map from an array of items using a specific key and value
1808
2191
  */
1809
- export declare function toRecord<Value>(
1810
- array: Value[],
2192
+ export declare function toMap<
2193
+ Item,
2194
+ Key extends KeyCallback<Item>,
2195
+ Value extends keyof Item,
2196
+ >(
2197
+ array: Item[],
1811
2198
  key: Key,
1812
- ): Record<Key, Value>;
2199
+ value: Value,
2200
+ ): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
1813
2201
  /**
1814
- * - Converts an array into a record
1815
- * - Uses `key` to find an identifcation value to use as keys
1816
- * - Groups values into arrays
2202
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
1817
2203
  */
1818
- export declare function toRecord<Value>(
1819
- array: Value[],
2204
+ export declare function toMap<
2205
+ Item,
2206
+ Key extends KeyCallback<Item>,
2207
+ Value extends keyof Item,
2208
+ >(
2209
+ array: Item[],
2210
+ key: Key,
2211
+ value: Value,
2212
+ arrays: true,
2213
+ ): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
2214
+ /**
2215
+ * Create a map from an array of items using a specific key and value
2216
+ */
2217
+ export declare function toMap<
2218
+ Item,
2219
+ Key extends KeyCallback<Item>,
2220
+ Value extends ValueCallback<Item>,
2221
+ >(
2222
+ array: Item[],
2223
+ key: Key,
2224
+ value: Value,
2225
+ ): Map<ReturnType<Key>, ReturnType<Value>>;
2226
+ /**
2227
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
2228
+ */
2229
+ export declare function toMap<
2230
+ Item,
2231
+ Key extends KeyCallback<Item>,
2232
+ Value extends ValueCallback<Item>,
2233
+ >(
2234
+ array: Item[],
1820
2235
  key: Key,
2236
+ value: Value,
1821
2237
  arrays: true,
1822
- ): Record<Key, Value[]>;
2238
+ ): Map<ReturnType<Key>, Array<ReturnType<Value>>>;
1823
2239
  /**
1824
- * - Converts an array into a record
1825
- * - Uses `key` to find an identifcation value to use as keys
2240
+ * Create a record from an array of items _(using their indices as keys)_
1826
2241
  */
1827
- export declare function toRecord<Value>(
1828
- array: Value[],
1829
- key: KeyCallback<Value>,
1830
- ): Record<Key, Value>;
2242
+ export declare function toRecord<Item>(array: Item[]): Record<number, Item>;
1831
2243
  /**
1832
- * - Converts an array into a record
1833
- * - Uses `key` to find an identifcation value to use as keys
1834
- * - Groups values into arrays
2244
+ * Create a record from an array of items using a specific key
1835
2245
  */
1836
- export declare function toRecord<Value>(
1837
- array: Value[],
1838
- key: KeyCallback<Value>,
2246
+ export declare function toRecord<Item, Key extends keyof Item>(
2247
+ array: Item[],
2248
+ key: Key,
2249
+ ): Record<KeyedValue<Item, Key>, Item>;
2250
+ /**
2251
+ * Create a record from an array of items using a specific key, and grouping them into arrays
2252
+ */
2253
+ export declare function toRecord<Item, Key extends keyof Item>(
2254
+ array: Item[],
2255
+ key: Key,
2256
+ arrays: true,
2257
+ ): Record<KeyedValue<Item, Key>, Item[]>;
2258
+ /**
2259
+ * Create a record from an array of items using a specific key
2260
+ */
2261
+ export declare function toRecord<Item, Key extends KeyCallback<Item>>(
2262
+ array: Item[],
2263
+ key: Key,
2264
+ ): Record<ReturnType<Key>, Item>;
2265
+ /**
2266
+ * Create a record from an array of items using a specific key, and grouping them into arrays
2267
+ */
2268
+ export declare function toRecord<Item, Key extends KeyCallback<Item>>(
2269
+ array: Item[],
2270
+ key: Key,
2271
+ arrays: true,
2272
+ ): Record<ReturnType<Key>, Item[]>;
2273
+ /**
2274
+ * Create a record from an array of items using a specific key and value
2275
+ */
2276
+ export declare function toRecord<
2277
+ Item,
2278
+ Key extends keyof Item,
2279
+ Value extends keyof Item,
2280
+ >(
2281
+ array: Item[],
2282
+ key: Key,
2283
+ value: Value,
2284
+ ): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
2285
+ /**
2286
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
2287
+ */
2288
+ export declare function toRecord<
2289
+ Item,
2290
+ Key extends keyof Item,
2291
+ Value extends keyof Item,
2292
+ >(
2293
+ array: Item[],
2294
+ key: Key,
2295
+ value: Value,
2296
+ arrays: true,
2297
+ ): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
2298
+ /**
2299
+ * Create a record from an array of items using a specific key and value
2300
+ */
2301
+ export declare function toRecord<
2302
+ Item,
2303
+ Key extends keyof Item,
2304
+ Value extends ValueCallback<Item>,
2305
+ >(
2306
+ array: Item[],
2307
+ key: Key,
2308
+ value: Value,
2309
+ ): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
2310
+ /**
2311
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
2312
+ */
2313
+ export declare function toRecord<
2314
+ Item,
2315
+ Key extends keyof Item,
2316
+ Value extends ValueCallback<Item>,
2317
+ >(
2318
+ array: Item[],
2319
+ key: Key,
2320
+ value: Value,
2321
+ arrays: true,
2322
+ ): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
2323
+ /**
2324
+ * Create a record from an array of items using a specific key and value
2325
+ */
2326
+ export declare function toRecord<
2327
+ Item,
2328
+ Key extends KeyCallback<Item>,
2329
+ Value extends keyof Item,
2330
+ >(
2331
+ array: Item[],
2332
+ key: Key,
2333
+ value: Value,
2334
+ ): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
2335
+ /**
2336
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
2337
+ */
2338
+ export declare function toRecord<
2339
+ Item,
2340
+ Key extends KeyCallback<Item>,
2341
+ Value extends keyof Item,
2342
+ >(
2343
+ array: Item[],
2344
+ key: Key,
2345
+ value: Value,
2346
+ arrays: true,
2347
+ ): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
2348
+ /**
2349
+ * Create a record from an array of items using a specific key and value
2350
+ */
2351
+ export declare function toRecord<
2352
+ Item,
2353
+ Key extends KeyCallback<Item>,
2354
+ Value extends ValueCallback<Item>,
2355
+ >(
2356
+ array: Item[],
2357
+ key: Key,
2358
+ value: Value,
2359
+ ): Record<ReturnType<Key>, ReturnType<Value>>;
2360
+ /**
2361
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
2362
+ */
2363
+ export declare function toRecord<
2364
+ Item,
2365
+ Key extends KeyCallback<Item>,
2366
+ Value extends ValueCallback<Item>,
2367
+ >(
2368
+ array: Item[],
2369
+ key: Key,
2370
+ value: Value,
1839
2371
  arrays: true,
1840
- ): Record<Key, Value[]>;
2372
+ ): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
1841
2373
  /**
1842
- * Returns an array of unique items
2374
+ * Get an array of unique items
1843
2375
  */
1844
- export declare function unique<Value>(array: Value[]): Value[];
2376
+ export declare function unique<Item>(array: Item[]): Item[];
1845
2377
  /**
1846
- * - Returns an array of unique items
2378
+ * - Get an array of unique items
1847
2379
  * - Use `key` to find a comparison value to match with `value`
1848
2380
  */
1849
- export declare function unique<Value>(
1850
- array: Value[],
1851
- key: Key | KeyCallback<Value>,
1852
- ): Value[];
2381
+ export declare function unique<Item, Key extends keyof Item>(
2382
+ array: Item[],
2383
+ key: Key,
2384
+ ): Item[];
1853
2385
  /**
1854
- * Flattens an array _(using native `flat` and maximum depth)_
2386
+ * - Get an array of unique items
2387
+ * - Use `key` to find a comparison value to match with `value`
1855
2388
  */
1856
- export declare function flatten<Value>(
1857
- array: Value[],
1858
- ): NestedArrayType<Value>[];
2389
+ export declare function unique<Item, Key extends KeyCallback<Item>>(
2390
+ array: Item[],
2391
+ key: Key,
2392
+ ): Item[];
1859
2393
  /**
1860
- * - Pushes values to the end of an array, returning the new length
1861
- * - Uses chunking to avoid stack overflow
2394
+ * Flatten an array _(using native `flat` and maximum depth)_
2395
+ */
2396
+ export declare function flatten<Item>(array: Item[]): NestedArrayType<Item>[];
2397
+ /**
2398
+ * - Push values to the end of an array
2399
+ * - Returns the new length
2400
+ * - _(Uses chunking to avoid stack overflow)_
1862
2401
  */
1863
- export declare function push<Value>(array: Value[], values: Value[]): number;
2402
+ export declare function push<Item>(array: Item[], pushed: Item[]): number;
1864
2403
  export type HSLColourValue = {
1865
2404
  hue: number;
1866
2405
  lightness: number;
@@ -1868,35 +2407,41 @@ export type HSLColourValue = {
1868
2407
  };
1869
2408
  export declare class HSLColour extends Colour<HSLColourValue> {
1870
2409
  /**
1871
- * Gets the current hue
2410
+ * Get the current hue
1872
2411
  */
1873
2412
  get hue(): number;
1874
2413
  /**
1875
- * Sets the current hue
2414
+ * Set the current hue
1876
2415
  */
1877
2416
  set hue(value: number);
1878
2417
  /**
1879
- * Gets the current lightness
2418
+ * Get the current lightness
1880
2419
  */
1881
2420
  get lightness(): number;
1882
2421
  /**
1883
- * Sets the current lightness
2422
+ * Set the current lightness
1884
2423
  */
1885
2424
  set lightness(value: number);
1886
2425
  /**
1887
- * Gets the current saturation
2426
+ * Get the current saturation
1888
2427
  */
1889
2428
  get saturation(): number;
1890
2429
  /**
1891
- * Sets the current saturation
2430
+ * Set the current saturation
1892
2431
  */
1893
2432
  set saturation(value: number);
1894
2433
  constructor(value: HSLColourValue);
2434
+ /**
2435
+ * @inheritdoc
2436
+ */
1895
2437
  toHex(): HexColour;
1896
2438
  /**
1897
- * Converts the colour to an RGB-colour
2439
+ * Convert the colour to an RGB-colour
1898
2440
  */
1899
2441
  toRgb(): RGBColour;
2442
+ /**
2443
+ * @inheritdoc
2444
+ */
1900
2445
  toString(): string;
1901
2446
  /**
1902
2447
  * Convert an HSL-colour to an RGB-colour
@@ -1911,11 +2456,11 @@ export declare class HexColour {
1911
2456
  private readonly $colour;
1912
2457
  private readonly state;
1913
2458
  /**
1914
- * Gets the value of the colour
2459
+ * Get the value of the colour
1915
2460
  */
1916
2461
  get value(): string;
1917
2462
  /**
1918
- * Sets the value of the colour
2463
+ * Set the value of the colour
1919
2464
  */
1920
2465
  set value(value: string);
1921
2466
  constructor(value: string);
@@ -1944,7 +2489,7 @@ declare abstract class Colour<Model> {
1944
2489
  private readonly $colour;
1945
2490
  protected readonly state: ColourState<Model>;
1946
2491
  /**
1947
- * Gets the current value of the colour
2492
+ * Get the current value of the colour
1948
2493
  */
1949
2494
  get value(): Model;
1950
2495
  constructor(
@@ -1972,390 +2517,232 @@ export type RGBColourValue = {
1972
2517
  };
1973
2518
  export declare class RGBColour extends Colour<RGBColourValue> {
1974
2519
  /**
1975
- * Gets the current blue value
2520
+ * Get the current blue value
1976
2521
  */
1977
2522
  get blue(): number;
1978
2523
  /**
1979
- * Sets the current blue value
2524
+ * Set the current blue value
1980
2525
  */
1981
2526
  set blue(value: number);
1982
2527
  /**
1983
- * Gets the current green value
2528
+ * Get the current green value
1984
2529
  */
1985
2530
  get green(): number;
1986
2531
  /**
1987
- * Sets the current green value
2532
+ * Set the current green value
1988
2533
  */
1989
2534
  set green(value: number);
1990
2535
  /**
1991
- * Gets the current red value
2536
+ * Get the current red value
1992
2537
  */
1993
2538
  get red(): number;
1994
2539
  /**
1995
- * Sets the current red value
2540
+ * Set the current red value
1996
2541
  */
1997
2542
  set red(value: number);
1998
2543
  constructor(value: RGBColourValue);
1999
- toHex(): HexColour;
2000
- /**
2001
- * Convert the colour to an HSL-colour
2002
- */
2003
- toHsl(): HSLColour;
2004
- toString(): string;
2005
- /**
2006
- * Convert an RGB-colour to a hex-colour
2007
- */
2008
- static toHex(value: RGBColourValue): HexColour;
2009
- /**
2010
- * - Convert an RGB-colour to an HSL-colour
2011
- */
2012
- static toHsl(rgb: RGBColourValue): HSLColour;
2013
- }
2014
- /**
2015
- * Get an RGB-colour from a value-object
2016
- */
2017
- export declare function getRGBColour(value: RGBColourValue): RGBColour;
2018
- /**
2019
- * Is the value a colour?
2020
- */
2021
- export declare function isColour(
2022
- value: unknown,
2023
- ): value is HexColour | HSLColour | RGBColour;
2024
- /**
2025
- * Is the value a hex-colour?
2026
- */
2027
- export declare function isHexColour(value: unknown): value is HexColour;
2028
- /**
2029
- * Is the value an HSL-colour?
2030
- */
2031
- export declare function isHSLColour(value: unknown): value is HSLColour;
2032
- /**
2033
- * Is the value an RGB-colour?
2034
- */
2035
- export declare function isRGBColour(value: unknown): value is RGBColour;
2036
- /**
2037
- * Get a foreground colour _(usually text)_ based on a background colour's luminance
2038
- */
2039
- export declare function getForegroundColour(value: RGBColourValue): string;
2040
- /**
2041
- * Is the value an array or a record?
2042
- */
2043
- export declare function isArrayOrPlainObject(
2044
- value: unknown,
2045
- ): value is ArrayOrPlainObject;
2046
- /**
2047
- * Is the array or object completely empty or only containing `null` or `undefined` values?
2048
- */
2049
- export declare function isEmpty(value: ArrayOrPlainObject): boolean;
2050
- /**
2051
- * Is the value a key?
2052
- */
2053
- export declare function isKey(value: unknown): value is Key;
2054
- /**
2055
- * Is the value undefined or null?
2056
- */
2057
- export declare function isNullable(value: unknown): value is undefined | null;
2058
- /**
2059
- * Is the value undefined, null, or an empty string?
2060
- */
2061
- export declare function isNullableOrEmpty(
2062
- value: unknown,
2063
- ): value is undefined | null | '';
2064
- /**
2065
- * Is the value undefined, null, or a whitespace-only string?
2066
- */
2067
- export declare function isNullableOrWhitespace(
2068
- value: unknown,
2069
- ): value is undefined | null | '';
2070
- /**
2071
- * Is the value a number?
2072
- */
2073
- export declare function isNumber(value: unknown): value is number;
2074
- /**
2075
- * Is the value a number, or a number-like string?
2076
- */
2077
- export declare function isNumerical(
2078
- value: unknown,
2079
- ): value is number | `${number}`;
2080
- /**
2081
- * Is the value an object?
2082
- */
2083
- export declare function isObject(value: unknown): value is object;
2084
- /**
2085
- * Is the value a plain object?
2086
- */
2087
- export declare function isPlainObject(value: unknown): value is PlainObject;
2088
- /**
2089
- * Is the value a primitive value?
2090
- */
2091
- export declare function isPrimitive(value: unknown): value is Primitive;
2092
- declare class Logger {
2093
- /**
2094
- * Logs any number of values at the "debug" log level
2095
- */
2096
- get debug(): {
2097
- (...data: any[]): void;
2098
- (message?: any, ...optionalParams: any[]): void;
2099
- };
2100
- /**
2101
- * Logs the value and shows all its properties
2102
- */
2103
- get dir(): {
2104
- (item?: any, options?: any): void;
2105
- (obj: any, options?: import('util').InspectOptions): void;
2106
- };
2107
- /**
2108
- * Is logging to the console enabled? _(defaults to `true`)_
2109
- */
2110
- get enabled(): boolean;
2111
- /**
2112
- * Enable or disable logging to the console
2113
- */
2114
- set enabled(value: boolean);
2115
- /**
2116
- * Logs any number of values at the "error" log level
2117
- */
2118
- get error(): {
2119
- (...data: any[]): void;
2120
- (message?: any, ...optionalParams: any[]): void;
2121
- };
2122
- /**
2123
- * Logs any number of values at the "info" log level
2124
- */
2125
- get info(): {
2126
- (...data: any[]): void;
2127
- (message?: any, ...optionalParams: any[]): void;
2128
- };
2129
- /**
2130
- * Logs any number of values at the "log" log level
2131
- */
2132
- get log(): {
2133
- (...data: any[]): void;
2134
- (message?: any, ...optionalParams: any[]): void;
2135
- };
2136
- /**
2137
- * Logs data as a table, with optional properties to use as columns
2138
- */
2139
- get table(): {
2140
- (tabularData?: any, properties?: string[]): void;
2141
- (tabularData: any, properties?: readonly string[]): void;
2142
- };
2143
- /**
2144
- * Logs any number of values together with a trace from where it was called
2145
- */
2146
- get trace(): {
2147
- (...data: any[]): void;
2148
- (message?: any, ...optionalParams: any[]): void;
2149
- };
2150
2544
  /**
2151
- * Logs any number of values at the "warn" log level
2545
+ * @inheritdoc
2152
2546
  */
2153
- get warn(): {
2154
- (...data: any[]): void;
2155
- (message?: any, ...optionalParams: any[]): void;
2156
- };
2547
+ toHex(): HexColour;
2157
2548
  /**
2158
- * - Starts a logged timer with a label
2159
- * - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
2549
+ * Convert the colour to an HSL-colour
2160
2550
  */
2161
- time(label: string): Time;
2162
- }
2163
- declare class Time {
2164
- private readonly state;
2165
- constructor(label: string);
2551
+ toHsl(): HSLColour;
2166
2552
  /**
2167
- * - Logs the current duration of the timer
2168
- * - Ignored if logging is disabled
2553
+ * @inheritdoc
2169
2554
  */
2170
- log(): void;
2555
+ toString(): string;
2171
2556
  /**
2172
- * - Stops the timer and logs the total duration
2173
- * - Will always log the total duration, even if logging is disabled
2557
+ * Convert an RGB-colour to a hex-colour
2174
2558
  */
2175
- stop(): void;
2559
+ static toHex(value: RGBColourValue): HexColour;
2560
+ /**
2561
+ * - Convert an RGB-colour to an HSL-colour
2562
+ */
2563
+ static toHsl(rgb: RGBColourValue): HSLColour;
2176
2564
  }
2177
- export declare const logger: Logger;
2178
- /**
2179
- * Get the average value from a list of numbers
2180
- */
2181
- export declare function average(values: number[]): number;
2182
- /**
2183
- * Get the maximum value from a list of numbers
2184
- */
2185
- export declare function max(values: number[]): number;
2186
- /**
2187
- * Get the minimum value from a list of numbers
2188
- */
2189
- export declare function min(values: number[]): number;
2190
- /**
2191
- * Rounds a number to a specific number of decimal places _(defaults to 0)_
2192
- */
2193
- export declare function round(value: number, decimals?: number): number;
2194
- /**
2195
- * Get the sum of a list of numbers
2196
- */
2197
- export declare function sum(values: number[]): number;
2198
- /**
2199
- * Is the number between a minimum and maximum value?
2200
- */
2201
- export declare function between(
2202
- value: number,
2203
- min: number,
2204
- max: number,
2205
- ): boolean;
2206
- /**
2207
- * - Clamps a number between a minimum and maximum value
2208
- * - If `loop` is `true`, when the value is less than the minimum, it will be clamped as the maximum, and vice versa
2209
- */
2210
- export declare function clamp(
2211
- value: number,
2212
- min: number,
2213
- max: number,
2214
- loop?: boolean,
2215
- ): number;
2216
- /**
2217
- * - Gets the number value from an unknown value
2218
- * - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
2219
- * - Based on Lodash :-)
2220
- */
2221
- export declare function getNumber(value: unknown): number;
2222
- /**
2223
- * Converts a query string to a plain _(nested)_ object
2224
- */
2225
- export declare function fromQuery(query: string): PlainObject;
2226
- /**
2227
- * Converts a plain _(nested)_ object to a query string
2228
- */
2229
- export declare function toQuery(parameters: PlainObject): string;
2230
- /**
2231
- * Queues a callback to be executed at the next best time
2232
- */
2233
- export declare function queue(callback: () => void): void;
2234
- /**
2235
- * Returns a random boolean
2236
- */
2237
- export declare function getRandomBoolean(): boolean;
2238
- /**
2239
- * Returns a random string of characters with a specified length
2240
- * - `selection` defaults to all lowercase letters in the English alphabet
2241
- */
2242
- export declare function getRandomCharacters(
2243
- length: number,
2244
- selection?: string,
2245
- ): string;
2246
- /**
2247
- * Returns a random hexadecimal colour
2248
- */
2249
- export declare function getRandomColour(): string;
2250
- /**
2251
- * Returns a random date
2252
- */
2253
- export declare function getRandomDate(earliest?: Date, latest?: Date): Date;
2254
2565
  /**
2255
- * Returns a random floating-point number
2566
+ * Get an RGB-colour from a value-object
2256
2567
  */
2257
- export declare function getRandomFloat(min?: number, max?: number): number;
2568
+ export declare function getRGBColour(value: RGBColourValue): RGBColour;
2258
2569
  /**
2259
- * Returns a random hexadecimal character
2570
+ * Is the value a colour?
2260
2571
  */
2261
- export declare function getRandomHex(): string;
2572
+ export declare function isColour(
2573
+ value: unknown,
2574
+ ): value is HexColour | HSLColour | RGBColour;
2262
2575
  /**
2263
- * Returns a random integer
2576
+ * Is the value a hex-colour?
2264
2577
  */
2265
- export declare function getRandomInteger(min?: number, max?: number): number;
2578
+ export declare function isHexColour(value: unknown): value is HexColour;
2266
2579
  /**
2267
- * Returns a random item from an array
2580
+ * Is the value an HSL-colour?
2268
2581
  */
2269
- export declare function getRandomItem<Value>(array: Value[]): Value;
2582
+ export declare function isHSLColour(value: unknown): value is HSLColour;
2270
2583
  /**
2271
- * - Returns an amount of random items from an array
2272
- * - If `amount` is not specified, a shuffled array will be returned instead
2584
+ * Is the value an RGB-colour?
2273
2585
  */
2274
- export declare function getRandomItems<Value>(
2275
- array: Value[],
2276
- amount?: number,
2277
- ): Value[];
2586
+ export declare function isRGBColour(value: unknown): value is RGBColour;
2278
2587
  /**
2279
- * A Map with a maximum size
2280
- * - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
2281
- * - Behaviour is similar to a _LRU_-cache, where the least recently used entries are removed
2588
+ * Get a foreground colour _(usually text)_ based on a background colour's luminance
2282
2589
  */
2283
- export declare class SizedMap<Key = unknown, Value = unknown> extends Map<
2284
- Key,
2285
- Value
2286
- > {
2287
- private readonly maximumSize;
2590
+ export declare function getForegroundColour(value: RGBColourValue): string;
2591
+ export declare class Emitter<Value> {
2592
+ private readonly state;
2288
2593
  /**
2289
- * Is the Map full?
2594
+ * Is the emitter active?
2290
2595
  */
2291
- get full(): boolean;
2596
+ get active(): boolean;
2292
2597
  /**
2293
- * The maximum size of the Map
2598
+ * The observable that can be subscribed to
2294
2599
  */
2295
- get maximum(): number;
2600
+ get observable(): Observable<Value>;
2296
2601
  /**
2297
- * Creates a new Map with entries and a maximum size _(2^20)_
2602
+ * The current value
2298
2603
  */
2299
- constructor(entries: Array<[Key, Value]>);
2604
+ get value(): Value;
2605
+ constructor(value: Value);
2300
2606
  /**
2301
- * Creates a new Map with a maximum size _(but clamped at 2^24)_
2607
+ * Destroy the emitter
2302
2608
  */
2303
- constructor(maximum: number);
2609
+ destroy(): void;
2304
2610
  /**
2305
- * Creates a new Map with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
2611
+ * Emit a new value _(and optionally finishes the emitter)_
2306
2612
  */
2307
- constructor(entries?: Array<[Key, Value]>, maximum?: number);
2613
+ emit(value: Value, finish?: boolean): void;
2308
2614
  /**
2309
- * @inheritdoc
2615
+ * Emit an error _(and optionally finishes the emitter)_
2310
2616
  */
2311
- get(key: Key): Value | undefined;
2617
+ error(error: Error, finish?: boolean): void;
2312
2618
  /**
2313
- * @inheritdoc
2619
+ * Finish the emitter
2314
2620
  */
2315
- set(key: Key, value: Value): this;
2621
+ finish(): void;
2316
2622
  }
2317
- /**
2318
- * A Set with a maximum size
2319
- * - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
2320
- * - Behaviour is similar to a _LRU_-cache, where the oldest values are removed
2321
- */
2322
- export declare class SizedSet<Value = unknown> extends Set<Value> {
2323
- private readonly maximumSize;
2623
+ export declare class Observable<Value> {
2624
+ private readonly state;
2625
+ constructor(
2626
+ emitter: Emitter<Value>,
2627
+ observers: Map<Subscription<Value>, Observer<Value>>,
2628
+ );
2324
2629
  /**
2325
- * Is the Set full?
2630
+ * Subscribe to value changes
2326
2631
  */
2327
- get full(): boolean;
2632
+ subscribe(observer: Observer<Value>): Subscription<Value>;
2328
2633
  /**
2329
- * The maximum size of the Set
2634
+ * Subscribe to value changes
2330
2635
  */
2331
- get maximum(): number;
2636
+ subscribe(
2637
+ onNext: (value: Value) => void,
2638
+ onError?: (error: Error) => void,
2639
+ onComplete?: () => void,
2640
+ ): Subscription<Value>;
2641
+ }
2642
+ export type ObservableState<Value> = {
2643
+ emitter: Emitter<Value>;
2644
+ observers: Map<Subscription<Value>, Observer<Value>>;
2645
+ };
2646
+ export type Observer<Value> = {
2332
2647
  /**
2333
- * Creates a new Set with values and a maximum size _(2^20)_
2648
+ * Callback for when the observable is complete
2334
2649
  */
2335
- constructor(values: Value[]);
2650
+ complete?: () => void;
2336
2651
  /**
2337
- * Creates a new Set with a maximum size _(but clamped at 2^24)_
2652
+ * Callback for when the observable has an error
2338
2653
  */
2339
- constructor(maximum: number);
2654
+ error?: (error: Error) => void;
2340
2655
  /**
2341
- * Creates a new Set with _(optional)_ values and a maximum size _(defaults to 2^20; clamped at 2^24)_
2656
+ * Callback for when the observable has a new value
2342
2657
  */
2343
- constructor(values?: Value[], maximum?: number);
2658
+ next?: (value: Value) => void;
2659
+ };
2660
+ export declare class Subscription<Value> {
2661
+ private readonly state;
2662
+ constructor(state: ObservableState<Value>);
2344
2663
  /**
2345
- * @inheritdoc
2664
+ * Is the subscription closed?
2346
2665
  */
2347
- add(value: Value): this;
2666
+ get closed(): boolean;
2348
2667
  /**
2349
- * Get a value from an index in the Set, if it exists
2350
- * - Negative indices are counted from the end
2351
- * - Optionally move the value to the end with `update`
2668
+ * Destroy the subscription
2352
2669
  */
2353
- at(index: number, update?: boolean): Value | undefined;
2670
+ destroy(): void;
2354
2671
  /**
2355
- * Get a value from the Set, if it exists _(and move it to the end)_
2672
+ * Unsubscribe from its observable
2356
2673
  */
2357
- get(value: Value, update?: boolean): Value | undefined;
2674
+ unsubscribe(): void;
2675
+ }
2676
+ /**
2677
+ * Create a new emitter
2678
+ */
2679
+ export declare function emitter<Value>(value: Value): Emitter<Value>;
2680
+ export type Debounced<Callback extends GenericCallback> = Callback & {
2681
+ /**
2682
+ * Cancel the debounce
2683
+ */
2684
+ cancel: () => void;
2685
+ };
2686
+ declare class Memoised<Callback extends GenericCallback> {
2687
+ readonly state: MemoisedState<Callback>;
2688
+ constructor(callback: Callback);
2689
+ /**
2690
+ * Clear the cache
2691
+ */
2692
+ clear(): void;
2693
+ /**
2694
+ * Delete a result from the cache
2695
+ */
2696
+ delete(key: Parameters<Callback>[0]): boolean;
2697
+ /**
2698
+ * Destroy the instance, clearing its cache and removing its callback
2699
+ */
2700
+ destroy(): void;
2701
+ /**
2702
+ * Get a result from the cache if it exists _(or `undefined` otherwise)_
2703
+ */
2704
+ get(key: Parameters<Callback>[0]): ReturnType<Callback> | undefined;
2705
+ /**
2706
+ * Does the result exist?
2707
+ */
2708
+ has(key: Parameters<Callback>[0]): boolean;
2709
+ /**
2710
+ * Get the result from the cache if it exists; otherwise runs the callback, caches the result, and returns it
2711
+ */
2712
+ run(...parameters: Parameters<Callback>): ReturnType<Callback>;
2358
2713
  }
2714
+ export type MemoisedState<Callback extends GenericCallback> = {
2715
+ cache: Map<Parameters<Callback>[0], ReturnType<Callback>>;
2716
+ getter: (...parameters: Parameters<Callback>) => ReturnType<Callback>;
2717
+ };
2718
+ /**
2719
+ * - Debounce a function, ensuring it is only called after `time` milliseconds have passed
2720
+ * - On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
2721
+ * - Time is clamped between _0_ and _1000_ milliseconds
2722
+ * - Returns the callback with an added `cancel`-method for manually cancelling the debounce
2723
+ */
2724
+ export declare function debounce<Callback extends GenericCallback>(
2725
+ callback: Callback,
2726
+ time?: number,
2727
+ ): Debounced<Callback>;
2728
+ /**
2729
+ * Memoise a function, caching and retrieving results based on the first parameter
2730
+ */
2731
+ export declare function memoise<Callback extends GenericCallback>(
2732
+ callback: Callback,
2733
+ ): Memoised<Callback>;
2734
+ /**
2735
+ * A function that does nothing, which can be useful, I guess…
2736
+ */
2737
+ export declare function noop(): void;
2738
+ /**
2739
+ * - Throttle a function, ensuring it is only called once every `time` milliseconds
2740
+ * - Time is clamped between _0_ and _1000_ milliseconds
2741
+ */
2742
+ export declare function throttle<Callback extends GenericCallback>(
2743
+ callback: Callback,
2744
+ time?: number,
2745
+ ): Callback;
2359
2746
  /**
2360
2747
  * Convert a string to camel case _(thisIsCamelCase)_
2361
2748
  */
@@ -2390,6 +2777,9 @@ export type Options = {
2390
2777
  */
2391
2778
  pattern?: RegExp;
2392
2779
  };
2780
+ /**
2781
+ * Render a string from a template with variables
2782
+ */
2393
2783
  export declare function template(
2394
2784
  value: string,
2395
2785
  variables: PlainObject,
@@ -2404,18 +2794,18 @@ export declare function createUuid(): string;
2404
2794
  */
2405
2795
  export declare function getString(value: unknown): string;
2406
2796
  /**
2407
- * Joins an array into a string while ignoring empty values _(with an optional delimiter)_
2797
+ * Join an array into a string while ignoring empty values _(with an optional delimiter)_
2408
2798
  */
2409
2799
  export declare function join(value: unknown[], delimiter?: string): string;
2410
2800
  /**
2411
- * Parses a JSON string into its proper value _(or `undefined` if it fails)_
2801
+ * Parse a JSON string into its proper value _(or `undefined` if it fails)_
2412
2802
  */
2413
2803
  export declare function parse(
2414
2804
  value: string,
2415
2805
  reviver?: (this: unknown, key: string, value: unknown) => unknown,
2416
2806
  ): unknown;
2417
2807
  /**
2418
- * Truncates a string to a specified length, when possible
2808
+ * Truncate a string to a specified length, when possible
2419
2809
  * - Returned as-is if the string is already short enough
2420
2810
  * - A suffix may be appended to the truncated string, e.g., an ellipsis
2421
2811
  */
@@ -2428,8 +2818,10 @@ export declare function truncate(
2428
2818
  * Split a string into words _(and other readable parts)_
2429
2819
  */
2430
2820
  export declare function words(value: string): string[];
2431
- export declare function clone(fn: (...args: unknown[]) => unknown): null;
2432
- export declare function clone<Value>(value: Value): Value;
2821
+ /**
2822
+ * Clone any kind of value _(deeply, if needed)_
2823
+ */
2824
+ export declare function clone(value: unknown): {} | null | undefined;
2433
2825
  /**
2434
2826
  * Compare two values _(for sorting purposes)_
2435
2827
  */
@@ -2498,7 +2890,7 @@ export type MergeOptions = {
2498
2890
  skipNullable?: boolean;
2499
2891
  };
2500
2892
  /**
2501
- * Merges multiple arrays or objects into a single one
2893
+ * Merge multiple arrays or objects into a single one
2502
2894
  */
2503
2895
  export declare function merge<Model extends ArrayOrPlainObject>(
2504
2896
  values: Model[],
@@ -2531,7 +2923,7 @@ export type Smushed<Value> = Simplify<{
2531
2923
  [Key in Paths<Value>]: Get<Value, ToString<Key>>;
2532
2924
  }>;
2533
2925
  /**
2534
- * Smushes an object into a flat object with dot notation keys
2926
+ * Smush an object into a flat object that uses dot notation keys
2535
2927
  */
2536
2928
  export declare function smush<Value extends PlainObject>(
2537
2929
  value: Value,
@@ -2545,13 +2937,13 @@ export type Unsmushed<Value extends PlainObject> = Simplify<
2545
2937
  >
2546
2938
  >;
2547
2939
  /**
2548
- * Unsmushes a smushed object _(turning dot notation keys into nested keys)_
2940
+ * Unsmush a smushed object _(turning dot notation keys into nested keys)_
2549
2941
  */
2550
2942
  export declare function unsmush<Value extends PlainObject>(
2551
2943
  value: Value,
2552
2944
  ): Unsmushed<Value>;
2553
2945
  /**
2554
- * Creates a new object with only the specified keys
2946
+ * Create a new object with only the specified keys
2555
2947
  */
2556
2948
  export declare function partial<
2557
2949
  Value extends PlainObject,