@oscarpalmer/atoms 0.77.2 → 0.78.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/README.md +2 -2
- package/package.json +39 -78
- package/src/{js/array → array}/group-by.ts +10 -9
- package/src/{js/array → array}/to-map.ts +20 -20
- package/src/{js/array → 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/dist/css/a11y.css +0 -13
- package/dist/css/flex.css +0 -150
- package/dist/css/reset.css +0 -316
- package/src/css/a11y.scss +0 -16
- package/src/css/flex.scss +0 -104
- package/src/css/reset.scss +0 -323
- /package/dist/{js/array → array}/chunk.cjs +0 -0
- /package/dist/{js/array → array}/chunk.js +0 -0
- /package/dist/{js/array → array}/compact.cjs +0 -0
- /package/dist/{js/array → array}/compact.js +0 -0
- /package/dist/{js/array → array}/count.cjs +0 -0
- /package/dist/{js/array → array}/count.js +0 -0
- /package/dist/{js/array → array}/exists.cjs +0 -0
- /package/dist/{js/array → array}/exists.js +0 -0
- /package/dist/{js/array → array}/filter.cjs +0 -0
- /package/dist/{js/array → array}/filter.js +0 -0
- /package/dist/{js/array → array}/find.cjs +0 -0
- /package/dist/{js/array → array}/find.js +0 -0
- /package/dist/{js/array → array}/group-by.cjs +0 -0
- /package/dist/{js/array → array}/group-by.js +0 -0
- /package/dist/{js/array → array}/index-of.cjs +0 -0
- /package/dist/{js/array → array}/index-of.js +0 -0
- /package/dist/{js/array → array}/index.cjs +0 -0
- /package/dist/{js/array → array}/index.js +0 -0
- /package/dist/{js/array → array}/insert.cjs +0 -0
- /package/dist/{js/array → array}/insert.js +0 -0
- /package/dist/{js/array → array}/models.cjs +0 -0
- /package/dist/{js/array → array}/models.js +0 -0
- /package/dist/{js/array → array}/shuffle.cjs +0 -0
- /package/dist/{js/array → array}/shuffle.js +0 -0
- /package/dist/{js/array → array}/sort.cjs +0 -0
- /package/dist/{js/array → array}/sort.js +0 -0
- /package/dist/{js/array → array}/splice.cjs +0 -0
- /package/dist/{js/array → array}/splice.js +0 -0
- /package/dist/{js/array → array}/to-map.cjs +0 -0
- /package/dist/{js/array → array}/to-map.js +0 -0
- /package/dist/{js/array → array}/to-record.cjs +0 -0
- /package/dist/{js/array → array}/to-record.js +0 -0
- /package/dist/{js/array → array}/unique.cjs +0 -0
- /package/dist/{js/array → array}/unique.js +0 -0
- /package/dist/{js/colour → colour}/base.cjs +0 -0
- /package/dist/{js/colour → colour}/base.js +0 -0
- /package/dist/{js/colour → colour}/functions.cjs +0 -0
- /package/dist/{js/colour → colour}/functions.js +0 -0
- /package/dist/{js/colour → colour}/hex.cjs +0 -0
- /package/dist/{js/colour → colour}/hex.js +0 -0
- /package/dist/{js/colour → colour}/hsl.cjs +0 -0
- /package/dist/{js/colour → colour}/hsl.js +0 -0
- /package/dist/{js/colour → colour}/index.cjs +0 -0
- /package/dist/{js/colour → colour}/index.js +0 -0
- /package/dist/{js/colour → colour}/is.cjs +0 -0
- /package/dist/{js/colour → colour}/is.js +0 -0
- /package/dist/{js/colour → colour}/rgb.cjs +0 -0
- /package/dist/{js/colour → colour}/rgb.js +0 -0
- /package/dist/{js/emitter.cjs → emitter.cjs} +0 -0
- /package/dist/{js/emitter.js → emitter.js} +0 -0
- /package/dist/{js/function.cjs → function.cjs} +0 -0
- /package/dist/{js/function.js → function.js} +0 -0
- /package/dist/{js/index.cjs → index.cjs} +0 -0
- /package/dist/{js/index.js → index.js} +0 -0
- /package/dist/{js/internal → internal}/array/callbacks.cjs +0 -0
- /package/dist/{js/internal → internal}/array/callbacks.js +0 -0
- /package/dist/{js/internal → internal}/array/find.cjs +0 -0
- /package/dist/{js/internal → internal}/array/find.js +0 -0
- /package/dist/{js/internal → internal}/value/handle.cjs +0 -0
- /package/dist/{js/internal → internal}/value/handle.js +0 -0
- /package/dist/{js/is.cjs → is.cjs} +0 -0
- /package/dist/{js/is.js → is.js} +0 -0
- /package/dist/{js/logger.cjs → logger.cjs} +0 -0
- /package/dist/{js/logger.js → logger.js} +0 -0
- /package/dist/{js/math.cjs → math.cjs} +0 -0
- /package/dist/{js/math.js → math.js} +0 -0
- /package/dist/{js/models.cjs → models.cjs} +0 -0
- /package/dist/{js/models.js → models.js} +0 -0
- /package/dist/{js/number.cjs → number.cjs} +0 -0
- /package/dist/{js/number.js → number.js} +0 -0
- /package/dist/{js/query.cjs → query.cjs} +0 -0
- /package/dist/{js/query.js → query.js} +0 -0
- /package/dist/{js/queue.cjs → queue.cjs} +0 -0
- /package/dist/{js/queue.js → queue.js} +0 -0
- /package/dist/{js/random.cjs → random.cjs} +0 -0
- /package/dist/{js/random.js → random.js} +0 -0
- /package/dist/{js/sized.cjs → sized.cjs} +0 -0
- /package/dist/{js/sized.js → sized.js} +0 -0
- /package/dist/{js/string → string}/case.cjs +0 -0
- /package/dist/{js/string → string}/case.js +0 -0
- /package/dist/{js/string → string}/index.cjs +0 -0
- /package/dist/{js/string → string}/index.js +0 -0
- /package/dist/{js/string → string}/template.cjs +0 -0
- /package/dist/{js/string → string}/template.js +0 -0
- /package/dist/{js/touch.cjs → touch.cjs} +0 -0
- /package/dist/{js/touch.js → touch.js} +0 -0
- /package/dist/{js/value → value}/clone.cjs +0 -0
- /package/dist/{js/value → value}/clone.js +0 -0
- /package/dist/{js/value → value}/compare.cjs +0 -0
- /package/dist/{js/value → value}/compare.js +0 -0
- /package/dist/{js/value → value}/diff.cjs +0 -0
- /package/dist/{js/value → value}/diff.js +0 -0
- /package/dist/{js/value → value}/equal.cjs +0 -0
- /package/dist/{js/value → value}/equal.js +0 -0
- /package/dist/{js/value → value}/get.cjs +0 -0
- /package/dist/{js/value → value}/get.js +0 -0
- /package/dist/{js/value → value}/index.cjs +0 -0
- /package/dist/{js/value → value}/index.js +0 -0
- /package/dist/{js/value → value}/merge.cjs +0 -0
- /package/dist/{js/value → value}/merge.js +0 -0
- /package/dist/{js/value → value}/set.cjs +0 -0
- /package/dist/{js/value → value}/set.js +0 -0
- /package/dist/{js/value → value}/smush.cjs +0 -0
- /package/dist/{js/value → value}/smush.js +0 -0
- /package/dist/{js/value → value}/unsmush.cjs +0 -0
- /package/dist/{js/value → value}/unsmush.js +0 -0
- /package/src/{js/array → array}/chunk.ts +0 -0
- /package/src/{js/array → array}/compact.ts +0 -0
- /package/src/{js/array → array}/count.ts +0 -0
- /package/src/{js/array → array}/exists.ts +0 -0
- /package/src/{js/array → array}/filter.ts +0 -0
- /package/src/{js/array → array}/find.ts +0 -0
- /package/src/{js/array → array}/index-of.ts +0 -0
- /package/src/{js/array → array}/index.ts +0 -0
- /package/src/{js/array → array}/insert.ts +0 -0
- /package/src/{js/array → array}/models.ts +0 -0
- /package/src/{js/array → array}/shuffle.ts +0 -0
- /package/src/{js/array → array}/sort.ts +0 -0
- /package/src/{js/array → array}/splice.ts +0 -0
- /package/src/{js/array → array}/unique.ts +0 -0
- /package/src/{js/colour → colour}/base.ts +0 -0
- /package/src/{js/colour → colour}/functions.ts +0 -0
- /package/src/{js/colour → colour}/hex.ts +0 -0
- /package/src/{js/colour → colour}/hsl.ts +0 -0
- /package/src/{js/colour → colour}/index.ts +0 -0
- /package/src/{js/colour → colour}/is.ts +0 -0
- /package/src/{js/colour → colour}/rgb.ts +0 -0
- /package/src/{js/emitter.ts → emitter.ts} +0 -0
- /package/src/{js/function.ts → function.ts} +0 -0
- /package/src/{js/index.ts → index.ts} +0 -0
- /package/src/{js/internal → internal}/array/callbacks.ts +0 -0
- /package/src/{js/internal → internal}/array/find.ts +0 -0
- /package/src/{js/internal → internal}/value/handle.ts +0 -0
- /package/src/{js/is.ts → is.ts} +0 -0
- /package/src/{js/logger.ts → logger.ts} +0 -0
- /package/src/{js/math.ts → math.ts} +0 -0
- /package/src/{js/models.ts → models.ts} +0 -0
- /package/src/{js/number.ts → number.ts} +0 -0
- /package/src/{js/query.ts → query.ts} +0 -0
- /package/src/{js/queue.ts → queue.ts} +0 -0
- /package/src/{js/random.ts → random.ts} +0 -0
- /package/src/{js/sized.ts → sized.ts} +0 -0
- /package/src/{js/string → string}/case.ts +0 -0
- /package/src/{js/string → string}/index.ts +0 -0
- /package/src/{js/string → string}/template.ts +0 -0
- /package/src/{js/touch.ts → touch.ts} +0 -0
- /package/src/{js/value → value}/clone.ts +0 -0
- /package/src/{js/value → value}/compare.ts +0 -0
- /package/src/{js/value → value}/diff.ts +0 -0
- /package/src/{js/value → value}/equal.ts +0 -0
- /package/src/{js/value → value}/get.ts +0 -0
- /package/src/{js/value → value}/index.ts +0 -0
- /package/src/{js/value → value}/merge.ts +0 -0
- /package/src/{js/value → value}/set.ts +0 -0
- /package/src/{js/value → value}/smush.ts +0 -0
- /package/src/{js/value → value}/unsmush.ts +0 -0
|
@@ -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
|
*/
|
package/types/array/index.d.cts
CHANGED
|
@@ -31,6 +31,66 @@ 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 NestedArrayType<Value> = Value extends Array<infer NestedValue> ? NestedArrayType<NestedValue> : Value;
|
|
36
96
|
export type Key = number | string;
|
|
@@ -120,11 +180,11 @@ export declare function find<Item, ItemKey extends (item: Item, index: number, a
|
|
|
120
180
|
/**
|
|
121
181
|
* Create a record from an array of items using a specific key
|
|
122
182
|
*/
|
|
123
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Record<KeyedValue<Item, ItemKey>, Item
|
|
183
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
124
184
|
/**
|
|
125
185
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
126
186
|
*/
|
|
127
|
-
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Record<KeyedValue<Item, ItemKey>, Item[]
|
|
187
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
128
188
|
/**
|
|
129
189
|
* Create a record from an array of items using a specific key
|
|
130
190
|
*/
|
|
@@ -136,31 +196,31 @@ export declare function groupBy<Item, ItemKey extends (item: Item, index: number
|
|
|
136
196
|
/**
|
|
137
197
|
* Create a record from an array of items using a specific key and value
|
|
138
198
|
*/
|
|
139
|
-
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>,
|
|
199
|
+
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]>>;
|
|
140
200
|
/**
|
|
141
201
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
142
202
|
*/
|
|
143
|
-
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<
|
|
203
|
+
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]>>>;
|
|
144
204
|
/**
|
|
145
205
|
* Create a record from an array of items using a specific key and value
|
|
146
206
|
*/
|
|
147
|
-
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
|
|
207
|
+
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>>>;
|
|
148
208
|
/**
|
|
149
209
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
150
210
|
*/
|
|
151
|
-
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
|
|
211
|
+
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>>>>;
|
|
152
212
|
/**
|
|
153
213
|
* Create a record from an array of items using a specific key and value
|
|
154
214
|
*/
|
|
155
|
-
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>,
|
|
215
|
+
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]>;
|
|
156
216
|
/**
|
|
157
217
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
158
218
|
*/
|
|
159
|
-
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<
|
|
219
|
+
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]>>;
|
|
160
220
|
/**
|
|
161
221
|
* Create a record from an array of items using a specific key and value
|
|
162
222
|
*/
|
|
163
|
-
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
|
|
223
|
+
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>>>;
|
|
164
224
|
/**
|
|
165
225
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
166
226
|
*/
|
|
@@ -250,11 +310,11 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
250
310
|
/**
|
|
251
311
|
* Create a map from an array of items using a specific key
|
|
252
312
|
*/
|
|
253
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<
|
|
313
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
|
|
254
314
|
/**
|
|
255
315
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
256
316
|
*/
|
|
257
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<
|
|
317
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<Item[ItemKey], Item[]>;
|
|
258
318
|
/**
|
|
259
319
|
* Create a map from an array of items using a specific key
|
|
260
320
|
*/
|
|
@@ -266,35 +326,35 @@ export declare function toMap<Item, ItemKey extends (item: Item, index: number,
|
|
|
266
326
|
/**
|
|
267
327
|
* Create a map from an array of items using a specific key and value
|
|
268
328
|
*/
|
|
269
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<
|
|
329
|
+
export 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]>;
|
|
270
330
|
/**
|
|
271
331
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
272
332
|
*/
|
|
273
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<
|
|
333
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<Item[ItemKey], Array<Item[ItemValue]>>;
|
|
274
334
|
/**
|
|
275
335
|
* Create a map from an array of items using a specific key and value
|
|
276
336
|
*/
|
|
277
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<
|
|
337
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], ReturnType<ItemValue>>;
|
|
278
338
|
/**
|
|
279
339
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
280
340
|
*/
|
|
281
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<
|
|
341
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<Item[ItemKey], Array<ReturnType<ItemValue>>>;
|
|
282
342
|
/**
|
|
283
343
|
* Create a map from an array of items using a specific key and value
|
|
284
344
|
*/
|
|
285
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>,
|
|
345
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
286
346
|
/**
|
|
287
347
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
288
348
|
*/
|
|
289
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<
|
|
349
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
290
350
|
/**
|
|
291
351
|
* Create a map from an array of items using a specific key and value
|
|
292
352
|
*/
|
|
293
|
-
export declare function toMap<Item,
|
|
353
|
+
export declare function toMap<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): Map<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
294
354
|
/**
|
|
295
355
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
296
356
|
*/
|
|
297
|
-
export declare function toMap<Item,
|
|
357
|
+
export declare function toMap<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, arrays: true): Map<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
298
358
|
/**
|
|
299
359
|
* Create a record from an array of items _(using their indices as keys)_
|
|
300
360
|
*/
|
|
@@ -302,11 +362,11 @@ export declare function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
|
302
362
|
/**
|
|
303
363
|
* Create a record from an array of items using a specific key
|
|
304
364
|
*/
|
|
305
|
-
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Record<KeyedValue<Item, ItemKey>, Item
|
|
365
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
306
366
|
/**
|
|
307
367
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
308
368
|
*/
|
|
309
|
-
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Record<KeyedValue<Item, ItemKey>, Item[]
|
|
369
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
310
370
|
/**
|
|
311
371
|
* Create a record from an array of items using a specific key
|
|
312
372
|
*/
|
|
@@ -318,27 +378,27 @@ export declare function toRecord<Item, ItemKey extends (item: Item, index: numbe
|
|
|
318
378
|
/**
|
|
319
379
|
* Create a record from an array of items using a specific key and value
|
|
320
380
|
*/
|
|
321
|
-
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>,
|
|
381
|
+
export 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]>>;
|
|
322
382
|
/**
|
|
323
383
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
324
384
|
*/
|
|
325
|
-
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<
|
|
385
|
+
export declare function toRecord<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]>>>;
|
|
326
386
|
/**
|
|
327
387
|
* Create a record from an array of items using a specific key and value
|
|
328
388
|
*/
|
|
329
|
-
export declare function toRecord<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
|
|
389
|
+
export declare function toRecord<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>>>;
|
|
330
390
|
/**
|
|
331
391
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
332
392
|
*/
|
|
333
|
-
export declare function toRecord<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
|
|
393
|
+
export declare function toRecord<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>>>>;
|
|
334
394
|
/**
|
|
335
395
|
* Create a record from an array of items using a specific key and value
|
|
336
396
|
*/
|
|
337
|
-
export declare function toRecord<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>,
|
|
397
|
+
export declare function toRecord<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]>;
|
|
338
398
|
/**
|
|
339
399
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
340
400
|
*/
|
|
341
|
-
export declare function toRecord<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<
|
|
401
|
+
export declare function toRecord<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]>>;
|
|
342
402
|
/**
|
|
343
403
|
* Create a record from an array of items using a specific key and value
|
|
344
404
|
*/
|
package/types/array/to-map.d.cts
CHANGED
|
@@ -31,7 +31,6 @@ isObject('hello');
|
|
|
31
31
|
@category Object
|
|
32
32
|
*/
|
|
33
33
|
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
34
|
-
export type KeyedValue<Item, Key extends keyof Item> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
35
34
|
export type Key = number | string;
|
|
36
35
|
export type PlainObject = UnknownRecord;
|
|
37
36
|
/**
|
|
@@ -41,11 +40,11 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
41
40
|
/**
|
|
42
41
|
* Create a map from an array of items using a specific key
|
|
43
42
|
*/
|
|
44
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<
|
|
43
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
|
|
45
44
|
/**
|
|
46
45
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
47
46
|
*/
|
|
48
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<
|
|
47
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<Item[ItemKey], Item[]>;
|
|
49
48
|
/**
|
|
50
49
|
* Create a map from an array of items using a specific key
|
|
51
50
|
*/
|
|
@@ -57,34 +56,34 @@ export declare function toMap<Item, ItemKey extends (item: Item, index: number,
|
|
|
57
56
|
/**
|
|
58
57
|
* Create a map from an array of items using a specific key and value
|
|
59
58
|
*/
|
|
60
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<
|
|
59
|
+
export 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]>;
|
|
61
60
|
/**
|
|
62
61
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
63
62
|
*/
|
|
64
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<
|
|
63
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<Item[ItemKey], Array<Item[ItemValue]>>;
|
|
65
64
|
/**
|
|
66
65
|
* Create a map from an array of items using a specific key and value
|
|
67
66
|
*/
|
|
68
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<
|
|
67
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], ReturnType<ItemValue>>;
|
|
69
68
|
/**
|
|
70
69
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
71
70
|
*/
|
|
72
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<
|
|
71
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<Item[ItemKey], Array<ReturnType<ItemValue>>>;
|
|
73
72
|
/**
|
|
74
73
|
* Create a map from an array of items using a specific key and value
|
|
75
74
|
*/
|
|
76
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>,
|
|
75
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
77
76
|
/**
|
|
78
77
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
79
78
|
*/
|
|
80
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<
|
|
79
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
81
80
|
/**
|
|
82
81
|
* Create a map from an array of items using a specific key and value
|
|
83
82
|
*/
|
|
84
|
-
export declare function toMap<Item,
|
|
83
|
+
export declare function toMap<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): Map<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
85
84
|
/**
|
|
86
85
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
87
86
|
*/
|
|
88
|
-
export declare function toMap<Item,
|
|
87
|
+
export declare function toMap<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, arrays: true): Map<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
89
88
|
|
|
90
89
|
export {};
|
package/types/array/to-map.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Key,
|
|
1
|
+
import type { Key, PlainObject } from '~/models';
|
|
2
2
|
/**
|
|
3
3
|
* Create a map from an array of items _(using their indices as keys)_
|
|
4
4
|
*/
|
|
@@ -6,11 +6,11 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
6
6
|
/**
|
|
7
7
|
* Create a map from an array of items using a specific key
|
|
8
8
|
*/
|
|
9
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<
|
|
9
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item>;
|
|
10
10
|
/**
|
|
11
11
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
12
12
|
*/
|
|
13
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<
|
|
13
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<Item[ItemKey], Item[]>;
|
|
14
14
|
/**
|
|
15
15
|
* Create a map from an array of items using a specific key
|
|
16
16
|
*/
|
|
@@ -22,32 +22,32 @@ export declare function toMap<Item, ItemKey extends (item: Item, index: number,
|
|
|
22
22
|
/**
|
|
23
23
|
* Create a map from an array of items using a specific key and value
|
|
24
24
|
*/
|
|
25
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<
|
|
25
|
+
export 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]>;
|
|
26
26
|
/**
|
|
27
27
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
28
28
|
*/
|
|
29
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<
|
|
29
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<Item[ItemKey], Array<Item[ItemValue]>>;
|
|
30
30
|
/**
|
|
31
31
|
* Create a map from an array of items using a specific key and value
|
|
32
32
|
*/
|
|
33
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<
|
|
33
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], ReturnType<ItemValue>>;
|
|
34
34
|
/**
|
|
35
35
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
36
36
|
*/
|
|
37
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<
|
|
37
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<Item[ItemKey], Array<ReturnType<ItemValue>>>;
|
|
38
38
|
/**
|
|
39
39
|
* Create a map from an array of items using a specific key and value
|
|
40
40
|
*/
|
|
41
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>,
|
|
41
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
42
42
|
/**
|
|
43
43
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
44
44
|
*/
|
|
45
|
-
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<
|
|
45
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
46
46
|
/**
|
|
47
47
|
* Create a map from an array of items using a specific key and value
|
|
48
48
|
*/
|
|
49
|
-
export declare function toMap<Item,
|
|
49
|
+
export declare function toMap<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): Map<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
50
50
|
/**
|
|
51
51
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
52
52
|
*/
|
|
53
|
-
export declare function toMap<Item,
|
|
53
|
+
export declare function toMap<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, arrays: true): Map<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|