@oscarpalmer/atoms 0.76.0 → 0.77.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/js/array/count.cjs +1 -8
  2. package/dist/js/array/count.js +1 -8
  3. package/dist/js/array/exists.cjs +1 -8
  4. package/dist/js/array/exists.js +1 -8
  5. package/dist/js/array/filter.cjs +1 -8
  6. package/dist/js/array/filter.js +1 -8
  7. package/dist/js/array/find.cjs +1 -8
  8. package/dist/js/array/find.js +1 -8
  9. package/dist/js/array/index-of.cjs +1 -8
  10. package/dist/js/array/index-of.js +1 -8
  11. package/dist/js/array/unique.cjs +1 -1
  12. package/dist/js/array/unique.js +1 -1
  13. package/dist/js/internal/array/find.cjs +12 -2
  14. package/dist/js/internal/array/find.js +12 -2
  15. package/dist/js/value/equal.cjs +4 -1
  16. package/dist/js/value/equal.js +4 -1
  17. package/package.json +11 -4
  18. package/src/js/array/count.ts +10 -23
  19. package/src/js/array/exists.ts +10 -25
  20. package/src/js/array/filter.ts +10 -23
  21. package/src/js/array/find.ts +10 -23
  22. package/src/js/array/group-by.ts +66 -56
  23. package/src/js/array/index-of.ts +10 -23
  24. package/src/js/array/models.ts +2 -16
  25. package/src/js/array/sort.ts +23 -7
  26. package/src/js/array/to-map.ts +59 -53
  27. package/src/js/array/to-record.ts +63 -61
  28. package/src/js/array/unique.ts +10 -10
  29. package/src/js/internal/array/callbacks.ts +4 -4
  30. package/src/js/internal/array/find.ts +29 -6
  31. package/src/js/internal/value/handle.ts +5 -5
  32. package/src/js/value/clone.ts +3 -1
  33. package/src/js/value/equal.ts +4 -1
  34. package/src/js/value/get.ts +9 -9
  35. package/src/js/value/set.ts +10 -11
  36. package/types/array/count.d.cts +35 -6
  37. package/types/array/count.d.ts +4 -4
  38. package/types/array/exists.d.cts +35 -6
  39. package/types/array/exists.d.ts +4 -4
  40. package/types/array/filter.d.cts +35 -6
  41. package/types/array/filter.d.ts +4 -4
  42. package/types/array/find.d.cts +35 -6
  43. package/types/array/find.d.ts +4 -4
  44. package/types/array/group-by.d.cts +44 -15
  45. package/types/array/group-by.d.ts +13 -14
  46. package/types/array/index-of.d.cts +35 -6
  47. package/types/array/index-of.d.ts +4 -4
  48. package/types/array/index.d.cts +103 -66
  49. package/types/array/models.d.cts +2 -7
  50. package/types/array/models.d.ts +2 -7
  51. package/types/array/sort.d.cts +45 -4
  52. package/types/array/sort.d.ts +14 -4
  53. package/types/array/to-map.d.cts +44 -15
  54. package/types/array/to-map.d.ts +13 -14
  55. package/types/array/to-record.d.cts +44 -15
  56. package/types/array/to-record.d.ts +13 -14
  57. package/types/array/unique.d.cts +36 -6
  58. package/types/array/unique.d.ts +5 -5
  59. package/types/index.d.cts +280 -261
  60. package/types/internal/array/find.d.cts +2 -2
  61. package/types/internal/array/find.d.ts +2 -2
  62. package/types/internal/value/handle.d.cts +27 -2
  63. package/types/internal/value/handle.d.ts +2 -2
  64. package/types/value/clone.d.cts +1 -1
  65. package/types/value/clone.d.ts +1 -1
  66. package/types/value/get.d.cts +3 -3
  67. package/types/value/get.d.ts +3 -3
  68. package/types/value/index.d.cts +5 -5
  69. package/types/value/set.d.cts +3 -3
  70. package/types/value/set.d.ts +3 -3
@@ -1,140 +1,150 @@
1
- import type {KeyCallback, ValueCallback} from '~/array/models';
2
1
  import {getCallbacks} from '~/internal/array/callbacks';
3
2
  import type {Key, KeyedValue, PlainObject} from '~/models';
4
3
 
5
4
  /**
6
5
  * Create a record from an array of items using a specific key
7
6
  */
8
- export function groupBy<Item, Key extends keyof Item>(
7
+ export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
9
8
  array: Item[],
10
- key: Key,
11
- ): Record<KeyedValue<Item, Key>, Item>;
9
+ key: ItemKey,
10
+ ): Record<KeyedValue<Item, ItemKey>, Item>;
12
11
 
13
12
  /**
14
13
  * Create a record from an array of items using a specific key, and grouping them into arrays
15
14
  */
16
- export function groupBy<Item, Key extends keyof Item>(
15
+ export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
17
16
  array: Item[],
18
- key: Key,
17
+ key: ItemKey,
19
18
  arrays: true,
20
- ): Record<KeyedValue<Item, Key>, Item[]>;
19
+ ): Record<KeyedValue<Item, ItemKey>, Item[]>;
21
20
 
22
21
  /**
23
22
  * Create a record from an array of items using a specific key
24
23
  */
25
- export function groupBy<Item, Key extends KeyCallback<Item>>(
26
- array: Item[],
27
- key: Key,
28
- ): Record<ReturnType<Key>, Item>;
24
+ export function groupBy<
25
+ Item,
26
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
27
+ >(array: Item[], key: ItemKey): Record<ReturnType<ItemKey>, Item>;
29
28
 
30
29
  /**
31
30
  * Create a record from an array of items using a specific key, and grouping them into arrays
32
31
  */
33
- export function groupBy<Item, Key extends KeyCallback<Item>>(
32
+ export function groupBy<
33
+ Item,
34
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
35
+ >(
34
36
  array: Item[],
35
- key: Key,
37
+ key: ItemKey,
36
38
  arrays: true,
37
- ): Record<ReturnType<Key>, Item[]>;
39
+ ): Record<ReturnType<ItemKey>, Item[]>;
38
40
 
39
41
  /**
40
42
  * Create a record from an array of items using a specific key and value
41
43
  */
42
- export function groupBy<Item, Key extends keyof Item, Value extends keyof Item>(
44
+ export function groupBy<
45
+ Item extends PlainObject,
46
+ ItemKey extends keyof Item,
47
+ ItemValue extends keyof Item,
48
+ >(
43
49
  array: Item[],
44
- key: Key,
45
- value: Value,
46
- ): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
50
+ key: ItemKey,
51
+ value: ItemValue,
52
+ ): Record<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
47
53
 
48
54
  /**
49
55
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
50
56
  */
51
- export function groupBy<Item, Key extends keyof Item, Value extends keyof Item>(
57
+ export function groupBy<
58
+ Item extends PlainObject,
59
+ ItemKey extends keyof Item,
60
+ ItemValue extends keyof Item,
61
+ >(
52
62
  array: Item[],
53
- key: Key,
54
- value: Value,
63
+ key: ItemKey,
64
+ value: ItemValue,
55
65
  arrays: true,
56
- ): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
66
+ ): Record<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
57
67
 
58
68
  /**
59
69
  * Create a record from an array of items using a specific key and value
60
70
  */
61
71
  export function groupBy<
62
- Item,
63
- Key extends keyof Item,
64
- Value extends ValueCallback<Item>,
72
+ Item extends PlainObject,
73
+ ItemKey extends keyof Item,
74
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
65
75
  >(
66
76
  array: Item[],
67
- key: Key,
68
- value: Value,
69
- ): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
77
+ key: ItemKey,
78
+ value: ItemValue,
79
+ ): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
70
80
 
71
81
  /**
72
82
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
73
83
  */
74
84
  export function groupBy<
75
- Item,
76
- Key extends keyof Item,
77
- Value extends ValueCallback<Item>,
85
+ Item extends PlainObject,
86
+ ItemKey extends keyof Item,
87
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
78
88
  >(
79
89
  array: Item[],
80
- key: Key,
81
- value: Value,
90
+ key: ItemKey,
91
+ value: ItemValue,
82
92
  arrays: true,
83
- ): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
93
+ ): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
84
94
 
85
95
  /**
86
96
  * Create a record from an array of items using a specific key and value
87
97
  */
88
98
  export function groupBy<
89
- Item,
90
- Key extends KeyCallback<Item>,
91
- Value extends keyof Item,
99
+ Item extends PlainObject,
100
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
101
+ ItemValue extends keyof Item,
92
102
  >(
93
103
  array: Item[],
94
- key: Key,
95
- value: Value,
96
- ): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
104
+ key: ItemKey,
105
+ value: ItemValue,
106
+ ): Record<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
97
107
 
98
108
  /**
99
109
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
100
110
  */
101
111
  export function groupBy<
102
- Item,
103
- Key extends KeyCallback<Item>,
104
- Value extends keyof Item,
112
+ Item extends PlainObject,
113
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
114
+ ItemValue extends keyof Item,
105
115
  >(
106
116
  array: Item[],
107
- key: Key,
108
- value: Value,
117
+ key: ItemKey,
118
+ value: ItemValue,
109
119
  arrays: true,
110
- ): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
120
+ ): Record<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
111
121
 
112
122
  /**
113
123
  * Create a record from an array of items using a specific key and value
114
124
  */
115
125
  export function groupBy<
116
126
  Item,
117
- Key extends KeyCallback<Item>,
118
- Value extends ValueCallback<Item>,
127
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
128
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
119
129
  >(
120
130
  array: Item[],
121
- key: Key,
122
- value: Value,
123
- ): Record<ReturnType<Key>, ReturnType<Value>>;
131
+ key: ItemKey,
132
+ value: ItemValue,
133
+ ): Record<ReturnType<ItemKey>, ReturnType<ItemValue>>;
124
134
 
125
135
  /**
126
136
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
127
137
  */
128
138
  export function groupBy<
129
139
  Item,
130
- Key extends KeyCallback<Item>,
131
- Value extends ValueCallback<Item>,
140
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
141
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
132
142
  >(
133
143
  array: Item[],
134
- key: Key,
135
- value: Value,
144
+ key: ItemKey,
145
+ value: ItemValue,
136
146
  arrays: true,
137
- ): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
147
+ ): Record<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
138
148
 
139
149
  export function groupBy(
140
150
  array: unknown[],
@@ -1,5 +1,5 @@
1
- import type {BooleanCallback, KeyCallback} from '~/array/models';
2
1
  import {findValue} from '~/internal/array/find';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the index for the first item matching `value` _(or `-1` if no match is found)_
@@ -11,41 +11,28 @@ export function indexOf<Item>(array: Item[], value: Item): number;
11
11
  */
12
12
  export function indexOf<Item>(
13
13
  array: Item[],
14
- matches: BooleanCallback<Item>,
14
+ matches: (item: Item, index: number, array: Item[]) => boolean,
15
15
  ): number;
16
16
 
17
17
  /**
18
18
  * - Get the index for the first matching item _(or `-1` if no match is found)_
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function indexOf<Item, Key extends keyof Item>(
21
+ export function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(
22
22
  array: Item[],
23
- key: Key,
24
- value: Item[Key],
23
+ key: ItemKey,
24
+ value: Item[ItemKey],
25
25
  ): number;
26
26
 
27
27
  /**
28
28
  * - Get the index for the first matching item _(or `-1` if no match is found)_
29
29
  * - Use `key` to find a comparison value to match with `value`
30
30
  */
31
- export function indexOf<Item, Key extends KeyCallback<Item>>(
32
- array: Item[],
33
- key: Key,
34
- value: ReturnType<Key>,
35
- ): number;
31
+ export function indexOf<
32
+ Item,
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
36
35
 
37
36
  export function indexOf(array: unknown[], ...parameters: unknown[]): number {
38
- const {length} = parameters;
39
-
40
- return findValue(
41
- 'index',
42
- array,
43
- length === 1 && typeof parameters[0] === 'function'
44
- ? parameters[0]
45
- : undefined,
46
- length === 2 ? parameters[0] : undefined,
47
- length === 1 && typeof parameters[0] !== 'function'
48
- ? parameters[0]
49
- : parameters[1],
50
- ) as number;
37
+ return findValue('index', array, parameters) as number;
51
38
  }
@@ -1,13 +1,5 @@
1
1
  import type {GenericCallback, Key} from '~/models';
2
2
 
3
- export type ArrayCallback<Item, Value> = (
4
- item: Item,
5
- index: number,
6
- array: Item[],
7
- ) => Value;
8
-
9
- export type BooleanCallback<Item> = ArrayCallback<Item, boolean>;
10
-
11
3
  export type Callbacks = {
12
4
  bool?: GenericCallback;
13
5
  key?: GenericCallback;
@@ -18,18 +10,12 @@ export type FindType = 'index' | 'value';
18
10
 
19
11
  export type InsertType = 'push' | 'splice';
20
12
 
21
- export type KeyCallback<Item> = ArrayCallback<Item, Key>;
22
-
23
13
  export type SortKey<Item> = {
24
14
  direction: 'asc' | 'desc';
25
- value: Key | SortKeyCallback<Item>;
15
+ value: Key | ((item: Item) => Key);
26
16
  };
27
17
 
28
- export type SortKeyCallback<Item> = (item: Item) => unknown;
29
-
30
18
  export type SortKeyWithCallback<Item> = {
31
- callback: SortKeyCallback<Item>;
19
+ callback: (item: Item) => Key;
32
20
  direction: 'asc' | 'desc';
33
21
  };
34
-
35
- export type ValueCallback<Item> = ArrayCallback<Item, unknown>;
@@ -1,8 +1,4 @@
1
- import type {
2
- SortKey,
3
- SortKeyCallback,
4
- SortKeyWithCallback,
5
- } from '~/array/models';
1
+ import type {SortKey, SortKeyWithCallback} from '~/array/models';
6
2
  import {isKey} from '~/is';
7
3
  import type {Key, PlainObject} from '~/models';
8
4
  import {compare} from '~/value/compare';
@@ -18,7 +14,17 @@ export function sort<Item>(array: Item[], descending?: boolean): Item[];
18
14
  */
19
15
  export function sort<Item>(
20
16
  array: Item[],
21
- key: Key | SortKey<Item> | SortKeyCallback<Item>,
17
+ key: Key | SortKey<Item> | ((item: Item) => Key),
18
+ descending?: boolean,
19
+ ): Item[];
20
+
21
+ /**
22
+ * - Sort an array of items, using a `key` to sort by a specific value
23
+ * - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
24
+ */
25
+ export function sort<Item extends PlainObject, ItemKey extends keyof Item>(
26
+ array: Item[],
27
+ key: ItemKey | Key | SortKey<Item> | ((item: Item) => Key),
22
28
  descending?: boolean,
23
29
  ): Item[];
24
30
 
@@ -28,7 +34,17 @@ export function sort<Item>(
28
34
  */
29
35
  export function sort<Item>(
30
36
  array: Item[],
31
- keys: Array<Key | SortKey<Item> | SortKeyCallback<Item>>,
37
+ keys: Array<Key | SortKey<Item> | ((item: Item) => Key)>,
38
+ descending?: boolean,
39
+ ): Item[];
40
+
41
+ /**
42
+ * - Sort an array of items, using multiple `keys` to sort by specific values
43
+ * - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
44
+ */
45
+ export function sort<Item extends PlainObject, ItemKey extends keyof Item>(
46
+ array: Item[],
47
+ keys: Array<ItemKey | Key | SortKey<Item> | ((item: Item) => Key)>,
32
48
  descending?: boolean,
33
49
  ): Item[];
34
50
 
@@ -1,6 +1,5 @@
1
- import type {KeyCallback, ValueCallback} from '~/array/models';
2
1
  import {getCallbacks} from '~/internal/array/callbacks';
3
- import type {Key, KeyedValue} from '~/models';
2
+ import type {Key, KeyedValue, PlainObject} from '~/models';
4
3
 
5
4
  /**
6
5
  * Create a map from an array of items _(using their indices as keys)_
@@ -10,117 +9,124 @@ export function toMap<Item>(array: Item[]): Map<number, Item>;
10
9
  /**
11
10
  * Create a map from an array of items using a specific key
12
11
  */
13
- export function toMap<Item, Key extends keyof Item>(
12
+ export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
14
13
  array: Item[],
15
- key: Key,
16
- ): Map<KeyedValue<Item, Key>, Item>;
14
+ key: ItemKey,
15
+ ): Map<KeyedValue<Item, ItemKey>, Item>;
17
16
 
18
17
  /**
19
18
  * Create a map from an array of items using a specific key, and grouping them into arrays
20
19
  */
21
- export function toMap<Item, Key extends keyof Item>(
20
+ export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
22
21
  array: Item[],
23
- key: Key,
22
+ key: ItemKey,
24
23
  arrays: true,
25
- ): Map<KeyedValue<Item, Key>, Item[]>;
24
+ ): Map<KeyedValue<Item, ItemKey>, Item[]>;
26
25
 
27
26
  /**
28
27
  * Create a map from an array of items using a specific key
29
28
  */
30
- export function toMap<Item, Key extends KeyCallback<Item>>(
31
- array: Item[],
32
- key: Key,
33
- ): Map<ReturnType<Key>, Item>;
29
+ export function toMap<
30
+ Item,
31
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
32
+ >(array: Item[], key: ItemKey): Map<ReturnType<ItemKey>, Item>;
34
33
 
35
34
  /**
36
35
  * Create a map from an array of items using a specific key, and grouping them into arrays
37
36
  */
38
- export function toMap<Item, Key extends KeyCallback<Item>>(
39
- array: Item[],
40
- key: Key,
41
- arrays: true,
42
- ): Map<ReturnType<Key>, Item[]>;
37
+ export function toMap<
38
+ Item,
39
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
40
+ >(array: Item[], key: ItemKey, arrays: true): Map<ReturnType<ItemKey>, Item[]>;
43
41
 
44
42
  /**
45
43
  * Create a map from an array of items using a specific key and value
46
44
  */
47
- export function toMap<Item, Key extends keyof Item, Value extends keyof Item>(
45
+ export function toMap<
46
+ Item extends PlainObject,
47
+ ItemKey extends keyof Item,
48
+ ItemValue extends keyof Item,
49
+ >(
48
50
  array: Item[],
49
- key: Key,
50
- value: Value,
51
- ): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
51
+ key: ItemKey,
52
+ value: ItemValue,
53
+ ): Map<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
52
54
 
53
55
  /**
54
56
  * Create a map from an array of items using a specific key and value, and grouping them into arrays
55
57
  */
56
- export function toMap<Item, Key extends keyof Item, Value extends keyof Item>(
58
+ export function toMap<
59
+ Item extends PlainObject,
60
+ ItemKey extends keyof Item,
61
+ ItemValue extends keyof Item,
62
+ >(
57
63
  array: Item[],
58
- key: Key,
59
- value: Value,
64
+ key: ItemKey,
65
+ value: ItemValue,
60
66
  arrays: true,
61
- ): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
67
+ ): Map<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
62
68
 
63
69
  /**
64
70
  * Create a map from an array of items using a specific key and value
65
71
  */
66
72
  export function toMap<
67
- Item,
68
- Key extends keyof Item,
69
- Value extends ValueCallback<Item>,
73
+ Item extends PlainObject,
74
+ ItemKey extends keyof Item,
75
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
70
76
  >(
71
77
  array: Item[],
72
- key: Key,
73
- value: Value,
74
- ): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
78
+ key: ItemKey,
79
+ value: ItemValue,
80
+ ): Map<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
75
81
 
76
82
  /**
77
83
  * Create a map from an array of items using a specific key and value, and grouping them into arrays
78
84
  */
79
85
  export function toMap<
80
- Item,
81
- Key extends keyof Item,
82
- Value extends ValueCallback<Item>,
86
+ Item extends PlainObject,
87
+ ItemKey extends keyof Item,
88
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
83
89
  >(
84
90
  array: Item[],
85
- key: Key,
86
- value: Value,
91
+ key: ItemKey,
92
+ value: ItemValue,
87
93
  arrays: true,
88
- ): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
94
+ ): Map<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
89
95
 
90
96
  /**
91
97
  * Create a map from an array of items using a specific key and value
92
98
  */
93
99
  export function toMap<
94
- Item,
95
- Key extends KeyCallback<Item>,
96
- Value extends keyof Item,
100
+ Item extends PlainObject,
101
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
102
+ ItemValue extends keyof Item,
97
103
  >(
98
104
  array: Item[],
99
- key: Key,
100
- value: Value,
101
- ): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
105
+ key: ItemKey,
106
+ value: ItemValue,
107
+ ): Map<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
102
108
 
103
109
  /**
104
110
  * Create a map from an array of items using a specific key and value, and grouping them into arrays
105
111
  */
106
112
  export function toMap<
107
- Item,
108
- Key extends KeyCallback<Item>,
109
- Value extends keyof Item,
113
+ Item extends PlainObject,
114
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
115
+ ItemValue extends keyof Item,
110
116
  >(
111
117
  array: Item[],
112
- key: Key,
113
- value: Value,
118
+ key: ItemKey,
119
+ value: ItemValue,
114
120
  arrays: true,
115
- ): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
121
+ ): Map<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
116
122
 
117
123
  /**
118
124
  * Create a map from an array of items using a specific key and value
119
125
  */
120
126
  export function toMap<
121
127
  Item,
122
- Key extends KeyCallback<Item>,
123
- Value extends ValueCallback<Item>,
128
+ Key extends (item: Item, index: number, array: Item[]) => Key,
129
+ Value extends (item: Item, index: number, array: Item[]) => unknown,
124
130
  >(
125
131
  array: Item[],
126
132
  key: Key,
@@ -132,8 +138,8 @@ export function toMap<
132
138
  */
133
139
  export function toMap<
134
140
  Item,
135
- Key extends KeyCallback<Item>,
136
- Value extends ValueCallback<Item>,
141
+ Key extends (item: Item, index: number, array: Item[]) => Key,
142
+ Value extends (item: Item, index: number, array: Item[]) => unknown,
137
143
  >(
138
144
  array: Item[],
139
145
  key: Key,