@oscarpalmer/atoms 0.119.0 → 0.120.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/dist/array/group-by.js +9 -2
- package/dist/array/to-map.js +9 -2
- package/dist/array/to-record.js +9 -2
- package/dist/atoms.full.js +56 -26
- package/dist/internal/value/equal.js +9 -6
- package/dist/string/template.js +11 -8
- package/dist/value/merge.js +9 -6
- package/package.json +3 -3
- package/src/array/group-by.ts +128 -118
- package/src/array/to-map.ts +143 -153
- package/src/array/to-record.ts +128 -118
- package/src/internal/value/equal.ts +31 -33
- package/src/string/template.ts +26 -26
- package/src/value/merge.ts +21 -28
- package/types/array/group-by.d.ts +72 -73
- package/types/array/to-map.d.ts +72 -73
- package/types/array/to-record.d.ts +72 -73
- package/types/internal/value/equal.d.ts +24 -25
- package/types/string/template.d.ts +16 -17
- package/types/value/merge.d.ts +15 -16
package/dist/array/group-by.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { groupValues } from "../internal/array/group.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
function groupBy(array, first, second) {
|
|
3
|
+
return groupValues(array, first, second, false);
|
|
4
|
+
}
|
|
5
|
+
(function(_groupBy) {
|
|
6
|
+
function arrays(array, first, second) {
|
|
7
|
+
return groupValues(array, first, second, true);
|
|
8
|
+
}
|
|
9
|
+
_groupBy.arrays = arrays;
|
|
10
|
+
})(groupBy || (groupBy = {}));
|
|
4
11
|
export { groupBy };
|
package/dist/array/to-map.js
CHANGED
|
@@ -16,6 +16,13 @@ function getMapValues(array, first, second, arrays) {
|
|
|
16
16
|
}
|
|
17
17
|
return map;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
function toMap(array, first, second) {
|
|
20
|
+
return getMapValues(array, first, second, false);
|
|
21
|
+
}
|
|
22
|
+
(function(_toMap) {
|
|
23
|
+
function arrays(array, first, second) {
|
|
24
|
+
return getMapValues(array, first, second, true);
|
|
25
|
+
}
|
|
26
|
+
_toMap.arrays = arrays;
|
|
27
|
+
})(toMap || (toMap = {}));
|
|
21
28
|
export { toMap };
|
package/dist/array/to-record.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { groupValues } from "../internal/array/group.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
function toRecord(array, first, second) {
|
|
3
|
+
return groupValues(array, first, second, false);
|
|
4
|
+
}
|
|
5
|
+
(function(_toRecord) {
|
|
6
|
+
function arrays(array, first, second) {
|
|
7
|
+
return groupValues(array, first, second, true);
|
|
8
|
+
}
|
|
9
|
+
_toRecord.arrays = arrays;
|
|
10
|
+
})(toRecord || (toRecord = {}));
|
|
4
11
|
export { toRecord };
|
package/dist/atoms.full.js
CHANGED
|
@@ -206,8 +206,15 @@ function groupValues(array, key, value, arrays) {
|
|
|
206
206
|
}
|
|
207
207
|
return record;
|
|
208
208
|
}
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
function groupBy(array, first, second) {
|
|
210
|
+
return groupValues(array, first, second, false);
|
|
211
|
+
}
|
|
212
|
+
(function(_groupBy) {
|
|
213
|
+
function arrays(array, first, second) {
|
|
214
|
+
return groupValues(array, first, second, true);
|
|
215
|
+
}
|
|
216
|
+
_groupBy.arrays = arrays;
|
|
217
|
+
})(groupBy || (groupBy = {}));
|
|
211
218
|
function indexOf(array, ...parameters) {
|
|
212
219
|
return findValue("index", array, parameters);
|
|
213
220
|
}
|
|
@@ -435,10 +442,24 @@ function getMapValues(array, first, second, arrays) {
|
|
|
435
442
|
}
|
|
436
443
|
return map;
|
|
437
444
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
445
|
+
function toMap(array, first, second) {
|
|
446
|
+
return getMapValues(array, first, second, false);
|
|
447
|
+
}
|
|
448
|
+
(function(_toMap) {
|
|
449
|
+
function arrays(array, first, second) {
|
|
450
|
+
return getMapValues(array, first, second, true);
|
|
451
|
+
}
|
|
452
|
+
_toMap.arrays = arrays;
|
|
453
|
+
})(toMap || (toMap = {}));
|
|
454
|
+
function toRecord(array, first, second) {
|
|
455
|
+
return groupValues(array, first, second, false);
|
|
456
|
+
}
|
|
457
|
+
(function(_toRecord) {
|
|
458
|
+
function arrays(array, first, second) {
|
|
459
|
+
return groupValues(array, first, second, true);
|
|
460
|
+
}
|
|
461
|
+
_toRecord.arrays = arrays;
|
|
462
|
+
})(toRecord || (toRecord = {}));
|
|
442
463
|
function toSet(array, value) {
|
|
443
464
|
if (!Array.isArray(array)) return /* @__PURE__ */ new Set();
|
|
444
465
|
const callbacks = getArrayCallbacks(void 0, void 0, value);
|
|
@@ -1660,24 +1681,30 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
|
1660
1681
|
return values[key];
|
|
1661
1682
|
});
|
|
1662
1683
|
}
|
|
1663
|
-
|
|
1684
|
+
function template(value, variables, options) {
|
|
1664
1685
|
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
1665
1686
|
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
return
|
|
1671
|
-
|
|
1672
|
-
};
|
|
1687
|
+
}
|
|
1688
|
+
(function(_template) {
|
|
1689
|
+
function initialize(options) {
|
|
1690
|
+
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
1691
|
+
return (value, variables) => {
|
|
1692
|
+
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
_template.initialize = initialize;
|
|
1696
|
+
})(template || (template = {}));
|
|
1673
1697
|
const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
1674
|
-
|
|
1698
|
+
function equal(first, second, options) {
|
|
1675
1699
|
return equalValue(first, second, getEqualOptions(options));
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1700
|
+
}
|
|
1701
|
+
(function(_equal) {
|
|
1702
|
+
function initialize(options) {
|
|
1703
|
+
const actual = getEqualOptions(options);
|
|
1704
|
+
return (first, second) => equalValue(first, second, actual);
|
|
1705
|
+
}
|
|
1706
|
+
_equal.initialize = initialize;
|
|
1707
|
+
})(equal || (equal = {}));
|
|
1681
1708
|
function equalArray(first, second, options) {
|
|
1682
1709
|
const { length } = first;
|
|
1683
1710
|
if (length !== second.length) return false;
|
|
@@ -2008,13 +2035,16 @@ function getReplaceableObjects(value) {
|
|
|
2008
2035
|
function handleMerge(values, options) {
|
|
2009
2036
|
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
2010
2037
|
}
|
|
2011
|
-
|
|
2038
|
+
function merge(values, options) {
|
|
2012
2039
|
return handleMerge(values, getMergeOptions(options));
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2040
|
+
}
|
|
2041
|
+
(function(_merge) {
|
|
2042
|
+
function initialize(options) {
|
|
2043
|
+
const actual = getMergeOptions(options);
|
|
2044
|
+
return (values) => handleMerge(values, actual);
|
|
2045
|
+
}
|
|
2046
|
+
_merge.initialize = initialize;
|
|
2047
|
+
})(merge || (merge = {}));
|
|
2018
2048
|
function mergeObjects(values, options, prefix) {
|
|
2019
2049
|
const { length } = values;
|
|
2020
2050
|
const isArray = values.every(Array.isArray);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { isPlainObject, isTypedArray } from "../is.js";
|
|
2
2
|
import { chunk } from "../array/chunk.js";
|
|
3
|
-
|
|
3
|
+
function equal(first, second, options) {
|
|
4
4
|
return equalValue(first, second, getEqualOptions(options));
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
}
|
|
6
|
+
(function(_equal) {
|
|
7
|
+
function initialize(options) {
|
|
8
|
+
const actual = getEqualOptions(options);
|
|
9
|
+
return (first, second) => equalValue(first, second, actual);
|
|
10
|
+
}
|
|
11
|
+
_equal.initialize = initialize;
|
|
12
|
+
})(equal || (equal = {}));
|
|
10
13
|
function equalArray(first, second, options) {
|
|
11
14
|
const { length } = first;
|
|
12
15
|
if (length !== second.length) return false;
|
package/dist/string/template.js
CHANGED
|
@@ -21,15 +21,18 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
|
21
21
|
return values[key];
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
function template(value, variables, options) {
|
|
25
25
|
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
26
26
|
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
};
|
|
27
|
+
}
|
|
28
|
+
(function(_template) {
|
|
29
|
+
function initialize(options) {
|
|
30
|
+
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
31
|
+
return (value, variables) => {
|
|
32
|
+
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
_template.initialize = initialize;
|
|
36
|
+
})(template || (template = {}));
|
|
34
37
|
var EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
35
38
|
export { template };
|
package/dist/value/merge.js
CHANGED
|
@@ -17,13 +17,16 @@ function getReplaceableObjects(value) {
|
|
|
17
17
|
function handleMerge(values, options) {
|
|
18
18
|
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
function merge(values, options) {
|
|
21
21
|
return handleMerge(values, getMergeOptions(options));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
}
|
|
23
|
+
(function(_merge) {
|
|
24
|
+
function initialize(options) {
|
|
25
|
+
const actual = getMergeOptions(options);
|
|
26
|
+
return (values) => handleMerge(values, actual);
|
|
27
|
+
}
|
|
28
|
+
_merge.initialize = initialize;
|
|
29
|
+
})(merge || (merge = {}));
|
|
27
30
|
function mergeObjects(values, options, prefix) {
|
|
28
31
|
const { length } = values;
|
|
29
32
|
const isArray = values.every(Array.isArray);
|
package/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"@types/node": "^25",
|
|
9
9
|
"@vitest/coverage-istanbul": "^4",
|
|
10
10
|
"jsdom": "^27.4",
|
|
11
|
-
"oxfmt": "^0.
|
|
12
|
-
"oxlint": "^1.
|
|
11
|
+
"oxfmt": "^0.21",
|
|
12
|
+
"oxlint": "^1.36",
|
|
13
13
|
"rolldown": "1.0.0-beta.57",
|
|
14
14
|
"tslib": "^2.8",
|
|
15
15
|
"typescript": "^5.9",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
},
|
|
102
102
|
"type": "module",
|
|
103
103
|
"types": "./types/index.d.ts",
|
|
104
|
-
"version": "0.
|
|
104
|
+
"version": "0.120.0"
|
|
105
105
|
}
|
package/src/array/group-by.ts
CHANGED
|
@@ -1,112 +1,120 @@
|
|
|
1
1
|
import {groupValues} from '../internal/array/group';
|
|
2
2
|
import type {Key, KeyedValue, PlainObject, Simplify} from '../models';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Create a record from an array of items using a specific key and value
|
|
6
|
+
*
|
|
7
|
+
* If multiple items have the same key, the latest item's value will be used
|
|
8
|
+
* @param array Array to group
|
|
9
|
+
* @param key Callback to get an item's grouping key
|
|
10
|
+
* @param value Callback to get an item's value
|
|
11
|
+
* @returns Record of keyed values
|
|
12
|
+
*/
|
|
13
|
+
function groupBy<
|
|
14
|
+
Item,
|
|
15
|
+
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
16
|
+
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
17
|
+
>(
|
|
18
|
+
array: Item[],
|
|
19
|
+
key: KeyCallback,
|
|
20
|
+
value: ValueCallback,
|
|
21
|
+
): Simplify<Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create a record from an array of items using a specific key and value
|
|
25
|
+
*
|
|
26
|
+
* If multiple items have the same key, the latest item's value will be used
|
|
27
|
+
* @param array Array to group
|
|
28
|
+
* @param key Callback to get an item's grouping key
|
|
29
|
+
* @param value Key to use for value
|
|
30
|
+
* @returns Record of keyed values
|
|
31
|
+
*/
|
|
32
|
+
function groupBy<
|
|
33
|
+
Item extends PlainObject,
|
|
34
|
+
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
35
|
+
ItemValue extends keyof Item,
|
|
36
|
+
>(
|
|
37
|
+
array: Item[],
|
|
38
|
+
key: KeyCallback,
|
|
39
|
+
value: ItemValue,
|
|
40
|
+
): Record<ReturnType<KeyCallback>, Item[ItemValue]>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a record from an array of items using a specific key and value
|
|
44
|
+
*
|
|
45
|
+
* If multiple items have the same key, the latest item's value will be used
|
|
46
|
+
* @param array Array to group
|
|
47
|
+
* @param key Key to use for grouping
|
|
48
|
+
* @param value Callback to get an item's value
|
|
49
|
+
* @returns Record of keyed values
|
|
50
|
+
*/
|
|
51
|
+
function groupBy<
|
|
52
|
+
Item extends PlainObject,
|
|
53
|
+
ItemKey extends keyof Item,
|
|
54
|
+
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
55
|
+
>(
|
|
56
|
+
array: Item[],
|
|
57
|
+
key: ItemKey,
|
|
58
|
+
value: ValueCallback,
|
|
59
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback>>>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a record from an array of items using a specific key and value
|
|
63
|
+
*
|
|
64
|
+
* If multiple items have the same key, the latest item's value will be used
|
|
65
|
+
* @param array Array to group
|
|
66
|
+
* @param key Key to use for grouping
|
|
67
|
+
* @param value Key to use for value
|
|
68
|
+
* @returns Record of keyed values
|
|
69
|
+
*/
|
|
70
|
+
function groupBy<
|
|
71
|
+
Item extends PlainObject,
|
|
72
|
+
ItemKey extends keyof Item,
|
|
73
|
+
ItemValue extends keyof Item,
|
|
74
|
+
>(
|
|
75
|
+
array: Item[],
|
|
76
|
+
key: ItemKey,
|
|
77
|
+
value: ItemValue,
|
|
78
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Create a record from an array of items using a specific key
|
|
82
|
+
*
|
|
83
|
+
* If multiple items have the same key, the latest item will be used
|
|
84
|
+
* @param array Array to group
|
|
85
|
+
* @param callback Callback to get an item's grouping key
|
|
86
|
+
* @returns Record of keyed items
|
|
87
|
+
*/
|
|
88
|
+
function groupBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
89
|
+
array: Item[],
|
|
90
|
+
callback: Callback,
|
|
91
|
+
): Record<ReturnType<Callback>, Item>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Create a record from an array of items using a specific key
|
|
95
|
+
*
|
|
96
|
+
* If multiple items have the same key, the latest item will be used
|
|
97
|
+
* @param array Array to group
|
|
98
|
+
* @param key Key to use for grouping
|
|
99
|
+
* @returns Record of keyed items
|
|
100
|
+
*/
|
|
101
|
+
function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
102
|
+
array: Item[],
|
|
103
|
+
key: ItemKey,
|
|
104
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Create a record from an array of items _(using indices as keys)_
|
|
108
|
+
* @param array Array to group
|
|
109
|
+
* @returns Record of indiced items
|
|
110
|
+
*/
|
|
111
|
+
function groupBy<Item>(array: Item[]): Record<number, Item>;
|
|
112
|
+
|
|
113
|
+
function groupBy(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
114
|
+
return groupValues(array, first, second, false);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
namespace groupBy {
|
|
110
118
|
/**
|
|
111
119
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
112
120
|
* @param array Array to group
|
|
@@ -114,7 +122,7 @@ type GroupBy = {
|
|
|
114
122
|
* @param value Callback to get an item's value
|
|
115
123
|
* @returns Record of keyed values
|
|
116
124
|
*/
|
|
117
|
-
arrays<
|
|
125
|
+
export function arrays<
|
|
118
126
|
Item,
|
|
119
127
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
120
128
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -131,7 +139,7 @@ type GroupBy = {
|
|
|
131
139
|
* @param value Key to use for value
|
|
132
140
|
* @returns Record of keyed values
|
|
133
141
|
*/
|
|
134
|
-
arrays<
|
|
142
|
+
export function arrays<
|
|
135
143
|
Item extends PlainObject,
|
|
136
144
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
137
145
|
ItemValue extends keyof Item,
|
|
@@ -148,7 +156,7 @@ type GroupBy = {
|
|
|
148
156
|
* @param value Callback to get an item's value
|
|
149
157
|
* @returns Record of keyed values
|
|
150
158
|
*/
|
|
151
|
-
arrays<
|
|
159
|
+
export function arrays<
|
|
152
160
|
Item extends PlainObject,
|
|
153
161
|
ItemKey extends keyof Item,
|
|
154
162
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -165,7 +173,11 @@ type GroupBy = {
|
|
|
165
173
|
* @param value Key to use for value
|
|
166
174
|
* @returns Record of keyed values
|
|
167
175
|
*/
|
|
168
|
-
arrays<
|
|
176
|
+
export function arrays<
|
|
177
|
+
Item extends PlainObject,
|
|
178
|
+
ItemKey extends keyof Item,
|
|
179
|
+
ItemValue extends keyof Item,
|
|
180
|
+
>(
|
|
169
181
|
array: Item[],
|
|
170
182
|
key: ItemKey,
|
|
171
183
|
value: ItemValue,
|
|
@@ -177,7 +189,7 @@ type GroupBy = {
|
|
|
177
189
|
* @param callback Callback to get an item's grouping key
|
|
178
190
|
* @returns Record of keyed items
|
|
179
191
|
*/
|
|
180
|
-
arrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
192
|
+
export function arrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
181
193
|
array: Item[],
|
|
182
194
|
callback: Callback,
|
|
183
195
|
): Record<ReturnType<Callback>, Item[]>;
|
|
@@ -188,16 +200,14 @@ type GroupBy = {
|
|
|
188
200
|
* @param key Key to use for grouping
|
|
189
201
|
* @returns Record of keyed items
|
|
190
202
|
*/
|
|
191
|
-
arrays<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
203
|
+
export function arrays<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
192
204
|
array: Item[],
|
|
193
205
|
key: ItemKey,
|
|
194
206
|
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const groupBy = ((array: unknown[], first: unknown, second: unknown) =>
|
|
198
|
-
groupValues(array, first, second, false)) as GroupBy;
|
|
199
207
|
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
export function arrays(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
209
|
+
return groupValues(array, first, second, true);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
202
212
|
|
|
203
213
|
export {groupBy};
|