@oscarpalmer/atoms 0.193.0 → 0.193.1

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 (126) hide show
  1. package/package.json +3 -4
  2. package/src/array/difference.ts +0 -73
  3. package/src/array/exists.ts +0 -93
  4. package/src/array/filter.ts +0 -182
  5. package/src/array/find.ts +0 -183
  6. package/src/array/first.ts +0 -196
  7. package/src/array/flatten.ts +0 -20
  8. package/src/array/from.ts +0 -129
  9. package/src/array/get.ts +0 -131
  10. package/src/array/group-by.ts +0 -369
  11. package/src/array/index.ts +0 -26
  12. package/src/array/insert.ts +0 -52
  13. package/src/array/intersection.ts +0 -72
  14. package/src/array/last.ts +0 -194
  15. package/src/array/match.ts +0 -436
  16. package/src/array/move.ts +0 -315
  17. package/src/array/partition.ts +0 -91
  18. package/src/array/push.ts +0 -23
  19. package/src/array/reverse.ts +0 -33
  20. package/src/array/select.ts +0 -260
  21. package/src/array/single.ts +0 -93
  22. package/src/array/slice.ts +0 -335
  23. package/src/array/sort.ts +0 -607
  24. package/src/array/splice.ts +0 -106
  25. package/src/array/swap.ts +0 -322
  26. package/src/array/to-map.ts +0 -371
  27. package/src/array/to-record.ts +0 -351
  28. package/src/array/to-set.ts +0 -80
  29. package/src/array/toggle.ts +0 -79
  30. package/src/array/union.ts +0 -72
  31. package/src/array/unique.ts +0 -67
  32. package/src/array/update.ts +0 -75
  33. package/src/beacon.ts +0 -378
  34. package/src/color/constants.ts +0 -137
  35. package/src/color/index.ts +0 -83
  36. package/src/color/instance.ts +0 -162
  37. package/src/color/misc/alpha.ts +0 -56
  38. package/src/color/misc/format.ts +0 -29
  39. package/src/color/misc/get.ts +0 -210
  40. package/src/color/misc/is.ts +0 -221
  41. package/src/color/misc/state.ts +0 -243
  42. package/src/color/models.ts +0 -389
  43. package/src/color/space/hex.ts +0 -184
  44. package/src/color/space/hsl.ts +0 -174
  45. package/src/color/space/hwb.ts +0 -153
  46. package/src/color/space/rgb.ts +0 -240
  47. package/src/function/assert.ts +0 -174
  48. package/src/function/index.ts +0 -2
  49. package/src/function/limit.ts +0 -83
  50. package/src/function/memoize.ts +0 -202
  51. package/src/function/once.ts +0 -200
  52. package/src/function/retry.ts +0 -175
  53. package/src/function/work.ts +0 -1007
  54. package/src/herald.ts +0 -216
  55. package/src/index.ts +0 -68
  56. package/src/internal/array/callbacks.ts +0 -46
  57. package/src/internal/array/chunk.ts +0 -51
  58. package/src/internal/array/compact.ts +0 -56
  59. package/src/internal/array/find.ts +0 -200
  60. package/src/internal/array/group.ts +0 -42
  61. package/src/internal/array/index-of.ts +0 -182
  62. package/src/internal/array/insert.ts +0 -80
  63. package/src/internal/array/overlap.ts +0 -35
  64. package/src/internal/array/sets.ts +0 -74
  65. package/src/internal/array/shuffle.ts +0 -33
  66. package/src/internal/array/update.ts +0 -52
  67. package/src/internal/function/misc.ts +0 -8
  68. package/src/internal/function/timer.ts +0 -168
  69. package/src/internal/is.ts +0 -244
  70. package/src/internal/math/aggregate.ts +0 -164
  71. package/src/internal/math/misc.ts +0 -28
  72. package/src/internal/number.ts +0 -129
  73. package/src/internal/random.ts +0 -49
  74. package/src/internal/result.ts +0 -92
  75. package/src/internal/sized.ts +0 -25
  76. package/src/internal/string.ts +0 -128
  77. package/src/internal/subscription.ts +0 -264
  78. package/src/internal/value/compare.ts +0 -170
  79. package/src/internal/value/equal.ts +0 -465
  80. package/src/internal/value/get.ts +0 -57
  81. package/src/internal/value/handlers.ts +0 -95
  82. package/src/internal/value/has.ts +0 -118
  83. package/src/internal/value/misc.ts +0 -125
  84. package/src/internal/value/partial.ts +0 -46
  85. package/src/internal/value/set.ts +0 -132
  86. package/src/is.ts +0 -182
  87. package/src/logger.ts +0 -230
  88. package/src/math.ts +0 -281
  89. package/src/models.ts +0 -286
  90. package/src/number.ts +0 -1
  91. package/src/promise/delay.ts +0 -62
  92. package/src/promise/helpers.ts +0 -96
  93. package/src/promise/index.ts +0 -300
  94. package/src/promise/misc.ts +0 -96
  95. package/src/promise/models.ts +0 -195
  96. package/src/promise/timed.ts +0 -91
  97. package/src/query.ts +0 -147
  98. package/src/queue.ts +0 -814
  99. package/src/random.ts +0 -125
  100. package/src/result/index.ts +0 -105
  101. package/src/result/match.ts +0 -124
  102. package/src/result/misc.ts +0 -129
  103. package/src/result/models.ts +0 -83
  104. package/src/result/work/flow.ts +0 -488
  105. package/src/result/work/pipe.ts +0 -496
  106. package/src/sized/map.ts +0 -110
  107. package/src/sized/set.ts +0 -107
  108. package/src/string/case.ts +0 -236
  109. package/src/string/fuzzy.ts +0 -444
  110. package/src/string/index.ts +0 -199
  111. package/src/string/match.ts +0 -80
  112. package/src/string/normalize.ts +0 -205
  113. package/src/string/template.ts +0 -161
  114. package/src/value/clone.ts +0 -319
  115. package/src/value/collection.ts +0 -63
  116. package/src/value/diff.ts +0 -232
  117. package/src/value/freeze.ts +0 -322
  118. package/src/value/handle.ts +0 -3
  119. package/src/value/index.ts +0 -5
  120. package/src/value/merge.ts +0 -278
  121. package/src/value/omit.ts +0 -20
  122. package/src/value/pick.ts +0 -20
  123. package/src/value/shake.ts +0 -45
  124. package/src/value/smush.ts +0 -89
  125. package/src/value/transform.ts +0 -153
  126. 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