@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.
@@ -1,4 +1,11 @@
1
1
  import { groupValues } from "../internal/array/group.js";
2
- var groupBy = ((array, first, second) => groupValues(array, first, second, false));
3
- groupBy.arrays = ((array, first, second) => groupValues(array, first, second, true));
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 };
@@ -16,6 +16,13 @@ function getMapValues(array, first, second, arrays) {
16
16
  }
17
17
  return map;
18
18
  }
19
- var toMap = ((array, first, second, arrays) => getMapValues(array, first, second, arrays));
20
- toMap.arrays = ((array, first, second) => getMapValues(array, first, second, true));
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 };
@@ -1,4 +1,11 @@
1
1
  import { groupValues } from "../internal/array/group.js";
2
- var toRecord = ((array, first, second) => groupValues(array, first, second, false));
3
- toRecord.arrays = ((array, first, second) => groupValues(array, first, second, true));
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 };
@@ -206,8 +206,15 @@ function groupValues(array, key, value, arrays) {
206
206
  }
207
207
  return record;
208
208
  }
209
- const groupBy = ((array, first, second) => groupValues(array, first, second, false));
210
- groupBy.arrays = ((array, first, second) => groupValues(array, first, second, true));
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
- const toMap = ((array, first, second, arrays) => getMapValues(array, first, second, arrays));
439
- toMap.arrays = ((array, first, second) => getMapValues(array, first, second, true));
440
- const toRecord = ((array, first, second) => groupValues(array, first, second, false));
441
- toRecord.arrays = ((array, first, second) => groupValues(array, first, second, true));
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
- const template = ((value, variables, options) => {
1684
+ function template(value, variables, options) {
1664
1685
  const { ignoreCase, pattern } = getTemplateOptions(options);
1665
1686
  return handleTemplate(value, pattern, ignoreCase, variables);
1666
- });
1667
- template.initialize = (options) => {
1668
- const { ignoreCase, pattern } = getTemplateOptions(options);
1669
- return (value, variables) => {
1670
- return handleTemplate(value, pattern, ignoreCase, variables);
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
- const equal = ((first, second, options) => {
1698
+ function equal(first, second, options) {
1675
1699
  return equalValue(first, second, getEqualOptions(options));
1676
- });
1677
- equal.initialize = (options) => {
1678
- const actual = getEqualOptions(options);
1679
- return (first, second) => equalValue(first, second, actual);
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
- const merge = ((values, options) => {
2038
+ function merge(values, options) {
2012
2039
  return handleMerge(values, getMergeOptions(options));
2013
- });
2014
- merge.initialize = (options) => {
2015
- const actual = getMergeOptions(options);
2016
- return (values) => handleMerge(values, actual);
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
- var equal = ((first, second, options) => {
3
+ function equal(first, second, options) {
4
4
  return equalValue(first, second, getEqualOptions(options));
5
- });
6
- equal.initialize = (options) => {
7
- const actual = getEqualOptions(options);
8
- return (first, second) => equalValue(first, second, actual);
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;
@@ -21,15 +21,18 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
21
21
  return values[key];
22
22
  });
23
23
  }
24
- var template = ((value, variables, options) => {
24
+ function template(value, variables, options) {
25
25
  const { ignoreCase, pattern } = getTemplateOptions(options);
26
26
  return handleTemplate(value, pattern, ignoreCase, variables);
27
- });
28
- template.initialize = (options) => {
29
- const { ignoreCase, pattern } = getTemplateOptions(options);
30
- return (value, variables) => {
31
- return handleTemplate(value, pattern, ignoreCase, variables);
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 };
@@ -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
- var merge = ((values, options) => {
20
+ function merge(values, options) {
21
21
  return handleMerge(values, getMergeOptions(options));
22
- });
23
- merge.initialize = (options) => {
24
- const actual = getMergeOptions(options);
25
- return (values) => handleMerge(values, actual);
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.20",
12
- "oxlint": "^1.35",
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.119.0"
104
+ "version": "0.120.0"
105
105
  }
@@ -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
- type GroupBy = {
5
- /**
6
- * Create a record from an array of items using a specific key and value
7
- *
8
- * If multiple items have the same key, the latest item's value will be used
9
- * @param array Array to group
10
- * @param key Callback to get an item's grouping key
11
- * @param value Callback to get an item's value
12
- * @returns Record of keyed values
13
- */
14
- <
15
- Item,
16
- KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
17
- ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
18
- >(
19
- array: Item[],
20
- key: KeyCallback,
21
- value: ValueCallback,
22
- ): Simplify<Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>>>;
23
-
24
- /**
25
- * Create a record from an array of items using a specific key and value
26
- *
27
- * If multiple items have the same key, the latest item's value will be used
28
- * @param array Array to group
29
- * @param key Callback to get an item's grouping key
30
- * @param value Key to use for value
31
- * @returns Record of keyed values
32
- */
33
- <
34
- Item extends PlainObject,
35
- KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
36
- ItemValue extends keyof Item,
37
- >(
38
- array: Item[],
39
- key: KeyCallback,
40
- value: ItemValue,
41
- ): Record<ReturnType<KeyCallback>, Item[ItemValue]>;
42
-
43
- /**
44
- * Create a record from an array of items using a specific key and value
45
- *
46
- * If multiple items have the same key, the latest item's value will be used
47
- * @param array Array to group
48
- * @param key Key to use for grouping
49
- * @param value Callback to get an item's value
50
- * @returns Record of keyed values
51
- */
52
- <
53
- Item extends PlainObject,
54
- ItemKey extends keyof Item,
55
- ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
56
- >(
57
- array: Item[],
58
- key: ItemKey,
59
- value: ValueCallback,
60
- ): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback>>>;
61
-
62
- /**
63
- * Create a record from an array of items using a specific key and value
64
- *
65
- * If multiple items have the same key, the latest item's value will be used
66
- * @param array Array to group
67
- * @param key Key to use for grouping
68
- * @param value Key to use for value
69
- * @returns Record of keyed values
70
- */
71
- <Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(
72
- array: Item[],
73
- key: ItemKey,
74
- value: ItemValue,
75
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
76
-
77
- /**
78
- * Create a record from an array of items using a specific key
79
- *
80
- * If multiple items have the same key, the latest item will be used
81
- * @param array Array to group
82
- * @param callback Callback to get an item's grouping key
83
- * @returns Record of keyed items
84
- */
85
- <Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
86
- array: Item[],
87
- callback: Callback,
88
- ): Record<ReturnType<Callback>, Item>;
89
-
90
- /**
91
- * Create a record from an array of items using a specific key
92
- *
93
- * If multiple items have the same key, the latest item will be used
94
- * @param array Array to group
95
- * @param key Key to use for grouping
96
- * @returns Record of keyed items
97
- */
98
- <Item extends PlainObject, ItemKey extends keyof Item>(
99
- array: Item[],
100
- key: ItemKey,
101
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
102
-
103
- /**
104
- * Create a record from an array of items _(using indices as keys)_
105
- * @param array Array to group
106
- * @returns Record of indiced items
107
- */
108
- <Item>(array: Item[]): Record<number, Item>;
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<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(
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
- groupBy.arrays = ((array: unknown[], first: unknown, second: unknown): unknown =>
201
- groupValues(array, first, second, true) as never) as GroupBy['arrays'];
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};