@oscarpalmer/atoms 0.77.0 → 0.77.2

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 (54) hide show
  1. package/dist/js/array/chunk.cjs +1 -1
  2. package/dist/js/array/chunk.js +1 -1
  3. package/dist/js/value/equal.cjs +4 -1
  4. package/dist/js/value/equal.js +4 -1
  5. package/package.json +1 -1
  6. package/src/js/array/chunk.ts +1 -1
  7. package/src/js/array/count.ts +6 -6
  8. package/src/js/array/exists.ts +6 -6
  9. package/src/js/array/filter.ts +6 -6
  10. package/src/js/array/find.ts +6 -6
  11. package/src/js/array/group-by.ts +67 -55
  12. package/src/js/array/index-of.ts +6 -6
  13. package/src/js/array/sort.ts +20 -0
  14. package/src/js/array/to-map.ts +55 -47
  15. package/src/js/array/to-record.ts +61 -57
  16. package/src/js/array/unique.ts +6 -6
  17. package/src/js/internal/value/handle.ts +5 -5
  18. package/src/js/value/clone.ts +3 -1
  19. package/src/js/value/equal.ts +4 -1
  20. package/src/js/value/get.ts +9 -9
  21. package/src/js/value/set.ts +10 -11
  22. package/types/array/count.d.cts +34 -2
  23. package/types/array/count.d.ts +3 -3
  24. package/types/array/exists.d.cts +34 -2
  25. package/types/array/exists.d.ts +3 -3
  26. package/types/array/filter.d.cts +34 -2
  27. package/types/array/filter.d.ts +3 -3
  28. package/types/array/find.d.cts +34 -2
  29. package/types/array/find.d.ts +3 -3
  30. package/types/array/group-by.d.cts +44 -12
  31. package/types/array/group-by.d.ts +14 -14
  32. package/types/array/index-of.d.cts +34 -2
  33. package/types/array/index-of.d.ts +3 -3
  34. package/types/array/index.d.cts +88 -46
  35. package/types/array/sort.d.cts +42 -0
  36. package/types/array/sort.d.ts +11 -1
  37. package/types/array/to-map.d.cts +42 -10
  38. package/types/array/to-map.d.ts +13 -13
  39. package/types/array/to-record.d.cts +44 -12
  40. package/types/array/to-record.d.ts +13 -13
  41. package/types/array/unique.d.cts +34 -2
  42. package/types/array/unique.d.ts +3 -3
  43. package/types/index.d.cts +1034 -317
  44. package/types/internal/value/handle.d.cts +27 -2
  45. package/types/internal/value/handle.d.ts +2 -2
  46. package/types/models.d.cts +467 -210
  47. package/types/value/clone.d.cts +1 -1
  48. package/types/value/clone.d.ts +1 -1
  49. package/types/value/get.d.cts +470 -211
  50. package/types/value/get.d.ts +3 -3
  51. package/types/value/index.d.cts +515 -224
  52. package/types/value/set.d.cts +357 -170
  53. package/types/value/set.d.ts +3 -3
  54. package/types/value/smush.d.cts +463 -209
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const number = require("../number.cjs");
4
4
  function chunk(array, size) {
5
- const chunkSize = number.clamp(size ?? 64e3, 1, 64e3);
5
+ const chunkSize = number.clamp(size ?? 5e3, 1, 5e3);
6
6
  const { length } = array;
7
7
  if (length <= chunkSize) {
8
8
  return [array];
@@ -1,6 +1,6 @@
1
1
  import { clamp } from "../number.js";
2
2
  function chunk(array, size) {
3
- const chunkSize = clamp(size ?? 64e3, 1, 64e3);
3
+ const chunkSize = clamp(size ?? 5e3, 1, 5e3);
4
4
  const { length } = array;
5
5
  if (length <= chunkSize) {
6
6
  return [array];
@@ -40,7 +40,10 @@ function equalArrayBuffer(first, second) {
40
40
  ) : false;
41
41
  }
42
42
  function equalDataView(first, second) {
43
- return first.byteOffset === second.byteOffset ? equalArrayBuffer(first.buffer, second.buffer) : false;
43
+ return first.byteOffset === second.byteOffset ? equalArrayBuffer(
44
+ first.buffer,
45
+ second.buffer
46
+ ) : false;
44
47
  }
45
48
  function equalMap(first, second) {
46
49
  const { size } = first;
@@ -38,7 +38,10 @@ function equalArrayBuffer(first, second) {
38
38
  ) : false;
39
39
  }
40
40
  function equalDataView(first, second) {
41
- return first.byteOffset === second.byteOffset ? equalArrayBuffer(first.buffer, second.buffer) : false;
41
+ return first.byteOffset === second.byteOffset ? equalArrayBuffer(
42
+ first.buffer,
43
+ second.buffer
44
+ ) : false;
42
45
  }
43
46
  function equalMap(first, second) {
44
47
  const { size } = first;
package/package.json CHANGED
@@ -237,5 +237,5 @@
237
237
  },
238
238
  "type": "module",
239
239
  "types": "./types/index.d.cts",
240
- "version": "0.77.0"
240
+ "version": "0.77.2"
241
241
  }
@@ -4,7 +4,7 @@ import {clamp} from '~/number';
4
4
  * Chunk an array _(into smaller arrays of a specified size)_
5
5
  */
6
6
  export function chunk<Item>(array: Item[], size?: number): Item[][] {
7
- const chunkSize = clamp(size ?? 64_000, 1, 64_000);
7
+ const chunkSize = clamp(size ?? 5_000, 1, 5_000);
8
8
  const {length} = array;
9
9
 
10
10
  if (length <= chunkSize) {
@@ -1,5 +1,5 @@
1
1
  import {findValues} from '~/internal/array/find';
2
- import type {Key as SimpleKey} from '~/models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the number of items _(count)_ that match the given value
@@ -17,10 +17,10 @@ export function count<Item>(
17
17
  /**
18
18
  * Get the number of items _(count)_ that match the given value
19
19
  */
20
- export function count<Item, Key extends keyof Item>(
20
+ export function count<Item extends PlainObject, ItemKey extends keyof Item>(
21
21
  array: Item[],
22
- key: Key,
23
- value: Item[Key],
22
+ key: ItemKey,
23
+ value: Item[ItemKey],
24
24
  ): number;
25
25
 
26
26
  /**
@@ -28,8 +28,8 @@ export function count<Item, Key extends keyof Item>(
28
28
  */
29
29
  export function count<
30
30
  Item,
31
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
32
- >(array: Item[], key: Key, value: ReturnType<Key>): number;
31
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
32
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
33
33
 
34
34
  export function count(array: unknown[], ...parameters: unknown[]): number {
35
35
  return findValues('all', array, parameters).length;
@@ -1,5 +1,5 @@
1
1
  import {findValue} from '~/internal/array/find';
2
- import type {Key as SimpleKey} from '~/models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Does the value exist in array?
@@ -18,10 +18,10 @@ export function exists<Item>(
18
18
  * - Does the value exist in array?
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function exists<Item, Key extends keyof Item>(
21
+ export function exists<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
  ): boolean;
26
26
 
27
27
  /**
@@ -30,8 +30,8 @@ export function exists<Item, Key extends keyof Item>(
30
30
  */
31
31
  export function exists<
32
32
  Item,
33
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
- >(array: Item[], key: Key, value: ReturnType<Key>): boolean;
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): boolean;
35
35
 
36
36
  export function exists(array: unknown[], ...parameters: unknown[]): boolean {
37
37
  return (findValue('index', array, parameters) as number) > -1;
@@ -1,5 +1,5 @@
1
1
  import {findValues} from '~/internal/array/find';
2
- import type {Key as SimpleKey} from '~/models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get a filtered array of items matching `value`
@@ -18,10 +18,10 @@ export function filter<Item>(
18
18
  * - Get a filtered array of items
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function filter<Item, Key extends keyof Item>(
21
+ export function filter<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
  ): Item[];
26
26
 
27
27
  /**
@@ -30,8 +30,8 @@ export function filter<Item, Key extends keyof Item>(
30
30
  */
31
31
  export function filter<
32
32
  Item,
33
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
- >(array: Item[], key: Key, value: ReturnType<Key>): Item[];
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item[];
35
35
 
36
36
  export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
37
37
  return findValues('all', array, parameters);
@@ -1,5 +1,5 @@
1
1
  import {findValue} from '~/internal/array/find';
2
- import type {Key as SimpleKey} from '~/models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get the first item matching `value` _(or `undefined` if no match is found)_
@@ -18,10 +18,10 @@ export function find<Item>(
18
18
  * - Get the first matching item _(or `undefined` if no match is found)_
19
19
  * - Use `key` to find a comparison value to match with `value`
20
20
  */
21
- export function find<Item, Key extends keyof Item>(
21
+ export function find<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
  ): Item | undefined;
26
26
 
27
27
  /**
@@ -30,8 +30,8 @@ export function find<Item, Key extends keyof Item>(
30
30
  */
31
31
  export function find<
32
32
  Item,
33
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
- >(array: Item[], key: Key, value: ReturnType<Key>): Item | undefined;
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item | undefined;
35
35
 
36
36
  export function find<Item>(
37
37
  array: unknown[],
@@ -1,138 +1,150 @@
1
1
  import {getCallbacks} from '~/internal/array/callbacks';
2
- import type {Key as SimpleKey, KeyedValue, PlainObject} from '~/models';
2
+ import type {Key, KeyedValue, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Create a record from an array of items using a specific key
6
6
  */
7
- export function groupBy<Item, Key extends keyof Item>(
7
+ export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
8
8
  array: Item[],
9
- key: Key,
10
- ): Record<KeyedValue<Item, Key>, Item>;
9
+ key: ItemKey,
10
+ ): Record<KeyedValue<Item, ItemKey>, Item>;
11
11
 
12
12
  /**
13
13
  * Create a record from an array of items using a specific key, and grouping them into arrays
14
14
  */
15
- export function groupBy<Item, Key extends keyof Item>(
15
+ export function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
16
16
  array: Item[],
17
- key: Key,
17
+ key: ItemKey,
18
18
  arrays: true,
19
- ): Record<KeyedValue<Item, Key>, Item[]>;
19
+ ): Record<KeyedValue<Item, ItemKey>, Item[]>;
20
20
 
21
21
  /**
22
22
  * Create a record from an array of items using a specific key
23
23
  */
24
24
  export function groupBy<
25
25
  Item,
26
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
27
- >(array: Item[], key: Key): Record<ReturnType<Key>, Item>;
26
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
27
+ >(array: Item[], key: ItemKey): Record<ReturnType<ItemKey>, Item>;
28
28
 
29
29
  /**
30
30
  * Create a record from an array of items using a specific key, and grouping them into arrays
31
31
  */
32
32
  export function groupBy<
33
33
  Item,
34
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
35
- >(array: Item[], key: Key, arrays: true): Record<ReturnType<Key>, Item[]>;
34
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
35
+ >(
36
+ array: Item[],
37
+ key: ItemKey,
38
+ arrays: true,
39
+ ): Record<ReturnType<ItemKey>, Item[]>;
36
40
 
37
41
  /**
38
42
  * Create a record from an array of items using a specific key and value
39
43
  */
40
- 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
+ >(
41
49
  array: Item[],
42
- key: Key,
43
- value: Value,
44
- ): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
50
+ key: ItemKey,
51
+ value: ItemValue,
52
+ ): Record<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
45
53
 
46
54
  /**
47
55
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
48
56
  */
49
- 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
+ >(
50
62
  array: Item[],
51
- key: Key,
52
- value: Value,
63
+ key: ItemKey,
64
+ value: ItemValue,
53
65
  arrays: true,
54
- ): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
66
+ ): Record<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
55
67
 
56
68
  /**
57
69
  * Create a record from an array of items using a specific key and value
58
70
  */
59
71
  export function groupBy<
60
- Item,
61
- Key extends keyof Item,
62
- Value extends (item: Item, index: number, array: Item[]) => unknown,
72
+ Item extends PlainObject,
73
+ ItemKey extends keyof Item,
74
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
63
75
  >(
64
76
  array: Item[],
65
- key: Key,
66
- value: Value,
67
- ): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
77
+ key: ItemKey,
78
+ value: ItemValue,
79
+ ): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
68
80
 
69
81
  /**
70
82
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
71
83
  */
72
84
  export function groupBy<
73
- Item,
74
- Key extends keyof Item,
75
- Value extends (item: Item, index: number, array: Item[]) => unknown,
85
+ Item extends PlainObject,
86
+ ItemKey extends keyof Item,
87
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
76
88
  >(
77
89
  array: Item[],
78
- key: Key,
79
- value: Value,
90
+ key: ItemKey,
91
+ value: ItemValue,
80
92
  arrays: true,
81
- ): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
93
+ ): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
82
94
 
83
95
  /**
84
96
  * Create a record from an array of items using a specific key and value
85
97
  */
86
98
  export function groupBy<
87
- Item,
88
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
89
- Value extends keyof Item,
99
+ Item extends PlainObject,
100
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
101
+ ItemValue extends keyof Item,
90
102
  >(
91
103
  array: Item[],
92
- key: Key,
93
- value: Value,
94
- ): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
104
+ key: ItemKey,
105
+ value: ItemValue,
106
+ ): Record<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
95
107
 
96
108
  /**
97
109
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
98
110
  */
99
111
  export function groupBy<
100
- Item,
101
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
102
- Value extends keyof Item,
112
+ Item extends PlainObject,
113
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
114
+ ItemValue extends keyof Item,
103
115
  >(
104
116
  array: Item[],
105
- key: Key,
106
- value: Value,
117
+ key: ItemKey,
118
+ value: ItemValue,
107
119
  arrays: true,
108
- ): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
120
+ ): Record<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
109
121
 
110
122
  /**
111
123
  * Create a record from an array of items using a specific key and value
112
124
  */
113
125
  export function groupBy<
114
126
  Item,
115
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
116
- Value extends (item: Item, index: number, array: Item[]) => unknown,
127
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
128
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
117
129
  >(
118
130
  array: Item[],
119
- key: Key,
120
- value: Value,
121
- ): Record<ReturnType<Key>, ReturnType<Value>>;
131
+ key: ItemKey,
132
+ value: ItemValue,
133
+ ): Record<ReturnType<ItemKey>, ReturnType<ItemValue>>;
122
134
 
123
135
  /**
124
136
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
125
137
  */
126
138
  export function groupBy<
127
139
  Item,
128
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
129
- Value extends (item: Item, index: number, array: Item[]) => unknown,
140
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
141
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
130
142
  >(
131
143
  array: Item[],
132
- key: Key,
133
- value: Value,
144
+ key: ItemKey,
145
+ value: ItemValue,
134
146
  arrays: true,
135
- ): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
147
+ ): Record<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
136
148
 
137
149
  export function groupBy(
138
150
  array: unknown[],
@@ -153,9 +165,9 @@ export function groupValues(
153
165
  key: unknown,
154
166
  value: unknown,
155
167
  arrays: boolean,
156
- ): Record<SimpleKey, unknown> {
168
+ ): Record<Key, unknown> {
157
169
  const callbacks = getCallbacks(undefined, key, value);
158
- const record: Record<SimpleKey, unknown> = {};
170
+ const record: Record<Key, unknown> = {};
159
171
  const {length} = array;
160
172
 
161
173
  for (let index = 0; index < length; index += 1) {
@@ -1,5 +1,5 @@
1
1
  import {findValue} from '~/internal/array/find';
2
- import type {Key as SimpleKey} from '~/models';
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)_
@@ -18,10 +18,10 @@ export function indexOf<Item>(
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
  /**
@@ -30,8 +30,8 @@ export function indexOf<Item, Key extends keyof Item>(
30
30
  */
31
31
  export function indexOf<
32
32
  Item,
33
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
34
- >(array: Item[], key: Key, value: ReturnType<Key>): number;
33
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
34
+ >(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
35
35
 
36
36
  export function indexOf(array: unknown[], ...parameters: unknown[]): number {
37
37
  return findValue('index', array, parameters) as number;
@@ -18,6 +18,16 @@ export function sort<Item>(
18
18
  descending?: boolean,
19
19
  ): Item[];
20
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),
28
+ descending?: boolean,
29
+ ): Item[];
30
+
21
31
  /**
22
32
  * - Sort an array of items, using multiple `keys` to sort by specific values
23
33
  * - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
@@ -28,6 +38,16 @@ export function sort<Item>(
28
38
  descending?: boolean,
29
39
  ): Item[];
30
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)>,
48
+ descending?: boolean,
49
+ ): Item[];
50
+
31
51
  export function sort(
32
52
  array: unknown[],
33
53
  first?: unknown,
@@ -1,5 +1,5 @@
1
1
  import {getCallbacks} from '~/internal/array/callbacks';
2
- import type {KeyedValue, Key as SimpleKey} from '~/models';
2
+ import type {Key, KeyedValue, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Create a map from an array of items _(using their indices as keys)_
@@ -9,115 +9,123 @@ export function toMap<Item>(array: Item[]): Map<number, Item>;
9
9
  /**
10
10
  * Create a map from an array of items using a specific key
11
11
  */
12
- export function toMap<Item, Key extends keyof Item>(
12
+ export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
13
13
  array: Item[],
14
- key: Key,
15
- ): Map<KeyedValue<Item, Key>, Item>;
14
+ key: ItemKey,
15
+ ): Map<KeyedValue<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
19
19
  */
20
- export function toMap<Item, Key extends keyof Item>(
20
+ export function toMap<Item extends PlainObject, ItemKey extends keyof Item>(
21
21
  array: Item[],
22
- key: Key,
22
+ key: ItemKey,
23
23
  arrays: true,
24
- ): Map<KeyedValue<Item, Key>, Item[]>;
24
+ ): Map<KeyedValue<Item, ItemKey>, Item[]>;
25
25
 
26
26
  /**
27
27
  * Create a map from an array of items using a specific key
28
28
  */
29
29
  export function toMap<
30
30
  Item,
31
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
32
- >(array: Item[], key: Key): Map<ReturnType<Key>, Item>;
31
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
32
+ >(array: Item[], key: ItemKey): Map<ReturnType<ItemKey>, Item>;
33
33
 
34
34
  /**
35
35
  * Create a map from an array of items using a specific key, and grouping them into arrays
36
36
  */
37
37
  export function toMap<
38
38
  Item,
39
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
40
- >(array: Item[], key: Key, arrays: true): Map<ReturnType<Key>, Item[]>;
39
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
40
+ >(array: Item[], key: ItemKey, arrays: true): Map<ReturnType<ItemKey>, Item[]>;
41
41
 
42
42
  /**
43
43
  * Create a map from an array of items using a specific key and value
44
44
  */
45
- 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
+ >(
46
50
  array: Item[],
47
- key: Key,
48
- value: Value,
49
- ): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
51
+ key: ItemKey,
52
+ value: ItemValue,
53
+ ): Map<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
50
54
 
51
55
  /**
52
56
  * Create a map from an array of items using a specific key and value, and grouping them into arrays
53
57
  */
54
- 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
+ >(
55
63
  array: Item[],
56
- key: Key,
57
- value: Value,
64
+ key: ItemKey,
65
+ value: ItemValue,
58
66
  arrays: true,
59
- ): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
67
+ ): Map<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
60
68
 
61
69
  /**
62
70
  * Create a map from an array of items using a specific key and value
63
71
  */
64
72
  export function toMap<
65
- Item,
66
- Key extends keyof Item,
67
- Value extends (item: Item, index: number, array: Item[]) => unknown,
73
+ Item extends PlainObject,
74
+ ItemKey extends keyof Item,
75
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
68
76
  >(
69
77
  array: Item[],
70
- key: Key,
71
- value: Value,
72
- ): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
78
+ key: ItemKey,
79
+ value: ItemValue,
80
+ ): Map<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
73
81
 
74
82
  /**
75
83
  * Create a map from an array of items using a specific key and value, and grouping them into arrays
76
84
  */
77
85
  export function toMap<
78
- Item,
79
- Key extends keyof Item,
80
- Value extends (item: Item, index: number, array: Item[]) => unknown,
86
+ Item extends PlainObject,
87
+ ItemKey extends keyof Item,
88
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
81
89
  >(
82
90
  array: Item[],
83
- key: Key,
84
- value: Value,
91
+ key: ItemKey,
92
+ value: ItemValue,
85
93
  arrays: true,
86
- ): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
94
+ ): Map<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
87
95
 
88
96
  /**
89
97
  * Create a map from an array of items using a specific key and value
90
98
  */
91
99
  export function toMap<
92
- Item,
93
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
94
- Value extends keyof Item,
100
+ Item extends PlainObject,
101
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
102
+ ItemValue extends keyof Item,
95
103
  >(
96
104
  array: Item[],
97
- key: Key,
98
- value: Value,
99
- ): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
105
+ key: ItemKey,
106
+ value: ItemValue,
107
+ ): Map<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
100
108
 
101
109
  /**
102
110
  * Create a map from an array of items using a specific key and value, and grouping them into arrays
103
111
  */
104
112
  export function toMap<
105
- Item,
106
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
107
- Value extends keyof Item,
113
+ Item extends PlainObject,
114
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
115
+ ItemValue extends keyof Item,
108
116
  >(
109
117
  array: Item[],
110
- key: Key,
111
- value: Value,
118
+ key: ItemKey,
119
+ value: ItemValue,
112
120
  arrays: true,
113
- ): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
121
+ ): Map<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
114
122
 
115
123
  /**
116
124
  * Create a map from an array of items using a specific key and value
117
125
  */
118
126
  export function toMap<
119
127
  Item,
120
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
128
+ Key extends (item: Item, index: number, array: Item[]) => Key,
121
129
  Value extends (item: Item, index: number, array: Item[]) => unknown,
122
130
  >(
123
131
  array: Item[],
@@ -130,7 +138,7 @@ export function toMap<
130
138
  */
131
139
  export function toMap<
132
140
  Item,
133
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
141
+ Key extends (item: Item, index: number, array: Item[]) => Key,
134
142
  Value extends (item: Item, index: number, array: Item[]) => unknown,
135
143
  >(
136
144
  array: Item[],
@@ -144,10 +152,10 @@ export function toMap(
144
152
  first?: unknown,
145
153
  second?: unknown,
146
154
  third?: unknown,
147
- ): Map<SimpleKey, unknown> {
155
+ ): Map<Key, unknown> {
148
156
  const asArrays = first === true || second === true || third === true;
149
157
  const callbacks = getCallbacks(undefined, first, second);
150
- const map = new Map<SimpleKey, unknown>();
158
+ const map = new Map<Key, unknown>();
151
159
  const {length} = array;
152
160
 
153
161
  for (let index = 0; index < length; index += 1) {