@oscarpalmer/atoms 0.184.2 → 0.186.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.
- package/dist/array/difference.d.mts +29 -0
- package/dist/array/exists.d.mts +35 -0
- package/dist/array/filter.d.mts +72 -2
- package/dist/array/find.d.mts +70 -0
- package/dist/array/first.d.mts +77 -2
- package/dist/array/flatten.d.mts +6 -0
- package/dist/array/flatten.mjs +6 -0
- package/dist/array/from.d.mts +36 -0
- package/dist/array/get.d.mts +21 -13
- package/dist/array/group-by.d.mts +142 -0
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/{position.d.mts → match.d.mts} +168 -36
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +11 -1
- package/dist/array/partition.d.mts +35 -0
- package/dist/array/push.d.mts +8 -0
- package/dist/array/push.mjs +8 -0
- package/dist/array/reverse.d.mts +1 -0
- package/dist/array/reverse.mjs +1 -0
- package/dist/array/select.d.mts +94 -8
- package/dist/array/single.d.mts +29 -0
- package/dist/array/slice.d.mts +106 -16
- package/dist/array/sort.d.mts +30 -4
- package/dist/array/sort.mjs +1 -1
- package/dist/array/splice.d.mts +48 -0
- package/dist/array/splice.mjs +2 -1
- package/dist/array/swap.d.mts +113 -8
- package/dist/array/swap.mjs +2 -1
- package/dist/array/to-map.d.mts +124 -0
- package/dist/array/to-record.d.mts +124 -0
- package/dist/array/to-set.d.mts +24 -0
- package/dist/array/toggle.d.mts +38 -3
- package/dist/array/union.d.mts +29 -0
- package/dist/array/unique.d.mts +24 -0
- package/dist/array/update.d.mts +38 -3
- package/dist/beacon.d.mts +12 -0
- package/dist/beacon.mjs +9 -0
- package/dist/color/instance.d.mts +8 -0
- package/dist/color/instance.mjs +3 -0
- package/dist/color/models.d.mts +30 -0
- package/dist/function/assert.d.mts +29 -8
- package/dist/function/assert.mjs +29 -8
- package/dist/function/memoize.d.mts +3 -0
- package/dist/function/memoize.mjs +3 -0
- package/dist/function/retry.d.mts +3 -0
- package/dist/function/retry.mjs +3 -0
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +2158 -288
- package/dist/index.mjs +294 -181
- package/dist/internal/array/chunk.d.mts +6 -0
- package/dist/internal/array/chunk.mjs +6 -0
- package/dist/internal/array/compact.d.mts +12 -0
- package/dist/internal/array/index-of.d.mts +70 -0
- package/dist/internal/math/aggregate.d.mts +29 -0
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/get.d.mts +27 -5
- package/dist/internal/value/has.d.mts +7 -7
- package/dist/internal/value/has.mjs +1 -1
- package/dist/internal/value/misc.d.mts +2 -2
- package/dist/internal/value/misc.mjs +10 -4
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +11 -0
- package/dist/models.d.mts +14 -1
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.d.mts +0 -6
- package/dist/promise/models.d.mts +36 -0
- package/dist/promise/models.mjs +6 -0
- package/dist/queue.d.mts +13 -1
- package/dist/queue.mjs +9 -0
- package/dist/result/index.d.mts +0 -8
- package/dist/result/index.mjs +0 -8
- package/dist/result/match.d.mts +4 -4
- package/dist/result/work/flow.d.mts +12 -36
- package/dist/result/work/pipe.d.mts +11 -33
- package/dist/sized/set.d.mts +3 -2
- package/dist/sized/set.mjs +3 -2
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +10 -1
- package/dist/value/unsmush.d.mts +2 -3
- package/package.json +5 -5
- package/src/array/difference.ts +33 -0
- package/src/array/exists.ts +35 -0
- package/src/array/filter.ts +72 -2
- package/src/array/find.ts +70 -0
- package/src/array/first.ts +77 -3
- package/src/array/flatten.ts +6 -0
- package/src/array/from.ts +40 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/index.ts +1 -1
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +33 -0
- package/src/array/last.ts +75 -2
- package/src/array/{position.ts → match.ts} +197 -65
- package/src/array/move.ts +87 -13
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +96 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +30 -4
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +122 -13
- package/src/array/to-map.ts +124 -0
- package/src/array/to-record.ts +124 -0
- package/src/array/to-set.ts +24 -0
- package/src/array/toggle.ts +42 -3
- package/src/array/union.ts +33 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +9 -1
- package/src/color/models.ts +30 -0
- package/src/function/assert.ts +66 -7
- package/src/function/memoize.ts +3 -0
- package/src/function/once.ts +5 -1
- package/src/function/retry.ts +3 -0
- package/src/internal/array/chunk.ts +6 -0
- package/src/internal/array/compact.ts +12 -0
- package/src/internal/array/index-of.ts +70 -0
- package/src/internal/math/aggregate.ts +29 -0
- package/src/internal/string.ts +0 -2
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +5 -0
- package/src/internal/value/get.ts +27 -5
- package/src/internal/value/has.ts +10 -10
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +18 -0
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +13 -1
- package/src/result/index.ts +0 -8
- package/src/result/match.ts +4 -4
- package/src/result/work/flow.ts +12 -36
- package/src/result/work/pipe.ts +11 -33
- package/src/sized/set.ts +4 -3
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +10 -1
- package/src/value/unsmush.ts +2 -8
package/src/array/group-by.ts
CHANGED
|
@@ -7,10 +7,20 @@ import type {Key, KeyedValue, PlainObject, Simplify} from '../models';
|
|
|
7
7
|
* Create a record from an array of items using a specific key and value
|
|
8
8
|
*
|
|
9
9
|
* If multiple items have the same key, the latest item's value will be used
|
|
10
|
+
*
|
|
10
11
|
* @param array Array to group
|
|
11
12
|
* @param key Callback to get an item's grouping key
|
|
12
13
|
* @param value Callback to get an item's value
|
|
13
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
|
+
* ```
|
|
14
24
|
*/
|
|
15
25
|
export function groupBy<
|
|
16
26
|
Item,
|
|
@@ -26,10 +36,20 @@ export function groupBy<
|
|
|
26
36
|
* Create a record from an array of items using a specific key and value
|
|
27
37
|
*
|
|
28
38
|
* If multiple items have the same key, the latest item's value will be used
|
|
39
|
+
*
|
|
29
40
|
* @param array Array to group
|
|
30
41
|
* @param key Callback to get an item's grouping key
|
|
31
42
|
* @param value Key to use for value
|
|
32
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
|
+
* ```
|
|
33
53
|
*/
|
|
34
54
|
export function groupBy<
|
|
35
55
|
Item extends PlainObject,
|
|
@@ -45,10 +65,20 @@ export function groupBy<
|
|
|
45
65
|
* Create a record from an array of items using a specific key and value
|
|
46
66
|
*
|
|
47
67
|
* If multiple items have the same key, the latest item's value will be used
|
|
68
|
+
*
|
|
48
69
|
* @param array Array to group
|
|
49
70
|
* @param key Key to use for grouping
|
|
50
71
|
* @param value Callback to get an item's value
|
|
51
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
|
+
* ```
|
|
52
82
|
*/
|
|
53
83
|
export function groupBy<
|
|
54
84
|
Item extends PlainObject,
|
|
@@ -64,10 +94,20 @@ export function groupBy<
|
|
|
64
94
|
* Create a record from an array of items using a specific key and value
|
|
65
95
|
*
|
|
66
96
|
* If multiple items have the same key, the latest item's value will be used
|
|
97
|
+
*
|
|
67
98
|
* @param array Array to group
|
|
68
99
|
* @param key Key to use for grouping
|
|
69
100
|
* @param value Key to use for value
|
|
70
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
|
+
* ```
|
|
71
111
|
*/
|
|
72
112
|
export function groupBy<
|
|
73
113
|
Item extends PlainObject,
|
|
@@ -83,9 +123,18 @@ export function groupBy<
|
|
|
83
123
|
* Create a record from an array of items using a specific key
|
|
84
124
|
*
|
|
85
125
|
* If multiple items have the same key, the latest item will be used
|
|
126
|
+
*
|
|
86
127
|
* @param array Array to group
|
|
87
128
|
* @param callback Callback to get an item's grouping key
|
|
88
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
|
+
* ```
|
|
89
138
|
*/
|
|
90
139
|
export function groupBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
91
140
|
array: Item[],
|
|
@@ -96,9 +145,18 @@ export function groupBy<Item, Callback extends (item: Item, index: number, array
|
|
|
96
145
|
* Create a record from an array of items using a specific key
|
|
97
146
|
*
|
|
98
147
|
* If multiple items have the same key, the latest item will be used
|
|
148
|
+
*
|
|
99
149
|
* @param array Array to group
|
|
100
150
|
* @param key Key to use for grouping
|
|
101
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
|
+
* ```
|
|
102
160
|
*/
|
|
103
161
|
export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
104
162
|
array: Item[],
|
|
@@ -107,8 +165,16 @@ export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
107
165
|
|
|
108
166
|
/**
|
|
109
167
|
* Create a record from an array of items _(using indices as keys)_
|
|
168
|
+
*
|
|
110
169
|
* @param array Array to group
|
|
111
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
|
+
* ```
|
|
112
178
|
*/
|
|
113
179
|
export function groupBy<Item>(array: Item[]): Record<number, Item>;
|
|
114
180
|
|
|
@@ -122,10 +188,23 @@ groupBy.arrays = groupArraysBy;
|
|
|
122
188
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
123
189
|
*
|
|
124
190
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
191
|
+
*
|
|
125
192
|
* @param array Array to group
|
|
126
193
|
* @param key Callback to get an item's grouping key
|
|
127
194
|
* @param value Callback to get an item's value
|
|
128
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
|
+
* ```
|
|
129
208
|
*/
|
|
130
209
|
export function groupArraysBy<
|
|
131
210
|
Item,
|
|
@@ -141,10 +220,23 @@ export function groupArraysBy<
|
|
|
141
220
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
142
221
|
*
|
|
143
222
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
223
|
+
*
|
|
144
224
|
* @param array Array to group
|
|
145
225
|
* @param key Callback to get an item's grouping key
|
|
146
226
|
* @param value Key to use for value
|
|
147
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
|
+
* ```
|
|
148
240
|
*/
|
|
149
241
|
export function groupArraysBy<
|
|
150
242
|
Item extends PlainObject,
|
|
@@ -160,10 +252,23 @@ export function groupArraysBy<
|
|
|
160
252
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
161
253
|
*
|
|
162
254
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
255
|
+
*
|
|
163
256
|
* @param array Array to group
|
|
164
257
|
* @param key Key to use for grouping
|
|
165
258
|
* @param value Callback to get an item's value
|
|
166
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
|
+
* ```
|
|
167
272
|
*/
|
|
168
273
|
export function groupArraysBy<
|
|
169
274
|
Item extends PlainObject,
|
|
@@ -179,10 +284,23 @@ export function groupArraysBy<
|
|
|
179
284
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
180
285
|
*
|
|
181
286
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
287
|
+
*
|
|
182
288
|
* @param array Array to group
|
|
183
289
|
* @param key Key to use for grouping
|
|
184
290
|
* @param value Key to use for value
|
|
185
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
|
+
* ```
|
|
186
304
|
*/
|
|
187
305
|
export function groupArraysBy<
|
|
188
306
|
Item extends PlainObject,
|
|
@@ -198,9 +316,21 @@ export function groupArraysBy<
|
|
|
198
316
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
199
317
|
*
|
|
200
318
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
319
|
+
*
|
|
201
320
|
* @param array Array to group
|
|
202
321
|
* @param callback Callback to get an item's grouping key
|
|
203
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
|
+
* ```
|
|
204
334
|
*/
|
|
205
335
|
export function groupArraysBy<
|
|
206
336
|
Item,
|
|
@@ -211,9 +341,21 @@ export function groupArraysBy<
|
|
|
211
341
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
212
342
|
*
|
|
213
343
|
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
344
|
+
*
|
|
214
345
|
* @param array Array to group
|
|
215
346
|
* @param key Key to use for grouping
|
|
216
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
|
+
* ```
|
|
217
359
|
*/
|
|
218
360
|
export function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
219
361
|
array: Item[],
|
package/src/array/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export * from './get';
|
|
|
12
12
|
export * from './insert';
|
|
13
13
|
export * from './intersection';
|
|
14
14
|
export * from './partition';
|
|
15
|
-
export * from './
|
|
15
|
+
export * from './match';
|
|
16
16
|
export * from './push';
|
|
17
17
|
export * from './reverse';
|
|
18
18
|
export * from './select';
|
package/src/array/insert.ts
CHANGED
|
@@ -2,22 +2,36 @@ import {INSERT_TYPE_INSERT, insertValues} from '../internal/array/insert';
|
|
|
2
2
|
|
|
3
3
|
// #region Functions
|
|
4
4
|
|
|
5
|
-
// Uses chunking to avoid call stack size being exceeded
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* Insert items into an array at a specified index
|
|
7
|
+
*
|
|
8
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
9
|
+
*
|
|
9
10
|
* @param array Original array
|
|
10
11
|
* @param index Index to insert at
|
|
11
12
|
* @param items Inserted items
|
|
12
13
|
* @returns Updated array
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* insert([1, 2, 3], 1, [4, 5]); // => [1, 4, 5, 2, 3]
|
|
18
|
+
* ```
|
|
13
19
|
*/
|
|
14
20
|
export function insert<Item>(array: Item[], index: number, items: Item[]): Item[];
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* Insert items into an array _(at the end)_
|
|
24
|
+
*
|
|
25
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
26
|
+
*
|
|
18
27
|
* @param array Original array
|
|
19
28
|
* @param items Inserted items
|
|
20
29
|
* @returns Updated array
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* insert([1, 2, 3], [4, 5]); // => [1, 2, 3, 4, 5]
|
|
34
|
+
* ```
|
|
21
35
|
*/
|
|
22
36
|
export function insert<Item>(array: Item[], items: Item[]): Item[];
|
|
23
37
|
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import {COMPARE_SETS_INTERSECTION, compareSets} from '../internal/array/sets';
|
|
2
2
|
|
|
3
|
+
// #region Functions
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Get the common values between two arrays
|
|
7
|
+
*
|
|
5
8
|
* @param first First array
|
|
6
9
|
* @param second Second array
|
|
7
10
|
* @param callback Callback to get an item's value for comparison
|
|
8
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
|
+
* ```
|
|
9
21
|
*/
|
|
10
22
|
export function intersection<First, Second>(
|
|
11
23
|
first: First[],
|
|
@@ -15,10 +27,20 @@ export function intersection<First, Second>(
|
|
|
15
27
|
|
|
16
28
|
/**
|
|
17
29
|
* Get the common values between two arrays
|
|
30
|
+
*
|
|
18
31
|
* @param first First array
|
|
19
32
|
* @param second Second array
|
|
20
33
|
* @param key Key to get an item's value for comparison
|
|
21
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
|
+
* ```
|
|
22
44
|
*/
|
|
23
45
|
export function intersection<
|
|
24
46
|
First extends Record<string, unknown>,
|
|
@@ -28,12 +50,23 @@ export function intersection<
|
|
|
28
50
|
|
|
29
51
|
/**
|
|
30
52
|
* Get the common values between two arrays
|
|
53
|
+
*
|
|
31
54
|
* @param first First array
|
|
32
55
|
* @param second Second array
|
|
33
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
|
+
* ```
|
|
34
65
|
*/
|
|
35
66
|
export function intersection<First, Second>(first: First[], second: Second[]): First[];
|
|
36
67
|
|
|
37
68
|
export function intersection(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
38
69
|
return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
|
|
39
70
|
}
|
|
71
|
+
|
|
72
|
+
// #endregion
|
package/src/array/last.ts
CHANGED
|
@@ -5,10 +5,20 @@ import type {PlainObject} from '../models';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Get the last items matching the given value
|
|
8
|
+
*
|
|
8
9
|
* @param array Array to search in
|
|
9
10
|
* @param callback Callback to get an item's value for matching
|
|
10
11
|
* @param value Value to match against
|
|
11
12
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* last(
|
|
17
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
18
|
+
* item => item.value,
|
|
19
|
+
* 10,
|
|
20
|
+
* ); // => {id: 3, value: 10}
|
|
21
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
export function last<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(
|
|
14
24
|
array: Item[],
|
|
@@ -18,10 +28,20 @@ export function last<Item, Callback extends (item: Item, index: number, array: I
|
|
|
18
28
|
|
|
19
29
|
/**
|
|
20
30
|
* Get the first item matching the given value by key
|
|
31
|
+
*
|
|
21
32
|
* @param array Array to search in
|
|
22
33
|
* @param key Key to get an item's value for matching
|
|
23
34
|
* @param value Value to match against
|
|
24
35
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* last(
|
|
40
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
41
|
+
* 'value',
|
|
42
|
+
* 10,
|
|
43
|
+
* ); // => {id: 3, value: 10}
|
|
44
|
+
* ```
|
|
25
45
|
*/
|
|
26
46
|
export function last<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
27
47
|
array: Item[],
|
|
@@ -31,9 +51,18 @@ export function last<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
31
51
|
|
|
32
52
|
/**
|
|
33
53
|
* Get the last item matching the filter
|
|
54
|
+
*
|
|
34
55
|
* @param array Array to search in
|
|
35
56
|
* @param filter Filter callback to match items
|
|
36
57
|
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* last(
|
|
62
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
63
|
+
* item => item.value === 10,
|
|
64
|
+
* ); // => {id: 3, value: 10}
|
|
65
|
+
* ```
|
|
37
66
|
*/
|
|
38
67
|
export function last<Item>(
|
|
39
68
|
array: Item[],
|
|
@@ -42,8 +71,14 @@ export function last<Item>(
|
|
|
42
71
|
|
|
43
72
|
/**
|
|
44
73
|
* Get the last item from an array
|
|
74
|
+
*
|
|
45
75
|
* @param array Array to get from
|
|
46
|
-
* @
|
|
76
|
+
* @returns Last item from the array, or `undefined` if the array is empty
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* last([1, 2, 3]); // => 3
|
|
81
|
+
* ```
|
|
47
82
|
*/
|
|
48
83
|
export function last<Item>(array: Item[]): Item | undefined;
|
|
49
84
|
|
|
@@ -57,11 +92,22 @@ last.default = lastOrDefault;
|
|
|
57
92
|
* Get the last item matching the given value
|
|
58
93
|
*
|
|
59
94
|
* Available as `lastOrDefault` and `last.default`
|
|
95
|
+
*
|
|
60
96
|
* @param array Array to search in
|
|
61
97
|
* @param defaultValue Default value to return if no match is found
|
|
62
98
|
* @param callback Callback to get an item's value for matching
|
|
63
99
|
* @param value Value to match against
|
|
64
100
|
* @returns Last item that matches the value, or the default value if no match is found
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* lastOrDefault(
|
|
105
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
106
|
+
* {id: -1, value: 30},
|
|
107
|
+
* item => item.value,
|
|
108
|
+
* 30,
|
|
109
|
+
* ); // => {id: -1, value: 30}
|
|
110
|
+
* ```
|
|
65
111
|
*/
|
|
66
112
|
export function lastOrDefault<
|
|
67
113
|
Item,
|
|
@@ -72,11 +118,22 @@ export function lastOrDefault<
|
|
|
72
118
|
* Get the last item matching the given value by key
|
|
73
119
|
*
|
|
74
120
|
* Available as `lastOrDefault` and `last.default`
|
|
121
|
+
*
|
|
75
122
|
* @param array Array to search in
|
|
76
123
|
* @param defaultValue Default value to return if no match is found
|
|
77
124
|
* @param key Key to get an item's value for matching
|
|
78
125
|
* @param value Value to match against
|
|
79
126
|
* @returns Last item that matches the value, or the default value if no match is found
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* lastOrDefault(
|
|
131
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
132
|
+
* {id: -1, value: 30},
|
|
133
|
+
* 'value',
|
|
134
|
+
* 30,
|
|
135
|
+
* ); // => {id: -1, value: 30}
|
|
136
|
+
* ```
|
|
80
137
|
*/
|
|
81
138
|
export function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
82
139
|
array: Item[],
|
|
@@ -89,10 +146,20 @@ export function lastOrDefault<Item extends PlainObject, ItemKey extends keyof It
|
|
|
89
146
|
* Get the last item matching the filter
|
|
90
147
|
*
|
|
91
148
|
* Available as `lastOrDefault` and `last.default`
|
|
149
|
+
*
|
|
92
150
|
* @param array Array to search in
|
|
93
151
|
* @param defaultValue Default value to return if no match is found
|
|
94
152
|
* @param filter Filter callback to match items
|
|
95
153
|
* @returns Last item that matches the filter, or the default value if no match is found
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* lastOrDefault(
|
|
158
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
159
|
+
* {id: -1, value: 30},
|
|
160
|
+
* item => item.value === 30,
|
|
161
|
+
* ); // => {id: -1, value: 30}
|
|
162
|
+
* ```
|
|
96
163
|
*/
|
|
97
164
|
export function lastOrDefault<Item>(
|
|
98
165
|
array: Item[],
|
|
@@ -104,9 +171,15 @@ export function lastOrDefault<Item>(
|
|
|
104
171
|
* Get the last item from an array
|
|
105
172
|
*
|
|
106
173
|
* Available as `lastOrDefault` and `last.default`
|
|
174
|
+
*
|
|
107
175
|
* @param array Array to get from
|
|
108
176
|
* @param defaultValue Default value to return if the array is empty
|
|
109
|
-
* @
|
|
177
|
+
* @returns Last item from the array, or the default value if the array is empty
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* lastOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
|
|
182
|
+
* ```
|
|
110
183
|
*/
|
|
111
184
|
export function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
112
185
|
|