@oscarpalmer/atoms 0.193.0 → 0.194.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 (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
@@ -1,351 +0,0 @@
1
- import {groupValues} from '../internal/array/group';
2
- import type {Key, KeyedValue, PlainObject, Simplify} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Create a record from an array of items using callbacks
8
- *
9
- * If multiple items have the same key, the latest item will be used
10
- *
11
- * @param array Array to convert
12
- * @param key Callback to get an item's grouping key
13
- * @param value Callback to get an item's value
14
- * @returns Record of keyed values
15
- *
16
- * @example
17
- * ```typescript
18
- * toRecord(
19
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
20
- * item => item.value,
21
- * item => item.id,
22
- * ); // => { 10: 3, 20: 2 }
23
- * ```
24
- */
25
- export function toRecord<
26
- Item,
27
- KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
28
- ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
29
- >(
30
- array: Item[],
31
- key: KeyCallback,
32
- value: ValueCallback,
33
- ): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
34
-
35
- /**
36
- * Create a record from an array of items using a callback and value
37
- *
38
- * If multiple items have the same key, the latest item will be used
39
- *
40
- * @param array Array to convert
41
- * @param callback Callback to get an item's grouping key
42
- * @param value Key to use for value
43
- * @returns Record with keys
44
- *
45
- * @example
46
- * ```typescript
47
- * toRecord(
48
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
49
- * item => item.value,
50
- * 'id',
51
- * ); // => { 10: 3, 20: 2 }
52
- * ```
53
- */
54
- export function toRecord<
55
- Item extends PlainObject,
56
- Callback extends (item: Item, index: number, array: Item[]) => Key,
57
- ItemValue extends keyof Item,
58
- >(
59
- array: Item[],
60
- callback: Callback,
61
- value: ItemValue,
62
- ): Record<ReturnType<Callback>, Item[ItemValue]>;
63
-
64
- /**
65
- * Create a record from an array of items using a key and callback
66
- *
67
- * If multiple items have the same key, the latest item will be used
68
- *
69
- * @param array Array to convert
70
- * @param key Key to use for grouping
71
- * @param callback Callback to get an item's value
72
- * @returns Record with keys
73
- *
74
- * @example
75
- * ```typescript
76
- * toRecord(
77
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
78
- * 'value',
79
- * item => item.id,
80
- * ); // => { 10: 3, 20: 2 }
81
- * ```
82
- */
83
- export function toRecord<
84
- Item extends PlainObject,
85
- ItemKey extends keyof Item,
86
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
87
- >(
88
- array: Item[],
89
- key: ItemKey,
90
- callback: Callback,
91
- ): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback>>>;
92
-
93
- /**
94
- * Create a record from an array of items using a key and value
95
- *
96
- * If multiple items have the same key, the latest item will be used
97
- *
98
- * @param array Array to convert
99
- * @param key Key to use for grouping
100
- * @param value Key to use for value
101
- * @returns Record of keyed values
102
- *
103
- * @example
104
- * ```typescript
105
- * toRecord(
106
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
107
- * 'value',
108
- * 'id',
109
- * ); // => { 10: 3, 20: 2 }
110
- * ```
111
- */
112
- export function toRecord<
113
- Item extends PlainObject,
114
- ItemKey extends keyof Item,
115
- ItemValue extends keyof Item,
116
- >(
117
- array: Item[],
118
- key: ItemKey,
119
- value: ItemValue,
120
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
121
-
122
- /**
123
- * Create a record from an array of items using a callback
124
- *
125
- * If multiple items have the same key, the latest item will be used
126
- *
127
- * @param array Array to convert
128
- * @param callback Callback to get an item's grouping key
129
- * @returns Record of keyed values
130
- *
131
- * @example
132
- * ```typescript
133
- * toRecord(
134
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
135
- * item => item.value,
136
- * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
137
- * ```
138
- */
139
- export function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
140
- array: Item[],
141
- callback: Callback,
142
- ): Record<ReturnType<Callback>, Item>;
143
-
144
- /**
145
- * Create a record from an array of items using a key
146
- *
147
- * If multiple items have the same key, the latest item will be used
148
- *
149
- * @param array Array to convert
150
- * @param key Key to use for grouping
151
- * @returns Record of keyed values
152
- *
153
- * @example
154
- * ```typescript
155
- * toRecord(
156
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
157
- * 'value',
158
- * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
159
- * ```
160
- */
161
- export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
162
- array: Item[],
163
- key: ItemKey,
164
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
165
-
166
- /**
167
- * Create a record from an array of items _(using indices as keys)_
168
- *
169
- * @param array Array to convert
170
- * @returns Record of indiced values
171
- *
172
- * @example
173
- * ```typescript
174
- * toRecord(
175
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
176
- * ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} }
177
- * ```
178
- */
179
- export function toRecord<Item>(array: Item[]): Record<number, Item>;
180
-
181
- export function toRecord(array: unknown[], first?: unknown, second?: unknown): unknown {
182
- return groupValues(array, first, second, false);
183
- }
184
-
185
- toRecord.arrays = toRecordArrays;
186
-
187
- /**
188
- * Create a record from an array of items using callbacks, grouping values into arrays
189
- *
190
- * _Available as `toRecordArrays` and `toRecord.arrays`_
191
- *
192
- * @param array Array to convert
193
- * @param key Callback to get an item's grouping key
194
- * @param value Callback to get an item's value
195
- * @returns Record of keyed arrays of values
196
- *
197
- * @example
198
- * ```typescript
199
- * toRecordArrays(
200
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
201
- * item => item.value,
202
- * item => item.id,
203
- * ); // => { 10: [1, 3], 20: [2] }
204
- * ```
205
- */
206
- export function toRecordArrays<
207
- Item,
208
- KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
209
- ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
210
- >(
211
- array: Item[],
212
- key: KeyCallback,
213
- value: ValueCallback,
214
- ): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
215
-
216
- /**
217
- * Create a record from an array of items using a callback and value, grouping values into arrays
218
- *
219
- * _Available as `toRecordArrays` and `toRecord.arrays`_
220
- *
221
- * @param array Array to convert
222
- * @param callback Callback to get an item's grouping key
223
- * @param value Key to use for value
224
- * @returns Record of keyed arrays of values
225
- *
226
- * @example
227
- * ```typescript
228
- * toRecordArrays(
229
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
230
- * item => item.value,
231
- * 'id',
232
- * ); // => { 10: [1, 3], 20: [2] }
233
- * ```
234
- */
235
- export function toRecordArrays<
236
- Item extends PlainObject,
237
- Callback extends (item: Item, index: number, array: Item[]) => Key,
238
- ItemValue extends keyof Item,
239
- >(
240
- array: Item[],
241
- callback: Callback,
242
- value: ItemValue,
243
- ): Record<ReturnType<Callback>, Item[ItemValue][]>;
244
-
245
- /**
246
- * Create a record from an array of items using a key and callback, grouping values into arrays
247
- *
248
- * _Available as `toRecordArrays` and `toRecord.arrays`_
249
- *
250
- * @param array Array to convert
251
- * @param key Key to use for grouping
252
- * @param callback Callback to get an item's value
253
- * @returns Record of keyed arrays of values
254
- *
255
- * @example
256
- * ```typescript
257
- * toRecordArrays(
258
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
259
- * 'value',
260
- * item => item.id,
261
- * ); // => { 10: [1, 3], 20: [2] }
262
- * ```
263
- */
264
- export function toRecordArrays<
265
- Item extends PlainObject,
266
- ItemKey extends keyof Item,
267
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
268
- >(
269
- array: Item[],
270
- key: ItemKey,
271
- callback: Callback,
272
- ): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback>[]>>;
273
-
274
- /**
275
- * Create a record from an array of items using a key and value, grouping values into arrays
276
- *
277
- * _Available as `toRecordArrays` and `toRecord.arrays`_
278
- *
279
- * @param array Array to convert
280
- * @param key Key to use for grouping
281
- * @param value Key to use for value
282
- * @returns Record of keyed arrays of values
283
- *
284
- * @example
285
- * ```typescript
286
- * toRecordArrays(
287
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
288
- * 'value',
289
- * 'id',
290
- * ); // => { 10: [1, 3], 20: [2] }
291
- * ```
292
- */
293
- export function toRecordArrays<
294
- Item extends PlainObject,
295
- ItemKey extends keyof Item,
296
- ItemValue extends keyof Item,
297
- >(
298
- array: Item[],
299
- key: ItemKey,
300
- value: ItemValue,
301
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
302
-
303
- /**
304
- * Create a record from an array of items using a callback, grouping items into arrays
305
- *
306
- * _Available as `toRecordArrays` and `toRecord.arrays`_
307
- *
308
- * @param array Array to convert
309
- * @param callback Callback to get an item's grouping key
310
- * @returns Record of keyed arrays of items
311
- *
312
- * @example
313
- * ```typescript
314
- * toRecordArrays(
315
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
316
- * item => item.value,
317
- * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
318
- * ```
319
- */
320
- export function toRecordArrays<
321
- Item,
322
- Callback extends (item: Item, index: number, array: Item[]) => Key,
323
- >(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
324
-
325
- /**
326
- * Create a record from an array of items using a key, grouping items into arrays
327
- *
328
- * _Available as `toRecordArrays` and `toRecord.arrays`_
329
- *
330
- * @param array Array to convert
331
- * @param key Key to use for grouping
332
- * @returns Record of keyed arrays of items
333
- *
334
- * @example
335
- * ```typescript
336
- * toRecordArrays(
337
- * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
338
- * 'value',
339
- * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
340
- * ```
341
- */
342
- export function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item>(
343
- array: Item[],
344
- key: ItemKey,
345
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
346
-
347
- export function toRecordArrays(array: unknown[], first?: unknown, second?: unknown): unknown {
348
- return groupValues(array, first, second, true);
349
- }
350
-
351
- // #endregion
@@ -1,80 +0,0 @@
1
- import {getArrayCallbacks} from '../internal/array/callbacks';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Create a _Set_ from an array of items using a callback
8
- *
9
- * @param array Array to convert
10
- * @param callback Callback to get an item's value
11
- * @returns _Set_ of values
12
- *
13
- * @example
14
- * ```typescript
15
- * toSet(
16
- * [{id: 1}, {id: 2}, {id: 3}],
17
- * item => item.id,
18
- * ); // => Set { 1, 2, 3 }
19
- * ```
20
- */
21
- export function toSet<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
22
- array: Item[],
23
- callback: Callback,
24
- ): Set<ReturnType<Callback>>;
25
-
26
- /**
27
- * Create a _Set_ from an array of items using a key
28
- *
29
- * @param array Array to convert
30
- * @param key Key to use for value
31
- * @returns _Set_ of values
32
- *
33
- * @example
34
- * ```typescript
35
- * toSet(
36
- * [{id: 1}, {id: 2}, {id: 3}],
37
- * 'id',
38
- * ); // => Set { 1, 2, 3 }
39
- * ```
40
- */
41
- export function toSet<Item extends PlainObject, ItemKey extends keyof Item>(
42
- array: Item[],
43
- key: ItemKey,
44
- ): Set<Item[ItemKey]>;
45
-
46
- /**
47
- * Create a _Set_ from an array of items
48
- *
49
- * @param array Array to convert
50
- * @returns _Set_ of items
51
- *
52
- * @example
53
- * ```typescript
54
- * toSet([1, 2, 3]); // => Set { 1, 2, 3 }
55
- * ```
56
- */
57
- export function toSet<Item>(array: Item[]): Set<Item>;
58
-
59
- export function toSet(array: unknown[], value?: unknown): Set<unknown> {
60
- if (!Array.isArray(array)) {
61
- return new Set();
62
- }
63
-
64
- const callbacks = getArrayCallbacks(undefined, undefined, value);
65
-
66
- if (callbacks?.value == null) {
67
- return new Set(array);
68
- }
69
-
70
- const {length} = array;
71
- const set = new Set<unknown>();
72
-
73
- for (let index = 0; index < length; index += 1) {
74
- set.add(callbacks.value(array[index], index, array));
75
- }
76
-
77
- return set;
78
- }
79
-
80
- // #endregion
@@ -1,79 +0,0 @@
1
- import {updateInArray} from '../internal/array/update';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Toggle an item in an array
8
- *
9
- * If the item exists, it will be removed; if it doesn't, it will be added
10
- *
11
- * @param destination Array to toggle within
12
- * @param toggled Toggled items
13
- * @param callback Callback to find existing item
14
- * @returns Original array
15
- *
16
- * @example
17
- * ```typescript
18
- * toggle(
19
- * [{id: 1}, {id: 2}, {id: 3}],
20
- * [{id: 2}, {id: 4}],
21
- * item => item.id,
22
- * ); // => [{id: 1}, {id: 3}, {id: 4}]
23
- * ```
24
- */
25
- export function toggle<Item>(
26
- destination: Item[],
27
- toggled: Item[],
28
- callback: (item: Item, index: number, array: Item[]) => unknown,
29
- ): Item[];
30
-
31
- /**
32
- * Toggle an item in an array
33
- *
34
- * If the item exists, it will be removed; if it doesn't, it will be added
35
- *
36
- * @param destination Array to toggle within
37
- * @param toggled Toggled items
38
- * @param key Key to find existing item
39
- * @returns Original array
40
- *
41
- * @example
42
- * ```typescript
43
- * toggle(
44
- * [{id: 1}, {id: 2}, {id: 3}],
45
- * [{id: 2}, {id: 4}],
46
- * 'id',
47
- * ); // => [{id: 1}, {id: 3}, {id: 4}]
48
- * ```
49
- */
50
- export function toggle<Item extends PlainObject, ItemKey extends keyof Item>(
51
- destination: Item[],
52
- toggled: Item[],
53
- key: ItemKey,
54
- ): Item[];
55
-
56
- /**
57
- * Toggle an item in an array
58
- *
59
- * If the item exists, it will be removed; if it doesn't, it will be added
60
- *
61
- * @param destination Array to toggle within
62
- * @param toggled Toggled items
63
- * @returns Original array
64
- *
65
- * @example
66
- * ```typescript
67
- * toggle(
68
- * [1, 2, 3],
69
- * [2, 4],
70
- * ); // => [1, 3, 4]
71
- * ```
72
- */
73
- export function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
74
-
75
- export function toggle(array: unknown[], values: unknown[], key?: unknown): unknown[] {
76
- return updateInArray(array, values, key, false);
77
- }
78
-
79
- // #endregion
@@ -1,72 +0,0 @@
1
- import {COMPARE_SETS_UNION, compareSets} from '../internal/array/sets';
2
-
3
- // #region Functions
4
-
5
- /**
6
- * Get the combined, unique values from two arrays
7
- *
8
- * @param first First array
9
- * @param second Second array
10
- * @param callback Callback to get an item's value for comparison
11
- * @returns Combined, unique values from both arrays
12
- *
13
- * @example
14
- * ```typescript
15
- * union(
16
- * [{id: 1}, {id: 2}, {id: 3}],
17
- * [{id: 2}, {id: 4}],
18
- * item => item.id,
19
- * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
20
- * ```
21
- */
22
- export function union<First, Second>(
23
- first: First[],
24
- second: Second[],
25
- callback: (item: First | Second) => unknown,
26
- ): (First | Second)[];
27
-
28
- /**
29
- * Get the combined, unique values from two arrays
30
- *
31
- * @param first First array
32
- * @param second Second array
33
- * @param key Key to get an item's value for comparison
34
- * @returns Combined, unique values from both arrays
35
- *
36
- * @example
37
- * ```typescript
38
- * union(
39
- * [{id: 1}, {id: 2}, {id: 3}],
40
- * [{id: 2}, {id: 4}],
41
- * 'id',
42
- * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
43
- * ```
44
- */
45
- export function union<
46
- First extends Record<string, unknown>,
47
- Second extends Record<string, unknown>,
48
- SharedKey extends keyof First & keyof Second,
49
- >(first: First[], second: Second[], key: SharedKey): (First | Second)[];
50
-
51
- /**
52
- * Get the combined, unique values from two arrays
53
- *
54
- * @param first First array
55
- * @param second Second array
56
- * @returns Combined, unique values from both arrays
57
- *
58
- * @example
59
- * ```typescript
60
- * union(
61
- * [1, 2, 3],
62
- * [2, 4],
63
- * ); // => [1, 2, 3, 4]
64
- * ```
65
- */
66
- export function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
67
-
68
- export function union(first: unknown[], second: unknown[], key?: unknown): unknown[] {
69
- return compareSets(COMPARE_SETS_UNION, first, second, key);
70
- }
71
-
72
- // #endregion
@@ -1,67 +0,0 @@
1
- import {FIND_VALUES_UNIQUE, findValues} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get an array of unique items
8
- *
9
- * @param array Original array
10
- * @param callback Callback to get an item's value
11
- * @returns Array of unique items
12
- *
13
- * @example
14
- * ```typescript
15
- * unique(
16
- * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
17
- * item => item.id,
18
- * ); // => [{id: 1}, {id: 2}, {id: 3}]
19
- * ```
20
- */
21
- export function unique<Item>(
22
- array: Item[],
23
- callback: (item: Item, index: number, array: Item[]) => unknown,
24
- ): Item[];
25
-
26
- /**
27
- * Get an array of unique items
28
- *
29
- * @param array Original array
30
- * @param key Key to use for unique value
31
- * @returns Array of unique items
32
- *
33
- * @example
34
- * ```typescript
35
- * unique(
36
- * [{id: 1}, {id: 2}, {id: 3}, {id: 2}],
37
- * 'id',
38
- * ); // => [{id: 1}, {id: 2}, {id: 3}]
39
- * ```
40
- */
41
- export function unique<Item extends PlainObject, ItemKey extends keyof Item>(
42
- array: Item[],
43
- key: ItemKey,
44
- ): Item[];
45
-
46
- /**
47
- * Get an array of unique items
48
- *
49
- * @param array Original array
50
- * @returns Array of unique items
51
- *
52
- * @example
53
- * ```typescript
54
- * unique([1, 2, 3, 2]); // => [1, 2, 3]
55
- * ```
56
- */
57
- export function unique<Item>(array: Item[]): Item[];
58
-
59
- export function unique(array: unknown[], key?: unknown): unknown[] {
60
- if (!Array.isArray(array)) {
61
- return [];
62
- }
63
-
64
- return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, undefined]).matched : array;
65
- }
66
-
67
- // #endregion