@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
@@ -1,57 +1,53 @@
1
- import {insertValues} from '@/array/insert';
1
+ import {insertValues} from '~/array/insert';
2
2
 
3
3
  /**
4
4
  * Removes and returns all items from an array starting from a specific index
5
5
  */
6
- export function splice<Value>(array: Value[], start: number): Value[];
6
+ export function splice<Item>(array: Item[], start: number): Item[];
7
7
 
8
8
  /**
9
9
  * Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
10
10
  */
11
- export function splice<Value>(
12
- array: Value[],
11
+ export function splice<Item>(
12
+ array: Item[],
13
13
  start: number,
14
14
  amount: number,
15
- ): Value[];
15
+ ): Item[];
16
16
 
17
17
  /**
18
18
  * - Splices values into an array and returns any removed values
19
19
  * - Uses chunking to avoid stack overflow
20
20
  */
21
- export function splice<Value>(
22
- array: Value[],
21
+ export function splice<Item>(
22
+ array: Item[],
23
23
  start: number,
24
- values: Value[],
25
- ): Value[];
24
+ added: Item[],
25
+ ): Item[];
26
26
 
27
27
  /**
28
28
  * - Splices values into an array and returns any removed values
29
29
  * - Uses chunking to avoid stack overflow
30
30
  */
31
- export function splice<Value>(
32
- array: Value[],
31
+ export function splice<Item>(
32
+ array: Item[],
33
33
  start: number,
34
34
  amount: number,
35
- values: Value[],
36
- ): Value[];
35
+ added: Item[],
36
+ ): Item[];
37
37
 
38
- export function splice<Value>(
39
- array: Value[],
38
+ export function splice(
39
+ array: unknown[],
40
40
  start: number,
41
- amountOrValues?: number | Value[],
42
- values?: Value[],
43
- ): Value[] {
44
- const amoutOrValuesIsArray = Array.isArray(amountOrValues);
41
+ first?: number | unknown[],
42
+ second?: unknown[],
43
+ ): unknown[] {
44
+ const isArray = Array.isArray(first);
45
45
 
46
46
  return insertValues(
47
47
  'splice',
48
48
  array,
49
- amoutOrValuesIsArray ? amountOrValues : values ?? [],
49
+ isArray ? first : (second ?? []),
50
50
  start,
51
- amoutOrValuesIsArray
52
- ? array.length
53
- : typeof amountOrValues === 'number' && amountOrValues > 0
54
- ? amountOrValues
55
- : 0,
56
- ) as Value[];
51
+ isArray ? array.length : typeof first === 'number' && first > 0 ? first : 0,
52
+ ) as unknown[];
57
53
  }
@@ -1,82 +1,170 @@
1
- import type {KeyCallback} from '@/array/models';
2
- import {getCallbacks} from '@/internal/array-callbacks';
3
- import type {Key} from '@/models';
1
+ import type {KeyCallback, ValueCallback} from '~/array/models';
2
+ import {getCallbacks} from '~/internal/array/callbacks';
3
+ import type {Key, KeyedValue} from '~/models';
4
4
 
5
5
  /**
6
- * Converts an array into a map, using indices as keys
6
+ * Create a map from an array of items _(using their indices as keys)_
7
7
  */
8
- export function toMap<Value>(array: Value[]): Map<number, Value>;
8
+ export function toMap<Item>(array: Item[]): Map<number, Item>;
9
9
 
10
10
  /**
11
- * Converts an array into a map, using indices as keys and grouping values into arrays
11
+ * Create a map from an array of items using a specific key
12
12
  */
13
- export function toMap<Value>(
14
- array: Value[],
13
+ export function toMap<Item, Key extends keyof Item>(
14
+ array: Item[],
15
+ key: Key,
16
+ ): Map<KeyedValue<Item, Key>, Item>;
17
+
18
+ /**
19
+ * Create a map from an array of items using a specific key, and grouping them into arrays
20
+ */
21
+ export function toMap<Item, Key extends keyof Item>(
22
+ array: Item[],
23
+ key: Key,
15
24
  arrays: true,
16
- ): Map<number, Value[]>;
25
+ ): Map<KeyedValue<Item, Key>, Item[]>;
17
26
 
18
27
  /**
19
- * - Converts an array into a map
20
- * - Uses `key` to find an identifcation value to use as keys
28
+ * Create a map from an array of items using a specific key
21
29
  */
22
- export function toMap<Value>(array: Value[], key: Key): Map<Key, Value>;
30
+ export function toMap<Item, Key extends KeyCallback<Item>>(
31
+ array: Item[],
32
+ key: Key,
33
+ ): Map<ReturnType<Key>, Item>;
23
34
 
24
35
  /**
25
- * - Converts an array into a map
26
- * - Uses `key` to find an identifcation value to use as keys
27
- * - Groups values into arrays
36
+ * Create a map from an array of items using a specific key, and grouping them into arrays
28
37
  */
29
- export function toMap<Value>(
30
- array: Value[],
38
+ export function toMap<Item, Key extends KeyCallback<Item>>(
39
+ array: Item[],
31
40
  key: Key,
32
41
  arrays: true,
33
- ): Map<Key, Value[]>;
42
+ ): Map<ReturnType<Key>, Item[]>;
34
43
 
35
44
  /**
36
- * - Converts an array into a map
37
- * - Uses `key` to find an identifcation value to use as keys
45
+ * Create a map from an array of items using a specific key and value
38
46
  */
39
- export function toMap<Value>(
40
- array: Value[],
41
- key: KeyCallback<Value>,
42
- ): Map<Key, Value>;
47
+ export function toMap<Item, Key extends keyof Item, Value extends keyof Item>(
48
+ array: Item[],
49
+ key: Key,
50
+ value: Value,
51
+ ): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
43
52
 
44
53
  /**
45
- * - Converts an array into a map
46
- * - Uses `key` to find an identifcation value to use as keys
47
- * - Groups values into arrays
54
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
48
55
  */
49
- export function toMap<Value>(
50
- array: Value[],
51
- key: KeyCallback<Value>,
56
+ export function toMap<Item, Key extends keyof Item, Value extends keyof Item>(
57
+ array: Item[],
58
+ key: Key,
59
+ value: Value,
52
60
  arrays: true,
53
- ): Map<Key, Value[]>;
61
+ ): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
54
62
 
55
- export function toMap<Value>(
56
- array: Value[],
57
- first?: boolean | Key | KeyCallback<Value>,
58
- second?: boolean,
63
+ /**
64
+ * Create a map from an array of items using a specific key and value
65
+ */
66
+ export function toMap<
67
+ Item,
68
+ Key extends keyof Item,
69
+ Value extends ValueCallback<Item>,
70
+ >(
71
+ array: Item[],
72
+ key: Key,
73
+ value: Value,
74
+ ): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
75
+
76
+ /**
77
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
78
+ */
79
+ export function toMap<
80
+ Item,
81
+ Key extends keyof Item,
82
+ Value extends ValueCallback<Item>,
83
+ >(
84
+ array: Item[],
85
+ key: Key,
86
+ value: Value,
87
+ arrays: true,
88
+ ): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
89
+
90
+ /**
91
+ * Create a map from an array of items using a specific key and value
92
+ */
93
+ export function toMap<
94
+ Item,
95
+ Key extends KeyCallback<Item>,
96
+ Value extends keyof Item,
97
+ >(
98
+ array: Item[],
99
+ key: Key,
100
+ value: Value,
101
+ ): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
102
+
103
+ /**
104
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
105
+ */
106
+ export function toMap<
107
+ Item,
108
+ Key extends KeyCallback<Item>,
109
+ Value extends keyof Item,
110
+ >(
111
+ array: Item[],
112
+ key: Key,
113
+ value: Value,
114
+ arrays: true,
115
+ ): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
116
+
117
+ /**
118
+ * Create a map from an array of items using a specific key and value
119
+ */
120
+ export function toMap<
121
+ Item,
122
+ Key extends KeyCallback<Item>,
123
+ Value extends ValueCallback<Item>,
124
+ >(
125
+ array: Item[],
126
+ key: Key,
127
+ value: Value,
128
+ ): Map<ReturnType<Key>, ReturnType<Value>>;
129
+
130
+ /**
131
+ * Create a map from an array of items using a specific key and value, and grouping them into arrays
132
+ */
133
+ export function toMap<
134
+ Item,
135
+ Key extends KeyCallback<Item>,
136
+ Value extends ValueCallback<Item>,
137
+ >(
138
+ array: Item[],
139
+ key: Key,
140
+ value: Value,
141
+ arrays: true,
142
+ ): Map<ReturnType<Key>, Array<ReturnType<Value>>>;
143
+
144
+ export function toMap(
145
+ array: unknown[],
146
+ first?: unknown,
147
+ second?: unknown,
148
+ third?: unknown,
59
149
  ): Map<Key, unknown> {
60
- const asArrays = first === true || second === true;
61
- const callbacks = getCallbacks(undefined, first);
62
- const hasCallback = typeof callbacks?.key === 'function';
150
+ const asArrays = first === true || second === true || third === true;
151
+ const callbacks = getCallbacks(undefined, first, second);
63
152
  const map = new Map<Key, unknown>();
64
153
  const {length} = array;
65
154
 
66
155
  for (let index = 0; index < length; index += 1) {
67
- const value = array[index];
156
+ const item = array[index];
68
157
 
69
- const key = hasCallback
70
- ? (callbacks?.key?.(value, index, array) ?? index)
71
- : index;
158
+ const key = callbacks?.key?.(item, index, array) ?? index;
159
+ const value = callbacks?.value?.(item, index, array) ?? item;
72
160
 
73
161
  if (asArrays) {
74
162
  const existing = map.get(key);
75
163
 
76
- if (Array.isArray(existing)) {
77
- existing.push(value);
78
- } else {
164
+ if (existing == null) {
79
165
  map.set(key, [value]);
166
+ } else {
167
+ (existing as unknown[]).push(value);
80
168
  }
81
169
  } else {
82
170
  map.set(key, value);
@@ -1,66 +1,164 @@
1
- import {groupValues} from '@/array/group-by';
2
- import type {KeyCallback} from '@/array/models';
3
- import type {Key} from '@/models';
1
+ import {groupValues} from '~/array/group-by';
2
+ import type {KeyCallback, ValueCallback} from '~/array/models';
3
+ import type {KeyedValue, PlainObject} from '~/models';
4
4
 
5
5
  /**
6
- * Converts an array into a record, using indices as keys
6
+ * Create a record from an array of items _(using their indices as keys)_
7
7
  */
8
- export function toRecord<Value>(array: Value[]): Record<number, Value>;
8
+ export function toRecord<Item>(array: Item[]): Record<number, Item>;
9
9
 
10
10
  /**
11
- * Converts an array into a record, using indices as keys and grouping values into arrays
11
+ * Create a record from an array of items using a specific key
12
12
  */
13
- export function toRecord<Value>(
14
- array: Value[],
13
+ export function toRecord<Item, Key extends keyof Item>(
14
+ array: Item[],
15
+ key: Key,
16
+ ): Record<KeyedValue<Item, Key>, Item>;
17
+
18
+ /**
19
+ * Create a record from an array of items using a specific key, and grouping them into arrays
20
+ */
21
+ export function toRecord<Item, Key extends keyof Item>(
22
+ array: Item[],
23
+ key: Key,
24
+ arrays: true,
25
+ ): Record<KeyedValue<Item, Key>, Item[]>;
26
+
27
+ /**
28
+ * Create a record from an array of items using a specific key
29
+ */
30
+ export function toRecord<Item, Key extends KeyCallback<Item>>(
31
+ array: Item[],
32
+ key: Key,
33
+ ): Record<ReturnType<Key>, Item>;
34
+
35
+ /**
36
+ * Create a record from an array of items using a specific key, and grouping them into arrays
37
+ */
38
+ export function toRecord<Item, Key extends KeyCallback<Item>>(
39
+ array: Item[],
40
+ key: Key,
15
41
  arrays: true,
16
- ): Record<number, Value[]>;
42
+ ): Record<ReturnType<Key>, Item[]>;
17
43
 
18
44
  /**
19
- * - Converts an array into a record
20
- * - Uses `key` to find an identifcation value to use as keys
45
+ * Create a record from an array of items using a specific key and value
21
46
  */
22
- export function toRecord<Value>(array: Value[], key: Key): Record<Key, Value>;
47
+ export function toRecord<
48
+ Item,
49
+ Key extends keyof Item,
50
+ Value extends keyof Item,
51
+ >(
52
+ array: Item[],
53
+ key: Key,
54
+ value: Value,
55
+ ): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
23
56
 
24
57
  /**
25
- * - Converts an array into a record
26
- * - Uses `key` to find an identifcation value to use as keys
27
- * - Groups values into arrays
58
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
28
59
  */
29
- export function toRecord<Value>(
30
- array: Value[],
60
+ export function toRecord<
61
+ Item,
62
+ Key extends keyof Item,
63
+ Value extends keyof Item,
64
+ >(
65
+ array: Item[],
31
66
  key: Key,
67
+ value: Value,
32
68
  arrays: true,
33
- ): Record<Key, Value[]>;
69
+ ): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
34
70
 
35
71
  /**
36
- * - Converts an array into a record
37
- * - Uses `key` to find an identifcation value to use as keys
72
+ * Create a record from an array of items using a specific key and value
38
73
  */
39
- export function toRecord<Value>(
40
- array: Value[],
41
- key: KeyCallback<Value>,
42
- ): Record<Key, Value>;
74
+ export function toRecord<
75
+ Item,
76
+ Key extends keyof Item,
77
+ Value extends ValueCallback<Item>,
78
+ >(
79
+ array: Item[],
80
+ key: Key,
81
+ value: Value,
82
+ ): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
43
83
 
44
84
  /**
45
- * - Converts an array into a record
46
- * - Uses `key` to find an identifcation value to use as keys
47
- * - Groups values into arrays
85
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
48
86
  */
49
- export function toRecord<Value>(
50
- array: Value[],
51
- key: KeyCallback<Value>,
87
+ export function toRecord<
88
+ Item,
89
+ Key extends keyof Item,
90
+ Value extends ValueCallback<Item>,
91
+ >(
92
+ array: Item[],
93
+ key: Key,
94
+ value: Value,
95
+ arrays: true,
96
+ ): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
97
+
98
+ /**
99
+ * Create a record from an array of items using a specific key and value
100
+ */
101
+ export function toRecord<
102
+ Item,
103
+ Key extends KeyCallback<Item>,
104
+ Value extends keyof Item,
105
+ >(
106
+ array: Item[],
107
+ key: Key,
108
+ value: Value,
109
+ ): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
110
+
111
+ /**
112
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
113
+ */
114
+ export function toRecord<
115
+ Item,
116
+ Key extends KeyCallback<Item>,
117
+ Value extends keyof Item,
118
+ >(
119
+ array: Item[],
120
+ key: Key,
121
+ value: Value,
122
+ arrays: true,
123
+ ): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
124
+
125
+ /**
126
+ * Create a record from an array of items using a specific key and value
127
+ */
128
+ export function toRecord<
129
+ Item,
130
+ Key extends KeyCallback<Item>,
131
+ Value extends ValueCallback<Item>,
132
+ >(
133
+ array: Item[],
134
+ key: Key,
135
+ value: Value,
136
+ ): Record<ReturnType<Key>, ReturnType<Value>>;
137
+
138
+ /**
139
+ * Create a record from an array of items using a specific key and value, and grouping them into arrays
140
+ */
141
+ export function toRecord<
142
+ Item,
143
+ Key extends KeyCallback<Item>,
144
+ Value extends ValueCallback<Item>,
145
+ >(
146
+ array: Item[],
147
+ key: Key,
148
+ value: Value,
52
149
  arrays: true,
53
- ): Record<Key, Value[]>;
150
+ ): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
54
151
 
55
- export function toRecord<Value>(
56
- array: Value[],
57
- first?: boolean | Key | KeyCallback<Value>,
58
- second?: boolean,
59
- ): Record<Key, unknown> {
152
+ export function toRecord(
153
+ array: unknown[],
154
+ first?: unknown,
155
+ second?: unknown,
156
+ third?: unknown,
157
+ ): PlainObject {
60
158
  return groupValues(
61
159
  array,
62
- first as Key | KeyCallback<Value>,
63
- first === true || second === true,
64
- true,
160
+ first as never,
161
+ second,
162
+ first === true || second === true || third === true,
65
163
  );
66
164
  }
@@ -1,24 +1,29 @@
1
- import type {KeyCallback} from '@/array/models';
2
- import {findValues} from '@/internal/array-find';
3
- import type {Key} from '@/models';
1
+ import type {KeyCallback} from '~/array/models';
2
+ import {findValues} from '~/internal/array/find';
4
3
 
5
4
  /**
6
- * Returns an array of unique items
5
+ * Get an array of unique items
7
6
  */
8
- export function unique<Value>(array: Value[]): Value[];
7
+ export function unique<Item>(array: Item[]): Item[];
9
8
 
10
9
  /**
11
- * - Returns an array of unique items
10
+ * - Get an array of unique items
12
11
  * - Use `key` to find a comparison value to match with `value`
13
12
  */
14
- export function unique<Value>(
15
- array: Value[],
16
- key: Key | KeyCallback<Value>,
17
- ): Value[];
13
+ export function unique<Item, Key extends keyof Item>(
14
+ array: Item[],
15
+ key: Key,
16
+ ): Item[];
18
17
 
19
- export function unique<Value>(
20
- array: Value[],
21
- key?: Key | KeyCallback<Value>,
22
- ): Value[] {
23
- return findValues('unique', array, undefined, key);
18
+ /**
19
+ * - Get an array of unique items
20
+ * - Use `key` to find a comparison value to match with `value`
21
+ */
22
+ export function unique<Item, Key extends KeyCallback<Item>>(
23
+ array: Item[],
24
+ key: Key,
25
+ ): Item[];
26
+
27
+ export function unique(array: unknown[], key?: unknown): unknown[] {
28
+ return findValues('unique', array, undefined, key, undefined);
24
29
  }
@@ -1,12 +1,12 @@
1
- import type {HexColour} from '@/colour/hex';
2
- import {isColourValue} from '@/colour/is';
1
+ import type {HexColour} from '~/colour/hex';
2
+ import {isColourValue} from '~/colour/is';
3
3
 
4
4
  export abstract class Colour<Model> {
5
5
  private declare readonly $colour: string;
6
6
  protected declare readonly state: ColourState<Model>;
7
7
 
8
8
  /**
9
- * Gets the current value of the colour
9
+ * Get the current value of the colour
10
10
  */
11
11
  get value(): Model {
12
12
  return {...this.state.value};
@@ -1,7 +1,7 @@
1
- import {HexColour} from '@/colour/hex';
2
- import {HSLColour, type HSLColourValue} from '@/colour/hsl';
3
- import {RGBColour, type RGBColourValue} from '@/colour/rgb';
4
- import {clamp} from '@/number';
1
+ import {HexColour} from '~/colour/hex';
2
+ import {HSLColour, type HSLColourValue} from '~/colour/hsl';
3
+ import {RGBColour, type RGBColourValue} from '~/colour/rgb';
4
+ import {clamp} from '~/number';
5
5
 
6
6
  export const anyPattern = /^#*([a-f0-9]{3}){1,2}$/i;
7
7
  const groupedPattern = /^#*([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
@@ -115,8 +115,6 @@ export function rgbToHsl(rgb: RGBColourValue): HSLColour {
115
115
  case red:
116
116
  hue = (green - blue) / delta + (green < blue ? 6 : 0);
117
117
  break;
118
- default:
119
- break;
120
118
  }
121
119
 
122
120
  hue *= 60;
@@ -1,6 +1,6 @@
1
- import {anyPattern, getNormalisedHex, hexToRgb} from '@/colour/functions';
2
- import type {HSLColour} from '@/colour/hsl';
3
- import type {RGBColour} from '@/colour/rgb';
1
+ import {anyPattern, getNormalisedHex, hexToRgb} from '~/colour/functions';
2
+ import type {HSLColour} from '~/colour/hsl';
3
+ import type {RGBColour} from '~/colour/rgb';
4
4
 
5
5
  type State = {
6
6
  value: string;
@@ -11,14 +11,14 @@ export class HexColour {
11
11
  private readonly state: State;
12
12
 
13
13
  /**
14
- * Gets the value of the colour
14
+ * Get the value of the colour
15
15
  */
16
16
  get value(): string {
17
17
  return `#${this.state.value}`;
18
18
  }
19
19
 
20
20
  /**
21
- * Sets the value of the colour
21
+ * Set the value of the colour
22
22
  */
23
23
  set value(value: string) {
24
24
  this.state.value = anyPattern.test(value)