@oscarpalmer/atoms 0.185.0 → 0.186.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.
- 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 +27 -7
- package/dist/array/group-by.d.mts +142 -0
- 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/match.d.mts +161 -32
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +10 -0
- 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 +21 -0
- 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 +1 -0
- 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/index.d.mts +1898 -129
- package/dist/index.mjs +64 -18
- 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/get.d.mts +25 -3
- package/dist/internal/value/has.d.mts +4 -4
- package/dist/models.d.mts +14 -1
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/transform.d.mts +1 -1
- package/dist/value/unsmush.d.mts +1 -5
- package/package.json +5 -5
- package/src/array/difference.ts +29 -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 +36 -0
- package/src/array/get.ts +27 -8
- package/src/array/group-by.ts +142 -0
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +29 -0
- package/src/array/last.ts +75 -2
- package/src/array/match.ts +171 -42
- package/src/array/move.ts +82 -12
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +1 -0
- package/src/array/select.ts +94 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +21 -0
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +117 -12
- 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 +38 -3
- package/src/array/union.ts +29 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- 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/get.ts +25 -3
- package/src/internal/value/has.ts +4 -4
- package/src/models.ts +18 -0
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/transform.ts +1 -1
- package/src/value/unsmush.ts +1 -10
package/dist/array/swap.d.mts
CHANGED
|
@@ -5,62 +5,166 @@ import { PlainObject } from "../models.mjs";
|
|
|
5
5
|
* Swap two smaller arrays within a larger array
|
|
6
6
|
*
|
|
7
7
|
* If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
|
|
8
|
+
*
|
|
8
9
|
* @param array Array of items to swap
|
|
9
10
|
* @param first First array
|
|
10
11
|
* @param second Second array
|
|
11
|
-
* @param
|
|
12
|
+
* @param callback Callback to get an item's value for matching
|
|
12
13
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* swap(
|
|
18
|
+
* [
|
|
19
|
+
* {id: 1, name: 'Alice'},
|
|
20
|
+
* {id: 2, name: 'Bob'},
|
|
21
|
+
* {id: 3, name: 'Charlie'},
|
|
22
|
+
* ],
|
|
23
|
+
* [
|
|
24
|
+
* {id: 2, name: 'Bob'},
|
|
25
|
+
* ],
|
|
26
|
+
* [
|
|
27
|
+
* {id: 3, name: 'Charlie'},
|
|
28
|
+
* ],
|
|
29
|
+
* item => item.id,
|
|
30
|
+
* ); // => [
|
|
31
|
+
* // {id: 1, name: 'Alice'},
|
|
32
|
+
* // {id: 3, name: 'Charlie'},
|
|
33
|
+
* // {id: 2, name: 'Bob'},
|
|
34
|
+
* // ]
|
|
35
|
+
* ```
|
|
13
36
|
*/
|
|
14
|
-
declare function swap<Item
|
|
37
|
+
declare function swap<Item>(array: Item[], first: Item[], second: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
15
38
|
/**
|
|
16
39
|
* Swap two smaller arrays within a larger array
|
|
17
40
|
*
|
|
18
41
|
* If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
|
|
42
|
+
*
|
|
19
43
|
* @param array Array of items to swap
|
|
20
44
|
* @param first First array
|
|
21
45
|
* @param second Second array
|
|
22
|
-
* @param
|
|
46
|
+
* @param key Key to get an item's value for matching
|
|
23
47
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* swap(
|
|
52
|
+
* [
|
|
53
|
+
* {id: 1, name: 'Alice'},
|
|
54
|
+
* {id: 2, name: 'Bob'},
|
|
55
|
+
* {id: 3, name: 'Charlie'},
|
|
56
|
+
* ],
|
|
57
|
+
* [
|
|
58
|
+
* {id: 2, name: 'Bob'},
|
|
59
|
+
* ],
|
|
60
|
+
* [
|
|
61
|
+
* {id: 3, name: 'Charlie'},
|
|
62
|
+
* ],
|
|
63
|
+
* 'id',
|
|
64
|
+
* ); // => [
|
|
65
|
+
* // {id: 1, name: 'Alice'},
|
|
66
|
+
* // {id: 3, name: 'Charlie'},
|
|
67
|
+
* // {id: 2, name: 'Bob'},
|
|
68
|
+
* // ]
|
|
69
|
+
* ```
|
|
24
70
|
*/
|
|
25
|
-
declare function swap<Item>(array: Item[], first: Item[], second: Item[],
|
|
71
|
+
declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item[], second: Item[], key: ItemKey): Item[];
|
|
26
72
|
/**
|
|
27
73
|
* Swap two smaller arrays within a larger array
|
|
28
74
|
*
|
|
29
75
|
* If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged
|
|
76
|
+
*
|
|
30
77
|
* @param array Array of items to swap
|
|
31
78
|
* @param first First array
|
|
32
79
|
* @param second Second array
|
|
33
80
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* swap(
|
|
85
|
+
* [1, 2, 3, 4, 5, 6],
|
|
86
|
+
* [1, 2],
|
|
87
|
+
* [5, 6],
|
|
88
|
+
* ); // => [5, 6, 3, 4, 1, 2]
|
|
89
|
+
* ```
|
|
34
90
|
*/
|
|
35
91
|
declare function swap<Item>(array: Item[], first: Item[], second: Item[]): Item[];
|
|
36
92
|
/**
|
|
37
93
|
* Swap two indiced items in an array
|
|
38
94
|
*
|
|
39
95
|
* If either of the items are not present in the array, the array will be returned unchanged
|
|
96
|
+
*
|
|
40
97
|
* @param array Array of items to swap
|
|
41
98
|
* @param first First item
|
|
42
99
|
* @param second Second item
|
|
43
|
-
* @param
|
|
100
|
+
* @param callback Callback to get an item's value for matching
|
|
44
101
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* swap(
|
|
106
|
+
* [
|
|
107
|
+
* {id: 1, name: 'Alice'},
|
|
108
|
+
* {id: 2, name: 'Bob'},
|
|
109
|
+
* {id: 3, name: 'Charlie'},
|
|
110
|
+
* ],
|
|
111
|
+
* {id: 2, name: 'Bob'},
|
|
112
|
+
* {id: 3, name: 'Charlie'},
|
|
113
|
+
* item => item.id,
|
|
114
|
+
* ); // => [
|
|
115
|
+
* // {id: 1, name: 'Alice'},
|
|
116
|
+
* // {id: 3, name: 'Charlie'},
|
|
117
|
+
* // {id: 2, name: 'Bob'},
|
|
118
|
+
* // ]
|
|
119
|
+
* ```
|
|
45
120
|
*/
|
|
46
|
-
declare function swap<Item
|
|
121
|
+
declare function swap<Item>(array: Item[], first: Item, second: Item, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
47
122
|
/**
|
|
48
123
|
* Swap two indiced items in an array
|
|
49
124
|
*
|
|
50
125
|
* If either of the items are not present in the array, the array will be returned unchanged
|
|
126
|
+
*
|
|
51
127
|
* @param array Array of items to swap
|
|
52
128
|
* @param first First item
|
|
53
129
|
* @param second Second item
|
|
54
|
-
* @param
|
|
130
|
+
* @param key Key to get an item's value for matching
|
|
55
131
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* swap(
|
|
136
|
+
* [
|
|
137
|
+
* {id: 1, name: 'Alice'},
|
|
138
|
+
* {id: 2, name: 'Bob'},
|
|
139
|
+
* {id: 3, name: 'Charlie'},
|
|
140
|
+
* ],
|
|
141
|
+
* {id: 2, name: 'Bob'},
|
|
142
|
+
* {id: 3, name: 'Charlie'},
|
|
143
|
+
* 'id',
|
|
144
|
+
* ); // => [
|
|
145
|
+
* // {id: 1, name: 'Alice'},
|
|
146
|
+
* // {id: 3, name: 'Charlie'},
|
|
147
|
+
* // {id: 2, name: 'Bob'},
|
|
148
|
+
* // ]
|
|
149
|
+
* ```
|
|
56
150
|
*/
|
|
57
|
-
declare function swap<Item>(array: Item[], first: Item, second: Item,
|
|
151
|
+
declare function swap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], first: Item, second: Item, key: ItemKey): Item[];
|
|
58
152
|
/**
|
|
59
153
|
* Swap two indiced items in an array
|
|
154
|
+
*
|
|
60
155
|
* @param array Array of items to swap
|
|
61
156
|
* @param first First item
|
|
62
157
|
* @param second Second item
|
|
63
158
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* swap(
|
|
163
|
+
* [1, 2, 3, 4, 5, 6],
|
|
164
|
+
* 2,
|
|
165
|
+
* 5,
|
|
166
|
+
* ); // => [1, 5, 3, 4, 2, 6]
|
|
167
|
+
* ```
|
|
64
168
|
*/
|
|
65
169
|
declare function swap<Item>(array: Item[], first: Item, second: Item): Item[];
|
|
66
170
|
declare namespace swap {
|
|
@@ -72,6 +176,7 @@ declare namespace swap {
|
|
|
72
176
|
* If either index is out of bounds, the array will be returned unchanged
|
|
73
177
|
*
|
|
74
178
|
* Available as `swapIndices` and `swap.indices`
|
|
179
|
+
*
|
|
75
180
|
* @param array Array of items to swap
|
|
76
181
|
* @param first First index _(can be negative to count from the end)_
|
|
77
182
|
* @param second Second index _(can be negative to count from the end)_
|
package/dist/array/swap.mjs
CHANGED
|
@@ -34,6 +34,7 @@ function swapArrays(array, from, to, key) {
|
|
|
34
34
|
* If either index is out of bounds, the array will be returned unchanged
|
|
35
35
|
*
|
|
36
36
|
* Available as `swapIndices` and `swap.indices`
|
|
37
|
+
*
|
|
37
38
|
* @param array Array of items to swap
|
|
38
39
|
* @param first First index _(can be negative to count from the end)_
|
|
39
40
|
* @param second Second index _(can be negative to count from the end)_
|
package/dist/array/to-map.d.mts
CHANGED
|
@@ -5,64 +5,130 @@ import { Key, PlainObject } from "../models.mjs";
|
|
|
5
5
|
* Create a Map from an array of items using callbacks
|
|
6
6
|
*
|
|
7
7
|
* If multiple items have the same key, the latest item's value will be used
|
|
8
|
+
*
|
|
8
9
|
* @param array Array to convert
|
|
9
10
|
* @param key Callback to get an item's grouping key
|
|
10
11
|
* @param value Callback to get an item's value
|
|
11
12
|
* @returns Map of keyed values
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* toMap(
|
|
17
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
18
|
+
* item => item.value,
|
|
19
|
+
* item => item.id,
|
|
20
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
21
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
declare function toMap<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
14
24
|
/**
|
|
15
25
|
* Create a Map from an array of items using a callback and value
|
|
16
26
|
*
|
|
17
27
|
* If multiple items have the same key, the latest item's value will be used
|
|
28
|
+
*
|
|
18
29
|
* @param array Array to convert
|
|
19
30
|
* @param key Callback to get an item's grouping key
|
|
20
31
|
* @param value Key to use for value
|
|
21
32
|
* @returns Map of keyed values
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* toMap(
|
|
37
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
38
|
+
* item => item.value,
|
|
39
|
+
* 'id',
|
|
40
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
41
|
+
* ```
|
|
22
42
|
*/
|
|
23
43
|
declare function toMap<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
24
44
|
/**
|
|
25
45
|
* Create a Map from an array of items using a key and callback
|
|
26
46
|
*
|
|
27
47
|
* If multiple items have the same key, the latest item's value will be used
|
|
48
|
+
*
|
|
28
49
|
* @param array Array to convert
|
|
29
50
|
* @param key Key to use for grouping
|
|
30
51
|
* @param value Callback to get an item's value
|
|
31
52
|
* @returns Map of keyed values
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* toMap(
|
|
57
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
58
|
+
* 'value',
|
|
59
|
+
* item => item.id,
|
|
60
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
61
|
+
* ```
|
|
32
62
|
*/
|
|
33
63
|
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], ReturnType<ValueCallback>>;
|
|
34
64
|
/**
|
|
35
65
|
* Create a Map from an array of items using a key and value
|
|
36
66
|
*
|
|
37
67
|
* If multiple items have the same key, the latest item's value will be used
|
|
68
|
+
*
|
|
38
69
|
* @param array Array to convert
|
|
39
70
|
* @param key Key to use for grouping
|
|
40
71
|
* @param value Key to use for value
|
|
41
72
|
* @returns Map of keyed values
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* toMap(
|
|
77
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
78
|
+
* 'value',
|
|
79
|
+
* 'id',
|
|
80
|
+
* ); // => Map { 10 => 3, 20 => 2 }
|
|
81
|
+
* ```
|
|
42
82
|
*/
|
|
43
83
|
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], Item[ItemValue]>;
|
|
44
84
|
/**
|
|
45
85
|
* Create a Map from an array of items using a callback
|
|
46
86
|
*
|
|
47
87
|
* If multiple items have the same key, the latest item will be used
|
|
88
|
+
*
|
|
48
89
|
* @param array Array to convert
|
|
49
90
|
* @param callback Callback to get an item's grouping key
|
|
50
91
|
* @returns Map of keyed items
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* toMap(
|
|
96
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
97
|
+
* item => item.value,
|
|
98
|
+
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
99
|
+
* ```
|
|
51
100
|
*/
|
|
52
101
|
declare function toMap<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item>;
|
|
53
102
|
/**
|
|
54
103
|
* Create a Map from an array of items using a key
|
|
55
104
|
*
|
|
56
105
|
* If multiple items have the same key, the latest item will be used
|
|
106
|
+
*
|
|
57
107
|
* @param array Array to convert
|
|
58
108
|
* @param key Key to use for grouping
|
|
59
109
|
* @returns Map of keyed items
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* toMap(
|
|
114
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
115
|
+
* 'value',
|
|
116
|
+
* ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} }
|
|
117
|
+
* ```
|
|
60
118
|
*/
|
|
61
119
|
declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
|
|
62
120
|
/**
|
|
63
121
|
* Create a Map from an array of items _(using indices as keys)_
|
|
122
|
+
*
|
|
64
123
|
* @param array Array to convert
|
|
65
124
|
* @returns Map of indiced items
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* toMap(
|
|
129
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
130
|
+
* ); // => Map { 0 => {id: 1, value: 10}, 1 => {id: 2, value: 20}, 2 => {id: 3, value: 10} }
|
|
131
|
+
* ```
|
|
66
132
|
*/
|
|
67
133
|
declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
68
134
|
declare namespace toMap {
|
|
@@ -72,58 +138,116 @@ declare namespace toMap {
|
|
|
72
138
|
* Create a Map from an array of items using callbacks, grouping values into arrays
|
|
73
139
|
*
|
|
74
140
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
141
|
+
*
|
|
75
142
|
* @param array Array to convert
|
|
76
143
|
* @param key Callback to get an item's grouping key
|
|
77
144
|
* @param value Callback to get an item's value
|
|
78
145
|
* @returns Map of keyed arrays of values
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* toMapArrays(
|
|
150
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
151
|
+
* item => item.value,
|
|
152
|
+
* item => item.id,
|
|
153
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
154
|
+
* ```
|
|
79
155
|
*/
|
|
80
156
|
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
81
157
|
/**
|
|
82
158
|
* Create a Map from an array of items using a callback and value, grouping values into arrays
|
|
83
159
|
*
|
|
84
160
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
161
|
+
*
|
|
85
162
|
* @param array Array to convert
|
|
86
163
|
* @param key Callback to get an item's grouping key
|
|
87
164
|
* @param value Key to use for value
|
|
88
165
|
* @returns Map of keyed arrays of values
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* toMapArrays(
|
|
170
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
171
|
+
* item => item.value,
|
|
172
|
+
* 'id',
|
|
173
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
174
|
+
* ```
|
|
89
175
|
*/
|
|
90
176
|
declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
91
177
|
/**
|
|
92
178
|
* Create a Map from an array of items using a key and callback, grouping values into arrays
|
|
93
179
|
*
|
|
94
180
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
181
|
+
*
|
|
95
182
|
* @param array Array to convert
|
|
96
183
|
* @param key Key to use for grouping
|
|
97
184
|
* @param value Callback to get an item's value
|
|
98
185
|
* @returns Map of keyed arrays of values
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* toMapArrays(
|
|
190
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
191
|
+
* 'value',
|
|
192
|
+
* item => item.id,
|
|
193
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
194
|
+
* ```
|
|
99
195
|
*/
|
|
100
196
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], ReturnType<ValueCallback>[]>;
|
|
101
197
|
/**
|
|
102
198
|
* Create a Map from an array of items using a key and value, grouping values into arrays
|
|
103
199
|
*
|
|
104
200
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
201
|
+
*
|
|
105
202
|
* @param array Array to convert
|
|
106
203
|
* @param key Key to use for grouping
|
|
107
204
|
* @param value Key to use for value
|
|
108
205
|
* @returns Map of keyed arrays of values
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* toMapArrays(
|
|
210
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
211
|
+
* 'value',
|
|
212
|
+
* 'id',
|
|
213
|
+
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
214
|
+
* ```
|
|
109
215
|
*/
|
|
110
216
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], Item[ItemValue][]>;
|
|
111
217
|
/**
|
|
112
218
|
* Create a Map from an array of items using a callback, grouping items into arrays
|
|
113
219
|
*
|
|
114
220
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
221
|
+
*
|
|
115
222
|
* @param array Array to convert
|
|
116
223
|
* @param callback Callback to get an item's grouping key
|
|
117
224
|
* @returns Map of keyed arrays of items
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* toMapArrays(
|
|
229
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
230
|
+
* item => item.value,
|
|
231
|
+
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
232
|
+
* ```
|
|
118
233
|
*/
|
|
119
234
|
declare function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item[]>;
|
|
120
235
|
/**
|
|
121
236
|
* Create a Map from an array of items using a key, grouping items into arrays
|
|
122
237
|
*
|
|
123
238
|
* Available as `toMapArrays` and `toMap.arrays`
|
|
239
|
+
*
|
|
124
240
|
* @param array Array to convert
|
|
125
241
|
* @param key Key to use for grouping
|
|
126
242
|
* @returns Map of keyed arrays of items
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* toMapArrays(
|
|
247
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
248
|
+
* 'value',
|
|
249
|
+
* ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] }
|
|
250
|
+
* ```
|
|
127
251
|
*/
|
|
128
252
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item[]>;
|
|
129
253
|
//#endregion
|
|
@@ -5,64 +5,130 @@ import { Key, KeyedValue, PlainObject, Simplify } from "../models.mjs";
|
|
|
5
5
|
* Create a record from an array of items using callbacks
|
|
6
6
|
*
|
|
7
7
|
* If multiple items have the same key, the latest item will be used
|
|
8
|
+
*
|
|
8
9
|
* @param array Array to convert
|
|
9
10
|
* @param key Callback to get an item's grouping key
|
|
10
11
|
* @param value Callback to get an item's value
|
|
11
12
|
* @returns Record of keyed values
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* toRecord(
|
|
17
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
18
|
+
* item => item.value,
|
|
19
|
+
* item => item.id,
|
|
20
|
+
* ); // => { 10: 3, 20: 2 }
|
|
21
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
declare function toRecord<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>;
|
|
14
24
|
/**
|
|
15
25
|
* Create a record from an array of items using a callback and value
|
|
16
26
|
*
|
|
17
27
|
* If multiple items have the same key, the latest item will be used
|
|
28
|
+
*
|
|
18
29
|
* @param array Array to convert
|
|
19
30
|
* @param callback Callback to get an item's grouping key
|
|
20
31
|
* @param value Key to use for value
|
|
21
32
|
* @returns Record with keys
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* toRecord(
|
|
37
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
38
|
+
* item => item.value,
|
|
39
|
+
* 'id',
|
|
40
|
+
* ); // => { 10: 3, 20: 2 }
|
|
41
|
+
* ```
|
|
22
42
|
*/
|
|
23
43
|
declare function toRecord<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue]>;
|
|
24
44
|
/**
|
|
25
45
|
* Create a record from an array of items using a key and callback
|
|
26
46
|
*
|
|
27
47
|
* If multiple items have the same key, the latest item will be used
|
|
48
|
+
*
|
|
28
49
|
* @param array Array to convert
|
|
29
50
|
* @param key Key to use for grouping
|
|
30
51
|
* @param callback Callback to get an item's value
|
|
31
52
|
* @returns Record with keys
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* toRecord(
|
|
57
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
58
|
+
* 'value',
|
|
59
|
+
* item => item.id,
|
|
60
|
+
* ); // => { 10: 3, 20: 2 }
|
|
61
|
+
* ```
|
|
32
62
|
*/
|
|
33
63
|
declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback>>>;
|
|
34
64
|
/**
|
|
35
65
|
* Create a record from an array of items using a key and value
|
|
36
66
|
*
|
|
37
67
|
* If multiple items have the same key, the latest item will be used
|
|
68
|
+
*
|
|
38
69
|
* @param array Array to convert
|
|
39
70
|
* @param key Key to use for grouping
|
|
40
71
|
* @param value Key to use for value
|
|
41
72
|
* @returns Record of keyed values
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* toRecord(
|
|
77
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
78
|
+
* 'value',
|
|
79
|
+
* 'id',
|
|
80
|
+
* ); // => { 10: 3, 20: 2 }
|
|
81
|
+
* ```
|
|
42
82
|
*/
|
|
43
83
|
declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
44
84
|
/**
|
|
45
85
|
* Create a record from an array of items using a callback
|
|
46
86
|
*
|
|
47
87
|
* If multiple items have the same key, the latest item will be used
|
|
88
|
+
*
|
|
48
89
|
* @param array Array to convert
|
|
49
90
|
* @param callback Callback to get an item's grouping key
|
|
50
91
|
* @returns Record of keyed values
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* toRecord(
|
|
96
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
97
|
+
* item => item.value,
|
|
98
|
+
* ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
|
|
99
|
+
* ```
|
|
51
100
|
*/
|
|
52
101
|
declare function toRecord<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item>;
|
|
53
102
|
/**
|
|
54
103
|
* Create a record from an array of items using a key
|
|
55
104
|
*
|
|
56
105
|
* If multiple items have the same key, the latest item will be used
|
|
106
|
+
*
|
|
57
107
|
* @param array Array to convert
|
|
58
108
|
* @param key Key to use for grouping
|
|
59
109
|
* @returns Record of keyed values
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* toRecord(
|
|
114
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
115
|
+
* 'value',
|
|
116
|
+
* ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} }
|
|
117
|
+
* ```
|
|
60
118
|
*/
|
|
61
119
|
declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
62
120
|
/**
|
|
63
121
|
* Create a record from an array of items _(using indices as keys)_
|
|
122
|
+
*
|
|
64
123
|
* @param array Array to convert
|
|
65
124
|
* @returns Record of indiced values
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* toRecord(
|
|
129
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
130
|
+
* ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} }
|
|
131
|
+
* ```
|
|
66
132
|
*/
|
|
67
133
|
declare function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
68
134
|
declare namespace toRecord {
|
|
@@ -72,58 +138,116 @@ declare namespace toRecord {
|
|
|
72
138
|
* Create a record from an array of items using callbacks, grouping values into arrays
|
|
73
139
|
*
|
|
74
140
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
141
|
+
*
|
|
75
142
|
* @param array Array to convert
|
|
76
143
|
* @param key Callback to get an item's grouping key
|
|
77
144
|
* @param value Callback to get an item's value
|
|
78
145
|
* @returns Record of keyed arrays of values
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* toRecordArrays(
|
|
150
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
151
|
+
* item => item.value,
|
|
152
|
+
* item => item.id,
|
|
153
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
154
|
+
* ```
|
|
79
155
|
*/
|
|
80
156
|
declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
81
157
|
/**
|
|
82
158
|
* Create a record from an array of items using a callback and value, grouping values into arrays
|
|
83
159
|
*
|
|
84
160
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
161
|
+
*
|
|
85
162
|
* @param array Array to convert
|
|
86
163
|
* @param callback Callback to get an item's grouping key
|
|
87
164
|
* @param value Key to use for value
|
|
88
165
|
* @returns Record of keyed arrays of values
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* toRecordArrays(
|
|
170
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
171
|
+
* item => item.value,
|
|
172
|
+
* 'id',
|
|
173
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
174
|
+
* ```
|
|
89
175
|
*/
|
|
90
176
|
declare function toRecordArrays<Item extends PlainObject, Callback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record<ReturnType<Callback>, Item[ItemValue][]>;
|
|
91
177
|
/**
|
|
92
178
|
* Create a record from an array of items using a key and callback, grouping values into arrays
|
|
93
179
|
*
|
|
94
180
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
181
|
+
*
|
|
95
182
|
* @param array Array to convert
|
|
96
183
|
* @param key Key to use for grouping
|
|
97
184
|
* @param callback Callback to get an item's value
|
|
98
185
|
* @returns Record of keyed arrays of values
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* toRecordArrays(
|
|
190
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
191
|
+
* 'value',
|
|
192
|
+
* item => item.id,
|
|
193
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
194
|
+
* ```
|
|
99
195
|
*/
|
|
100
196
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback>[]>>;
|
|
101
197
|
/**
|
|
102
198
|
* Create a record from an array of items using a key and value, grouping values into arrays
|
|
103
199
|
*
|
|
104
200
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
201
|
+
*
|
|
105
202
|
* @param array Array to convert
|
|
106
203
|
* @param key Key to use for grouping
|
|
107
204
|
* @param value Key to use for value
|
|
108
205
|
* @returns Record of keyed arrays of values
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* toRecordArrays(
|
|
210
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
211
|
+
* 'value',
|
|
212
|
+
* 'id',
|
|
213
|
+
* ); // => { 10: [1, 3], 20: [2] }
|
|
214
|
+
* ```
|
|
109
215
|
*/
|
|
110
216
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
|
|
111
217
|
/**
|
|
112
218
|
* Create a record from an array of items using a callback, grouping items into arrays
|
|
113
219
|
*
|
|
114
220
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
221
|
+
*
|
|
115
222
|
* @param array Array to convert
|
|
116
223
|
* @param callback Callback to get an item's grouping key
|
|
117
224
|
* @returns Record of keyed arrays of items
|
|
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
|
+
* ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
|
|
232
|
+
* ```
|
|
118
233
|
*/
|
|
119
234
|
declare function toRecordArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
120
235
|
/**
|
|
121
236
|
* Create a record from an array of items using a key, grouping items into arrays
|
|
122
237
|
*
|
|
123
238
|
* Available as `toRecordArrays` and `toRecord.arrays`
|
|
239
|
+
*
|
|
124
240
|
* @param array Array to convert
|
|
125
241
|
* @param key Key to use for grouping
|
|
126
242
|
* @returns Record of keyed arrays of items
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* toRecordArrays(
|
|
247
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
248
|
+
* 'value',
|
|
249
|
+
* ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] }
|
|
250
|
+
* ```
|
|
127
251
|
*/
|
|
128
252
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
129
253
|
//#endregion
|