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