@oscarpalmer/atoms 0.77.2 → 0.77.3
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/package.json +1 -1
- package/src/js/array/group-by.ts +10 -9
- package/src/js/array/to-map.ts +20 -20
- package/src/js/array/to-record.ts +59 -58
- package/types/array/group-by.d.cts +69 -9
- package/types/array/group-by.d.ts +10 -9
- package/types/array/index.d.cts +87 -27
- package/types/array/to-map.d.cts +10 -11
- package/types/array/to-map.d.ts +11 -11
- package/types/array/to-record.d.cts +68 -8
- package/types/array/to-record.d.ts +9 -8
- package/types/index.d.cts +41 -39
package/package.json
CHANGED
package/src/js/array/group-by.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {Simplify} from 'type-fest';
|
|
1
2
|
import {getCallbacks} from '~/internal/array/callbacks';
|
|
2
3
|
import type {Key, KeyedValue, PlainObject} from '~/models';
|
|
3
4
|
|
|
@@ -7,7 +8,7 @@ import type {Key, KeyedValue, PlainObject} from '~/models';
|
|
|
7
8
|
export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
8
9
|
array: Item[],
|
|
9
10
|
key: ItemKey,
|
|
10
|
-
): Record<KeyedValue<Item, ItemKey>, Item
|
|
11
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
@@ -16,7 +17,7 @@ export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
16
17
|
array: Item[],
|
|
17
18
|
key: ItemKey,
|
|
18
19
|
arrays: true,
|
|
19
|
-
): Record<KeyedValue<Item, ItemKey>, Item[]
|
|
20
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Create a record from an array of items using a specific key
|
|
@@ -49,7 +50,7 @@ export function groupBy<
|
|
|
49
50
|
array: Item[],
|
|
50
51
|
key: ItemKey,
|
|
51
52
|
value: ItemValue,
|
|
52
|
-
): Record<KeyedValue<Item, ItemKey>,
|
|
53
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
@@ -63,7 +64,7 @@ export function groupBy<
|
|
|
63
64
|
key: ItemKey,
|
|
64
65
|
value: ItemValue,
|
|
65
66
|
arrays: true,
|
|
66
|
-
): Record<KeyedValue<Item, ItemKey>, Array<
|
|
67
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Array<Item[ItemValue]>>>;
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Create a record from an array of items using a specific key and value
|
|
@@ -76,7 +77,7 @@ export function groupBy<
|
|
|
76
77
|
array: Item[],
|
|
77
78
|
key: ItemKey,
|
|
78
79
|
value: ItemValue,
|
|
79
|
-
): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue
|
|
80
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>>;
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
83
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
@@ -90,7 +91,7 @@ export function groupBy<
|
|
|
90
91
|
key: ItemKey,
|
|
91
92
|
value: ItemValue,
|
|
92
93
|
arrays: true,
|
|
93
|
-
): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue
|
|
94
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>>;
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* Create a record from an array of items using a specific key and value
|
|
@@ -103,7 +104,7 @@ export function groupBy<
|
|
|
103
104
|
array: Item[],
|
|
104
105
|
key: ItemKey,
|
|
105
106
|
value: ItemValue,
|
|
106
|
-
): Record<ReturnType<ItemKey>,
|
|
107
|
+
): Record<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
110
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
@@ -117,7 +118,7 @@ export function groupBy<
|
|
|
117
118
|
key: ItemKey,
|
|
118
119
|
value: ItemValue,
|
|
119
120
|
arrays: true,
|
|
120
|
-
): Record<ReturnType<ItemKey>, Array<
|
|
121
|
+
): Record<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* Create a record from an array of items using a specific key and value
|
|
@@ -130,7 +131,7 @@ export function groupBy<
|
|
|
130
131
|
array: Item[],
|
|
131
132
|
key: ItemKey,
|
|
132
133
|
value: ItemValue,
|
|
133
|
-
): Record<ReturnType<ItemKey>, ReturnType<ItemValue
|
|
134
|
+
): Simplify<Record<ReturnType<ItemKey>, ReturnType<ItemValue>>>;
|
|
134
135
|
|
|
135
136
|
/**
|
|
136
137
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
package/src/js/array/to-map.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {getCallbacks} from '~/internal/array/callbacks';
|
|
2
|
-
import type {Key,
|
|
2
|
+
import type {Key, PlainObject} from '~/models';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Create a map from an array of items _(using their indices as keys)_
|
|
@@ -12,7 +12,7 @@ export function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
12
12
|
export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
13
13
|
array: Item[],
|
|
14
14
|
key: ItemKey,
|
|
15
|
-
): Map<
|
|
15
|
+
): Map<Item[ItemKey], Item>;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
@@ -21,7 +21,7 @@ export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
21
21
|
array: Item[],
|
|
22
22
|
key: ItemKey,
|
|
23
23
|
arrays: true,
|
|
24
|
-
): Map<
|
|
24
|
+
): Map<Item[ItemKey], Item[]>;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Create a map from an array of items using a specific key
|
|
@@ -50,7 +50,7 @@ export function toMap<
|
|
|
50
50
|
array: Item[],
|
|
51
51
|
key: ItemKey,
|
|
52
52
|
value: ItemValue,
|
|
53
|
-
): Map<
|
|
53
|
+
): Map<Item[ItemKey], Item[ItemValue]>;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
@@ -64,7 +64,7 @@ export function toMap<
|
|
|
64
64
|
key: ItemKey,
|
|
65
65
|
value: ItemValue,
|
|
66
66
|
arrays: true,
|
|
67
|
-
): Map<
|
|
67
|
+
): Map<Item[ItemKey], Array<Item[ItemValue]>>;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Create a map from an array of items using a specific key and value
|
|
@@ -77,7 +77,7 @@ export function toMap<
|
|
|
77
77
|
array: Item[],
|
|
78
78
|
key: ItemKey,
|
|
79
79
|
value: ItemValue,
|
|
80
|
-
): Map<
|
|
80
|
+
): Map<Item[ItemKey], ReturnType<ItemValue>>;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
@@ -91,7 +91,7 @@ export function toMap<
|
|
|
91
91
|
key: ItemKey,
|
|
92
92
|
value: ItemValue,
|
|
93
93
|
arrays: true,
|
|
94
|
-
): Map<
|
|
94
|
+
): Map<Item[ItemKey], Array<ReturnType<ItemValue>>>;
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* Create a map from an array of items using a specific key and value
|
|
@@ -104,7 +104,7 @@ export function toMap<
|
|
|
104
104
|
array: Item[],
|
|
105
105
|
key: ItemKey,
|
|
106
106
|
value: ItemValue,
|
|
107
|
-
): Map<ReturnType<ItemKey>,
|
|
107
|
+
): Map<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
@@ -118,41 +118,41 @@ export function toMap<
|
|
|
118
118
|
key: ItemKey,
|
|
119
119
|
value: ItemValue,
|
|
120
120
|
arrays: true,
|
|
121
|
-
): Map<ReturnType<ItemKey>, Array<
|
|
121
|
+
): Map<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* Create a map from an array of items using a specific key and value
|
|
125
125
|
*/
|
|
126
126
|
export function toMap<
|
|
127
127
|
Item,
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
129
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
130
130
|
>(
|
|
131
131
|
array: Item[],
|
|
132
|
-
key:
|
|
133
|
-
value:
|
|
134
|
-
): Map<ReturnType<
|
|
132
|
+
key: ItemKey,
|
|
133
|
+
value: ItemValue,
|
|
134
|
+
): Map<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
138
138
|
*/
|
|
139
139
|
export function toMap<
|
|
140
140
|
Item,
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
142
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
143
143
|
>(
|
|
144
144
|
array: Item[],
|
|
145
|
-
key:
|
|
146
|
-
value:
|
|
145
|
+
key: ItemKey,
|
|
146
|
+
value: ItemValue,
|
|
147
147
|
arrays: true,
|
|
148
|
-
): Map<ReturnType<
|
|
148
|
+
): Map<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
149
149
|
|
|
150
150
|
export function toMap(
|
|
151
151
|
array: unknown[],
|
|
152
152
|
first?: unknown,
|
|
153
153
|
second?: unknown,
|
|
154
154
|
third?: unknown,
|
|
155
|
-
): Map<
|
|
155
|
+
): Map<unknown, unknown> {
|
|
156
156
|
const asArrays = first === true || second === true || third === true;
|
|
157
157
|
const callbacks = getCallbacks(undefined, first, second);
|
|
158
158
|
const map = new Map<Key, unknown>();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {Simplify} from 'type-fest';
|
|
1
2
|
import {groupValues} from '~/array/group-by';
|
|
2
3
|
import type {Key, KeyedValue, PlainObject} from '~/models';
|
|
3
4
|
|
|
@@ -10,18 +11,18 @@ export function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
|
10
11
|
* Create a record from an array of items using a specific key
|
|
11
12
|
*/
|
|
12
13
|
export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
): Record<KeyedValue<Item, ItemKey>, Item
|
|
14
|
+
array: Item[],
|
|
15
|
+
key: ItemKey,
|
|
16
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
19
20
|
*/
|
|
20
21
|
export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
): Record<KeyedValue<Item, ItemKey>, Item[]
|
|
22
|
+
array: Item[],
|
|
23
|
+
key: ItemKey,
|
|
24
|
+
arrays: true,
|
|
25
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Create a record from an array of items using a specific key
|
|
@@ -47,82 +48,82 @@ export function toRecord<
|
|
|
47
48
|
* Create a record from an array of items using a specific key and value
|
|
48
49
|
*/
|
|
49
50
|
export function toRecord<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
>(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
): Record<KeyedValue<Item, ItemKey>,
|
|
51
|
+
Item extends PlainObject,
|
|
52
|
+
ItemKey extends keyof Item,
|
|
53
|
+
ItemValue extends keyof Item,
|
|
54
|
+
>(
|
|
55
|
+
array: Item[],
|
|
56
|
+
key: ItemKey,
|
|
57
|
+
value: ItemValue,
|
|
58
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
61
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
61
62
|
*/
|
|
62
63
|
export function toRecord<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
>(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
): Record<KeyedValue<Item, ItemKey>, Array<
|
|
64
|
+
Item extends PlainObject,
|
|
65
|
+
ItemKey extends keyof Item,
|
|
66
|
+
ItemValue extends keyof Item,
|
|
67
|
+
>(
|
|
68
|
+
array: Item[],
|
|
69
|
+
key: ItemKey,
|
|
70
|
+
value: ItemValue,
|
|
71
|
+
arrays: true,
|
|
72
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Array<Item[ItemValue]>>>;
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* Create a record from an array of items using a specific key and value
|
|
75
76
|
*/
|
|
76
77
|
export function toRecord<
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
>(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue
|
|
78
|
+
Item extends PlainObject,
|
|
79
|
+
ItemKey extends keyof Item,
|
|
80
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
81
|
+
>(
|
|
82
|
+
array: Item[],
|
|
83
|
+
key: ItemKey,
|
|
84
|
+
value: ItemValue,
|
|
85
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>>;
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
88
89
|
*/
|
|
89
90
|
export function toRecord<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
>(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue
|
|
91
|
+
Item extends PlainObject,
|
|
92
|
+
ItemKey extends keyof Item,
|
|
93
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
94
|
+
>(
|
|
95
|
+
array: Item[],
|
|
96
|
+
key: ItemKey,
|
|
97
|
+
value: ItemValue,
|
|
98
|
+
arrays: true,
|
|
99
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>>;
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
102
|
* Create a record from an array of items using a specific key and value
|
|
102
103
|
*/
|
|
103
104
|
export function toRecord<
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
>(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
): Record<ReturnType<ItemKey>,
|
|
105
|
+
Item extends PlainObject,
|
|
106
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
107
|
+
ItemValue extends keyof Item,
|
|
108
|
+
>(
|
|
109
|
+
array: Item[],
|
|
110
|
+
key: ItemKey,
|
|
111
|
+
value: ItemValue,
|
|
112
|
+
): Record<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
112
113
|
|
|
113
114
|
/**
|
|
114
115
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
115
116
|
*/
|
|
116
117
|
export function toRecord<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
>(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
): Record<ReturnType<ItemKey>, Array<
|
|
118
|
+
Item extends PlainObject,
|
|
119
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
120
|
+
ItemValue extends keyof Item,
|
|
121
|
+
>(
|
|
122
|
+
array: Item[],
|
|
123
|
+
key: ItemKey,
|
|
124
|
+
value: ItemValue,
|
|
125
|
+
arrays: true,
|
|
126
|
+
): Record<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
* Create a record from an array of items using a specific key and value
|
|
@@ -31,17 +31,77 @@ isObject('hello');
|
|
|
31
31
|
@category Object
|
|
32
32
|
*/
|
|
33
33
|
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
36
|
+
|
|
37
|
+
@example
|
|
38
|
+
```
|
|
39
|
+
import type {Simplify} from 'type-fest';
|
|
40
|
+
|
|
41
|
+
type PositionProps = {
|
|
42
|
+
top: number;
|
|
43
|
+
left: number;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type SizeProps = {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
52
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
56
|
+
|
|
57
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
58
|
+
|
|
59
|
+
@example
|
|
60
|
+
```
|
|
61
|
+
import type {Simplify} from 'type-fest';
|
|
62
|
+
|
|
63
|
+
interface SomeInterface {
|
|
64
|
+
foo: number;
|
|
65
|
+
bar?: string;
|
|
66
|
+
baz: number | undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type SomeType = {
|
|
70
|
+
foo: number;
|
|
71
|
+
bar?: string;
|
|
72
|
+
baz: number | undefined;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
76
|
+
const someType: SomeType = literal;
|
|
77
|
+
const someInterface: SomeInterface = literal;
|
|
78
|
+
|
|
79
|
+
function fn(object: Record<string, unknown>): void {}
|
|
80
|
+
|
|
81
|
+
fn(literal); // Good: literal object type is sealed
|
|
82
|
+
fn(someType); // Good: type is sealed
|
|
83
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
84
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
88
|
+
@see SimplifyDeep
|
|
89
|
+
@category Object
|
|
90
|
+
*/
|
|
91
|
+
export type Simplify<T> = {
|
|
92
|
+
[KeyType in keyof T]: T[KeyType];
|
|
93
|
+
} & {};
|
|
34
94
|
export type KeyedValue<Item, Key extends keyof Item> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
35
95
|
export type Key = number | string;
|
|
36
96
|
export type PlainObject = UnknownRecord;
|
|
37
97
|
/**
|
|
38
98
|
* Create a record from an array of items using a specific key
|
|
39
99
|
*/
|
|
40
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Record<KeyedValue<Item, ItemKey>, Item
|
|
100
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
41
101
|
/**
|
|
42
102
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
43
103
|
*/
|
|
44
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Record<KeyedValue<Item, ItemKey>, Item[]
|
|
104
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
45
105
|
/**
|
|
46
106
|
* Create a record from an array of items using a specific key
|
|
47
107
|
*/
|
|
@@ -53,31 +113,31 @@ export declare function groupBy<Item, ItemKey extends (item: Item, index: number
|
|
|
53
113
|
/**
|
|
54
114
|
* Create a record from an array of items using a specific key and value
|
|
55
115
|
*/
|
|
56
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>,
|
|
116
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
57
117
|
/**
|
|
58
118
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
59
119
|
*/
|
|
60
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<
|
|
120
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Array<Item[ItemValue]>>>;
|
|
61
121
|
/**
|
|
62
122
|
* Create a record from an array of items using a specific key and value
|
|
63
123
|
*/
|
|
64
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue
|
|
124
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>>;
|
|
65
125
|
/**
|
|
66
126
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
67
127
|
*/
|
|
68
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue
|
|
128
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>>;
|
|
69
129
|
/**
|
|
70
130
|
* Create a record from an array of items using a specific key and value
|
|
71
131
|
*/
|
|
72
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>,
|
|
132
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
73
133
|
/**
|
|
74
134
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
75
135
|
*/
|
|
76
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<
|
|
136
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
77
137
|
/**
|
|
78
138
|
* Create a record from an array of items using a specific key and value
|
|
79
139
|
*/
|
|
80
|
-
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, ReturnType<ItemValue
|
|
140
|
+
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<ReturnType<ItemKey>, ReturnType<ItemValue>>>;
|
|
81
141
|
/**
|
|
82
142
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
83
143
|
*/
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import type { Simplify } from 'type-fest';
|
|
1
2
|
import type { Key, KeyedValue, PlainObject } from '~/models';
|
|
2
3
|
/**
|
|
3
4
|
* Create a record from an array of items using a specific key
|
|
4
5
|
*/
|
|
5
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Record<KeyedValue<Item, ItemKey>, Item
|
|
6
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
6
7
|
/**
|
|
7
8
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
8
9
|
*/
|
|
9
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Record<KeyedValue<Item, ItemKey>, Item[]
|
|
10
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
10
11
|
/**
|
|
11
12
|
* Create a record from an array of items using a specific key
|
|
12
13
|
*/
|
|
@@ -18,31 +19,31 @@ export declare function groupBy<Item, ItemKey extends (item: Item, index: number
|
|
|
18
19
|
/**
|
|
19
20
|
* Create a record from an array of items using a specific key and value
|
|
20
21
|
*/
|
|
21
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>,
|
|
22
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
22
23
|
/**
|
|
23
24
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
24
25
|
*/
|
|
25
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<
|
|
26
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Array<Item[ItemValue]>>>;
|
|
26
27
|
/**
|
|
27
28
|
* Create a record from an array of items using a specific key and value
|
|
28
29
|
*/
|
|
29
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue
|
|
30
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>>;
|
|
30
31
|
/**
|
|
31
32
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
32
33
|
*/
|
|
33
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue
|
|
34
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>>;
|
|
34
35
|
/**
|
|
35
36
|
* Create a record from an array of items using a specific key and value
|
|
36
37
|
*/
|
|
37
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>,
|
|
38
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
38
39
|
/**
|
|
39
40
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
40
41
|
*/
|
|
41
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<
|
|
42
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
42
43
|
/**
|
|
43
44
|
* Create a record from an array of items using a specific key and value
|
|
44
45
|
*/
|
|
45
|
-
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, ReturnType<ItemValue
|
|
46
|
+
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<ReturnType<ItemKey>, ReturnType<ItemValue>>>;
|
|
46
47
|
/**
|
|
47
48
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
48
49
|
*/
|