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