@helpers4/map 3.0.2-alpha.0 → 3.0.3
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/lib/index.d.ts +11 -11
- package/lib/index.js +11 -11
- package/lib/index.js.map +1 -1
- package/llms.txt +1 -1
- package/meta/api.json +12 -12
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @example
|
|
12
12
|
* countBy(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0 ? 'even' : 'odd')
|
|
13
13
|
* // => Map(2) { 'odd' => 2, 'even' => 1 }
|
|
14
|
-
* @since
|
|
14
|
+
* @since 3.0.3
|
|
15
15
|
*/
|
|
16
16
|
declare function countBy<K, V, R>(map: ReadonlyMap<K, V>, fn: (value: V, key: K) => R): Map<R, number>;
|
|
17
17
|
|
|
@@ -28,7 +28,7 @@ declare function countBy<K, V, R>(map: ReadonlyMap<K, V>, fn: (value: V, key: K)
|
|
|
28
28
|
* @example
|
|
29
29
|
* every(new Map([['a', 1], ['b', 2]]), value => value > 0)
|
|
30
30
|
* // => true
|
|
31
|
-
* @since
|
|
31
|
+
* @since 3.0.3
|
|
32
32
|
*/
|
|
33
33
|
declare function every<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key: K) => boolean): boolean;
|
|
34
34
|
|
|
@@ -45,7 +45,7 @@ declare function every<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key:
|
|
|
45
45
|
* @example
|
|
46
46
|
* filter(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0)
|
|
47
47
|
* // => Map(1) { 'b' => 2 }
|
|
48
|
-
* @since
|
|
48
|
+
* @since 3.0.3
|
|
49
49
|
*/
|
|
50
50
|
declare function filter<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key: K) => boolean): Map<K, V>;
|
|
51
51
|
|
|
@@ -62,7 +62,7 @@ declare function filter<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key:
|
|
|
62
62
|
* @example
|
|
63
63
|
* findKey(new Map([['a', 1], ['b', 2]]), value => value > 1)
|
|
64
64
|
* // => 'b'
|
|
65
|
-
* @since
|
|
65
|
+
* @since 3.0.3
|
|
66
66
|
*/
|
|
67
67
|
declare function findKey<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key: K) => boolean): K | undefined;
|
|
68
68
|
|
|
@@ -79,7 +79,7 @@ declare function findKey<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key
|
|
|
79
79
|
* @example
|
|
80
80
|
* findValue(new Map([['a', 1], ['b', 2]]), value => value > 1)
|
|
81
81
|
* // => 2
|
|
82
|
-
* @since
|
|
82
|
+
* @since 3.0.3
|
|
83
83
|
*/
|
|
84
84
|
declare function findValue<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key: K) => boolean): V | undefined;
|
|
85
85
|
|
|
@@ -97,7 +97,7 @@ declare function findValue<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, k
|
|
|
97
97
|
* @example
|
|
98
98
|
* hasValue(new Map([['a', 1], ['b', 2]]), 2)
|
|
99
99
|
* // => true
|
|
100
|
-
* @since
|
|
100
|
+
* @since 3.0.3
|
|
101
101
|
*/
|
|
102
102
|
declare function hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean;
|
|
103
103
|
|
|
@@ -115,7 +115,7 @@ declare function hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean;
|
|
|
115
115
|
* @example
|
|
116
116
|
* mapKeys(new Map([['a', 1], ['b', 2]]), key => key.toUpperCase())
|
|
117
117
|
* // => Map(2) { 'A' => 1, 'B' => 2 }
|
|
118
|
-
* @since
|
|
118
|
+
* @since 3.0.3
|
|
119
119
|
*/
|
|
120
120
|
declare function mapKeys<K, V, R>(map: ReadonlyMap<K, V>, fn: (key: K, value: V) => R): Map<R, V>;
|
|
121
121
|
|
|
@@ -132,7 +132,7 @@ declare function mapKeys<K, V, R>(map: ReadonlyMap<K, V>, fn: (key: K, value: V)
|
|
|
132
132
|
* @example
|
|
133
133
|
* mapValues(new Map([['a', 1], ['b', 2]]), value => value * 10)
|
|
134
134
|
* // => Map(2) { 'a' => 10, 'b' => 20 }
|
|
135
|
-
* @since
|
|
135
|
+
* @since 3.0.3
|
|
136
136
|
*/
|
|
137
137
|
declare function mapValues<K, V, R>(map: ReadonlyMap<K, V>, fn: (value: V, key: K) => R): Map<K, R>;
|
|
138
138
|
|
|
@@ -150,7 +150,7 @@ declare function mapValues<K, V, R>(map: ReadonlyMap<K, V>, fn: (value: V, key:
|
|
|
150
150
|
* @example
|
|
151
151
|
* reduce(new Map([['a', 1], ['b', 2]]), (acc, value) => acc + value, 0)
|
|
152
152
|
* // => 3
|
|
153
|
-
* @since
|
|
153
|
+
* @since 3.0.3
|
|
154
154
|
*/
|
|
155
155
|
declare function reduce<K, V, R>(map: ReadonlyMap<K, V>, fn: (accumulator: R, value: V, key: K) => R, initial: R): R;
|
|
156
156
|
|
|
@@ -167,7 +167,7 @@ declare function reduce<K, V, R>(map: ReadonlyMap<K, V>, fn: (accumulator: R, va
|
|
|
167
167
|
* @example
|
|
168
168
|
* some(new Map([['a', 1], ['b', 2]]), value => value > 1)
|
|
169
169
|
* // => true
|
|
170
|
-
* @since
|
|
170
|
+
* @since 3.0.3
|
|
171
171
|
*/
|
|
172
172
|
declare function some<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key: K) => boolean): boolean;
|
|
173
173
|
|
|
@@ -189,7 +189,7 @@ declare function some<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V, key: K
|
|
|
189
189
|
* @example
|
|
190
190
|
* toMapByKey([{ id: 'a', n: 1 }, { id: 'b', n: 2 }], item => item.id)
|
|
191
191
|
* // => Map(2) { 'a' => { id: 'a', n: 1 }, 'b' => { id: 'b', n: 2 } }
|
|
192
|
-
* @since
|
|
192
|
+
* @since 3.0.3
|
|
193
193
|
*/
|
|
194
194
|
declare function toMapByKey<T, K>(items: Iterable<T>, fn: (item: T) => K): Map<K, T>;
|
|
195
195
|
|
package/lib/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @example
|
|
13
13
|
* countBy(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0 ? 'even' : 'odd')
|
|
14
14
|
* // => Map(2) { 'odd' => 2, 'even' => 1 }
|
|
15
|
-
* @since
|
|
15
|
+
* @since 3.0.3
|
|
16
16
|
*/
|
|
17
17
|
function countBy(map, fn) {
|
|
18
18
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -37,7 +37,7 @@ function countBy(map, fn) {
|
|
|
37
37
|
* @example
|
|
38
38
|
* every(new Map([['a', 1], ['b', 2]]), value => value > 0)
|
|
39
39
|
* // => true
|
|
40
|
-
* @since
|
|
40
|
+
* @since 3.0.3
|
|
41
41
|
*/
|
|
42
42
|
function every(map, predicate) {
|
|
43
43
|
for (const [key, value] of map) if (!predicate(value, key)) return false;
|
|
@@ -58,7 +58,7 @@ function every(map, predicate) {
|
|
|
58
58
|
* @example
|
|
59
59
|
* filter(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0)
|
|
60
60
|
* // => Map(1) { 'b' => 2 }
|
|
61
|
-
* @since
|
|
61
|
+
* @since 3.0.3
|
|
62
62
|
*/
|
|
63
63
|
function filter(map, predicate) {
|
|
64
64
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -80,7 +80,7 @@ function filter(map, predicate) {
|
|
|
80
80
|
* @example
|
|
81
81
|
* findKey(new Map([['a', 1], ['b', 2]]), value => value > 1)
|
|
82
82
|
* // => 'b'
|
|
83
|
-
* @since
|
|
83
|
+
* @since 3.0.3
|
|
84
84
|
*/
|
|
85
85
|
function findKey(map, predicate) {
|
|
86
86
|
for (const [key, value] of map) if (predicate(value, key)) return key;
|
|
@@ -100,7 +100,7 @@ function findKey(map, predicate) {
|
|
|
100
100
|
* @example
|
|
101
101
|
* findValue(new Map([['a', 1], ['b', 2]]), value => value > 1)
|
|
102
102
|
* // => 2
|
|
103
|
-
* @since
|
|
103
|
+
* @since 3.0.3
|
|
104
104
|
*/
|
|
105
105
|
function findValue(map, predicate) {
|
|
106
106
|
for (const [key, value] of map) if (predicate(value, key)) return value;
|
|
@@ -121,7 +121,7 @@ function findValue(map, predicate) {
|
|
|
121
121
|
* @example
|
|
122
122
|
* hasValue(new Map([['a', 1], ['b', 2]]), 2)
|
|
123
123
|
* // => true
|
|
124
|
-
* @since
|
|
124
|
+
* @since 3.0.3
|
|
125
125
|
*/
|
|
126
126
|
function hasValue(map, value) {
|
|
127
127
|
for (const v of map.values()) if (Object.is(v, value)) return true;
|
|
@@ -143,7 +143,7 @@ function hasValue(map, value) {
|
|
|
143
143
|
* @example
|
|
144
144
|
* mapKeys(new Map([['a', 1], ['b', 2]]), key => key.toUpperCase())
|
|
145
145
|
* // => Map(2) { 'A' => 1, 'B' => 2 }
|
|
146
|
-
* @since
|
|
146
|
+
* @since 3.0.3
|
|
147
147
|
*/
|
|
148
148
|
function mapKeys(map, fn) {
|
|
149
149
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -165,7 +165,7 @@ function mapKeys(map, fn) {
|
|
|
165
165
|
* @example
|
|
166
166
|
* mapValues(new Map([['a', 1], ['b', 2]]), value => value * 10)
|
|
167
167
|
* // => Map(2) { 'a' => 10, 'b' => 20 }
|
|
168
|
-
* @since
|
|
168
|
+
* @since 3.0.3
|
|
169
169
|
*/
|
|
170
170
|
function mapValues(map, fn) {
|
|
171
171
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -188,7 +188,7 @@ function mapValues(map, fn) {
|
|
|
188
188
|
* @example
|
|
189
189
|
* reduce(new Map([['a', 1], ['b', 2]]), (acc, value) => acc + value, 0)
|
|
190
190
|
* // => 3
|
|
191
|
-
* @since
|
|
191
|
+
* @since 3.0.3
|
|
192
192
|
*/
|
|
193
193
|
function reduce(map, fn, initial) {
|
|
194
194
|
let accumulator = initial;
|
|
@@ -210,7 +210,7 @@ function reduce(map, fn, initial) {
|
|
|
210
210
|
* @example
|
|
211
211
|
* some(new Map([['a', 1], ['b', 2]]), value => value > 1)
|
|
212
212
|
* // => true
|
|
213
|
-
* @since
|
|
213
|
+
* @since 3.0.3
|
|
214
214
|
*/
|
|
215
215
|
function some(map, predicate) {
|
|
216
216
|
for (const [key, value] of map) if (predicate(value, key)) return true;
|
|
@@ -236,7 +236,7 @@ function some(map, predicate) {
|
|
|
236
236
|
* @example
|
|
237
237
|
* toMapByKey([{ id: 'a', n: 1 }, { id: 'b', n: 2 }], item => item.id)
|
|
238
238
|
* // => Map(2) { 'a' => { id: 'a', n: 1 }, 'b' => { id: 'b', n: 2 } }
|
|
239
|
-
* @since
|
|
239
|
+
* @since 3.0.3
|
|
240
240
|
*/
|
|
241
241
|
function toMapByKey(items, fn) {
|
|
242
242
|
const result = /* @__PURE__ */ new Map();
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/map/countBy.ts","../../../helpers/map/every.ts","../../../helpers/map/filter.ts","../../../helpers/map/findKey.ts","../../../helpers/map/findValue.ts","../../../helpers/map/hasValue.ts","../../../helpers/map/mapKeys.ts","../../../helpers/map/mapValues.ts","../../../helpers/map/reduce.ts","../../../helpers/map/some.ts","../../../helpers/map/toMapByKey.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Groups the entries of a Map by a derived key and counts how many fall into each group.\n * @param map - The Map to summarize\n * @param fn - Function deriving the grouping key from (value, key)\n * @returns A Map from derived key to the number of entries in that group\n * @example\n * countBy(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0 ? 'even' : 'odd')\n * // => Map(2) { 'odd' => 2, 'even' => 1 }\n * @since next\n */\nexport function countBy<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (value: V, key: K) => R,\n): Map<R, number> {\n const counts = new Map<R, number>();\n for (const [key, value] of map) {\n const group = fn(value, key);\n counts.set(group, (counts.get(group) ?? 0) + 1);\n }\n return counts;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if every entry of a Map satisfies the predicate. Short-circuits on the first mismatch.\n * @param map - The Map to check\n * @param predicate - Function invoked with (value, key)\n * @returns `true` if all entries match (vacuously `true` for an empty map), `false` otherwise\n * @example\n * every(new Map([['a', 1], ['b', 2]]), value => value > 0)\n * // => true\n * @since next\n */\nexport function every<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): boolean {\n for (const [key, value] of map) {\n if (!predicate(value, key)) return false;\n }\n return true;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new Map containing only the entries for which the predicate returns true.\n * @param map - The Map to filter\n * @param predicate - Function invoked with (value, key) — return true to keep the entry\n * @returns A new Map with only the matching entries\n * @example\n * filter(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0)\n * // => Map(1) { 'b' => 2 }\n * @since next\n */\nexport function filter<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): Map<K, V> {\n const result = new Map<K, V>();\n for (const [key, value] of map) {\n if (predicate(value, key)) {\n result.set(key, value);\n }\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Returns the first key of a Map whose entry satisfies the predicate, in insertion order.\n * @param map - The Map to search\n * @param predicate - Function invoked with (value, key)\n * @returns The matching key, or `undefined` if none matches\n * @example\n * findKey(new Map([['a', 1], ['b', 2]]), value => value > 1)\n * // => 'b'\n * @since next\n */\nexport function findKey<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): K | undefined {\n for (const [key, value] of map) {\n if (predicate(value, key)) return key;\n }\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Returns the first value of a Map whose entry satisfies the predicate, in insertion order.\n * @param map - The Map to search\n * @param predicate - Function invoked with (value, key)\n * @returns The matching value, or `undefined` if none matches\n * @example\n * findValue(new Map([['a', 1], ['b', 2]]), value => value > 1)\n * // => 2\n * @since next\n */\nexport function findValue<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): V | undefined {\n for (const [key, value] of map) {\n if (predicate(value, key)) return value;\n }\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).\n * Uses `Object.is`-style equality (via `===`, with `NaN` matching `NaN`).\n * @param map - The Map to search\n * @param value - The value to look for\n * @returns `true` if the value is found in at least one entry\n * @example\n * hasValue(new Map([['a', 1], ['b', 2]]), 2)\n * // => true\n * @since next\n */\nexport function hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean {\n for (const v of map.values()) {\n if (Object.is(v, value)) return true;\n }\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new Map with the same values but with each key transformed by a function.\n * If two entries derive the same new key, the later one (in insertion order) wins.\n * @param map - The Map to transform\n * @param fn - Function invoked with (key, value) that returns the new key\n * @returns A new Map with transformed keys\n * @example\n * mapKeys(new Map([['a', 1], ['b', 2]]), key => key.toUpperCase())\n * // => Map(2) { 'A' => 1, 'B' => 2 }\n * @since next\n */\nexport function mapKeys<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (key: K, value: V) => R,\n): Map<R, V> {\n const result = new Map<R, V>();\n for (const [key, value] of map) {\n result.set(fn(key, value), value);\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new Map with the same keys but with each value transformed by a function.\n * @param map - The Map to transform\n * @param fn - Function invoked with (value, key) that returns the new value\n * @returns A new Map with transformed values\n * @example\n * mapValues(new Map([['a', 1], ['b', 2]]), value => value * 10)\n * // => Map(2) { 'a' => 10, 'b' => 20 }\n * @since next\n */\nexport function mapValues<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (value: V, key: K) => R,\n): Map<K, R> {\n const result = new Map<K, R>();\n for (const [key, value] of map) {\n result.set(key, fn(value, key));\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Reduces a Map to a single value by applying a function to each entry, in insertion order.\n * @param map - The Map to reduce\n * @param fn - Function invoked with (accumulator, value, key)\n * @param initial - Initial accumulator value\n * @returns The final accumulator value\n * @example\n * reduce(new Map([['a', 1], ['b', 2]]), (acc, value) => acc + value, 0)\n * // => 3\n * @since next\n */\nexport function reduce<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (accumulator: R, value: V, key: K) => R,\n initial: R,\n): R {\n let accumulator = initial;\n for (const [key, value] of map) {\n accumulator = fn(accumulator, value, key);\n }\n return accumulator;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if at least one entry of a Map satisfies the predicate. Short-circuits on the first match.\n * @param map - The Map to check\n * @param predicate - Function invoked with (value, key)\n * @returns `true` if at least one entry matches, `false` otherwise (including for an empty map)\n * @example\n * some(new Map([['a', 1], ['b', 2]]), value => value > 1)\n * // => true\n * @since next\n */\nexport function some<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): boolean {\n for (const [key, value] of map) {\n if (predicate(value, key)) return true;\n }\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Builds a Map from an iterable of items, keyed by a derived key. When two items derive the\n * same key, the later item wins (last-write-wins, matching `Map.prototype.set` semantics).\n *\n * Named `toMapByKey`, not `keyBy` (lodash's name for the same idea) — lodash's `_.keyBy`\n * returns a plain object, not a `Map`; the `to<Type>` prefix (matching `toSorted`/`toReversed`)\n * makes the actual return type unambiguous.\n * @param items - The items to index\n * @param fn - Function deriving the key for each item\n * @returns A Map from derived key to item\n * @example\n * toMapByKey([{ id: 'a', n: 1 }, { id: 'b', n: 2 }], item => item.id)\n * // => Map(2) { 'a' => { id: 'a', n: 1 }, 'b' => { id: 'b', n: 2 } }\n * @since next\n */\nexport function toMapByKey<T, K>(items: Iterable<T>, fn: (item: T) => K): Map<K, T> {\n const result = new Map<K, T>();\n for (const item of items) {\n result.set(fn(item), item);\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,QACd,KACA,IACgB;CAChB,MAAM,yBAAS,IAAI,IAAe;CAClC,KAAK,MAAM,CAAC,KAAK,UAAU,KAAK;EAC9B,MAAM,QAAQ,GAAG,OAAO,GAAG;EAC3B,OAAO,IAAI,QAAQ,OAAO,IAAI,KAAK,KAAK,KAAK,CAAC;CAChD;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;ACVA,SAAgB,MACd,KACA,WACS;CACT,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,CAAC,UAAU,OAAO,GAAG,GAAG,OAAO;CAErC,OAAO;AACT;;;;;;;;;;;;;;;;;;ACRA,SAAgB,OACd,KACA,WACW;CACX,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GACtB,OAAO,IAAI,KAAK,KAAK;CAGzB,OAAO;AACT;;;;;;;;;;;;;;;;;;ACXA,SAAgB,QACd,KACA,WACe;CACf,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GAAG,OAAO;AAGtC;;;;;;;;;;;;;;;;;;ACRA,SAAgB,UACd,KACA,WACe;CACf,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GAAG,OAAO;AAGtC;;;;;;;;;;;;;;;;;;;ACPA,SAAgB,SAAe,KAAwB,OAAmB;CACxE,KAAK,MAAM,KAAK,IAAI,OAAO,GACzB,IAAI,OAAO,GAAG,GAAG,KAAK,GAAG,OAAO;CAElC,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACLA,SAAgB,QACd,KACA,IACW;CACX,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,OAAO,IAAI,GAAG,KAAK,KAAK,GAAG,KAAK;CAElC,OAAO;AACT;;;;;;;;;;;;;;;;;;ACVA,SAAgB,UACd,KACA,IACW;CACX,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,OAAO,IAAI,KAAK,GAAG,OAAO,GAAG,CAAC;CAEhC,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACRA,SAAgB,OACd,KACA,IACA,SACG;CACH,IAAI,cAAc;CAClB,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,cAAc,GAAG,aAAa,OAAO,GAAG;CAE1C,OAAO;AACT;;;;;;;;;;;;;;;;;;ACXA,SAAgB,KACd,KACA,WACS;CACT,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GAAG,OAAO;CAEpC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;ACHA,SAAgB,WAAiB,OAAoB,IAA+B;CAClF,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,QAAQ,OACjB,OAAO,IAAI,GAAG,IAAI,GAAG,IAAI;CAE3B,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/map/countBy.ts","../../../helpers/map/every.ts","../../../helpers/map/filter.ts","../../../helpers/map/findKey.ts","../../../helpers/map/findValue.ts","../../../helpers/map/hasValue.ts","../../../helpers/map/mapKeys.ts","../../../helpers/map/mapValues.ts","../../../helpers/map/reduce.ts","../../../helpers/map/some.ts","../../../helpers/map/toMapByKey.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Groups the entries of a Map by a derived key and counts how many fall into each group.\n * @param map - The Map to summarize\n * @param fn - Function deriving the grouping key from (value, key)\n * @returns A Map from derived key to the number of entries in that group\n * @example\n * countBy(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0 ? 'even' : 'odd')\n * // => Map(2) { 'odd' => 2, 'even' => 1 }\n * @since 3.0.3\n */\nexport function countBy<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (value: V, key: K) => R,\n): Map<R, number> {\n const counts = new Map<R, number>();\n for (const [key, value] of map) {\n const group = fn(value, key);\n counts.set(group, (counts.get(group) ?? 0) + 1);\n }\n return counts;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if every entry of a Map satisfies the predicate. Short-circuits on the first mismatch.\n * @param map - The Map to check\n * @param predicate - Function invoked with (value, key)\n * @returns `true` if all entries match (vacuously `true` for an empty map), `false` otherwise\n * @example\n * every(new Map([['a', 1], ['b', 2]]), value => value > 0)\n * // => true\n * @since 3.0.3\n */\nexport function every<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): boolean {\n for (const [key, value] of map) {\n if (!predicate(value, key)) return false;\n }\n return true;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new Map containing only the entries for which the predicate returns true.\n * @param map - The Map to filter\n * @param predicate - Function invoked with (value, key) — return true to keep the entry\n * @returns A new Map with only the matching entries\n * @example\n * filter(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0)\n * // => Map(1) { 'b' => 2 }\n * @since 3.0.3\n */\nexport function filter<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): Map<K, V> {\n const result = new Map<K, V>();\n for (const [key, value] of map) {\n if (predicate(value, key)) {\n result.set(key, value);\n }\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Returns the first key of a Map whose entry satisfies the predicate, in insertion order.\n * @param map - The Map to search\n * @param predicate - Function invoked with (value, key)\n * @returns The matching key, or `undefined` if none matches\n * @example\n * findKey(new Map([['a', 1], ['b', 2]]), value => value > 1)\n * // => 'b'\n * @since 3.0.3\n */\nexport function findKey<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): K | undefined {\n for (const [key, value] of map) {\n if (predicate(value, key)) return key;\n }\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Returns the first value of a Map whose entry satisfies the predicate, in insertion order.\n * @param map - The Map to search\n * @param predicate - Function invoked with (value, key)\n * @returns The matching value, or `undefined` if none matches\n * @example\n * findValue(new Map([['a', 1], ['b', 2]]), value => value > 1)\n * // => 2\n * @since 3.0.3\n */\nexport function findValue<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): V | undefined {\n for (const [key, value] of map) {\n if (predicate(value, key)) return value;\n }\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).\n * Uses `Object.is`-style equality (via `===`, with `NaN` matching `NaN`).\n * @param map - The Map to search\n * @param value - The value to look for\n * @returns `true` if the value is found in at least one entry\n * @example\n * hasValue(new Map([['a', 1], ['b', 2]]), 2)\n * // => true\n * @since 3.0.3\n */\nexport function hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean {\n for (const v of map.values()) {\n if (Object.is(v, value)) return true;\n }\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new Map with the same values but with each key transformed by a function.\n * If two entries derive the same new key, the later one (in insertion order) wins.\n * @param map - The Map to transform\n * @param fn - Function invoked with (key, value) that returns the new key\n * @returns A new Map with transformed keys\n * @example\n * mapKeys(new Map([['a', 1], ['b', 2]]), key => key.toUpperCase())\n * // => Map(2) { 'A' => 1, 'B' => 2 }\n * @since 3.0.3\n */\nexport function mapKeys<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (key: K, value: V) => R,\n): Map<R, V> {\n const result = new Map<R, V>();\n for (const [key, value] of map) {\n result.set(fn(key, value), value);\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new Map with the same keys but with each value transformed by a function.\n * @param map - The Map to transform\n * @param fn - Function invoked with (value, key) that returns the new value\n * @returns A new Map with transformed values\n * @example\n * mapValues(new Map([['a', 1], ['b', 2]]), value => value * 10)\n * // => Map(2) { 'a' => 10, 'b' => 20 }\n * @since 3.0.3\n */\nexport function mapValues<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (value: V, key: K) => R,\n): Map<K, R> {\n const result = new Map<K, R>();\n for (const [key, value] of map) {\n result.set(key, fn(value, key));\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Reduces a Map to a single value by applying a function to each entry, in insertion order.\n * @param map - The Map to reduce\n * @param fn - Function invoked with (accumulator, value, key)\n * @param initial - Initial accumulator value\n * @returns The final accumulator value\n * @example\n * reduce(new Map([['a', 1], ['b', 2]]), (acc, value) => acc + value, 0)\n * // => 3\n * @since 3.0.3\n */\nexport function reduce<K, V, R>(\n map: ReadonlyMap<K, V>,\n fn: (accumulator: R, value: V, key: K) => R,\n initial: R,\n): R {\n let accumulator = initial;\n for (const [key, value] of map) {\n accumulator = fn(accumulator, value, key);\n }\n return accumulator;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if at least one entry of a Map satisfies the predicate. Short-circuits on the first match.\n * @param map - The Map to check\n * @param predicate - Function invoked with (value, key)\n * @returns `true` if at least one entry matches, `false` otherwise (including for an empty map)\n * @example\n * some(new Map([['a', 1], ['b', 2]]), value => value > 1)\n * // => true\n * @since 3.0.3\n */\nexport function some<K, V>(\n map: ReadonlyMap<K, V>,\n predicate: (value: V, key: K) => boolean,\n): boolean {\n for (const [key, value] of map) {\n if (predicate(value, key)) return true;\n }\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Builds a Map from an iterable of items, keyed by a derived key. When two items derive the\n * same key, the later item wins (last-write-wins, matching `Map.prototype.set` semantics).\n *\n * Named `toMapByKey`, not `keyBy` (lodash's name for the same idea) — lodash's `_.keyBy`\n * returns a plain object, not a `Map`; the `to<Type>` prefix (matching `toSorted`/`toReversed`)\n * makes the actual return type unambiguous.\n * @param items - The items to index\n * @param fn - Function deriving the key for each item\n * @returns A Map from derived key to item\n * @example\n * toMapByKey([{ id: 'a', n: 1 }, { id: 'b', n: 2 }], item => item.id)\n * // => Map(2) { 'a' => { id: 'a', n: 1 }, 'b' => { id: 'b', n: 2 } }\n * @since 3.0.3\n */\nexport function toMapByKey<T, K>(items: Iterable<T>, fn: (item: T) => K): Map<K, T> {\n const result = new Map<K, T>();\n for (const item of items) {\n result.set(fn(item), item);\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,QACd,KACA,IACgB;CAChB,MAAM,yBAAS,IAAI,IAAe;CAClC,KAAK,MAAM,CAAC,KAAK,UAAU,KAAK;EAC9B,MAAM,QAAQ,GAAG,OAAO,GAAG;EAC3B,OAAO,IAAI,QAAQ,OAAO,IAAI,KAAK,KAAK,KAAK,CAAC;CAChD;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;ACVA,SAAgB,MACd,KACA,WACS;CACT,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,CAAC,UAAU,OAAO,GAAG,GAAG,OAAO;CAErC,OAAO;AACT;;;;;;;;;;;;;;;;;;ACRA,SAAgB,OACd,KACA,WACW;CACX,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GACtB,OAAO,IAAI,KAAK,KAAK;CAGzB,OAAO;AACT;;;;;;;;;;;;;;;;;;ACXA,SAAgB,QACd,KACA,WACe;CACf,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GAAG,OAAO;AAGtC;;;;;;;;;;;;;;;;;;ACRA,SAAgB,UACd,KACA,WACe;CACf,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GAAG,OAAO;AAGtC;;;;;;;;;;;;;;;;;;;ACPA,SAAgB,SAAe,KAAwB,OAAmB;CACxE,KAAK,MAAM,KAAK,IAAI,OAAO,GACzB,IAAI,OAAO,GAAG,GAAG,KAAK,GAAG,OAAO;CAElC,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACLA,SAAgB,QACd,KACA,IACW;CACX,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,OAAO,IAAI,GAAG,KAAK,KAAK,GAAG,KAAK;CAElC,OAAO;AACT;;;;;;;;;;;;;;;;;;ACVA,SAAgB,UACd,KACA,IACW;CACX,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,OAAO,IAAI,KAAK,GAAG,OAAO,GAAG,CAAC;CAEhC,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACRA,SAAgB,OACd,KACA,IACA,SACG;CACH,IAAI,cAAc;CAClB,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,cAAc,GAAG,aAAa,OAAO,GAAG;CAE1C,OAAO;AACT;;;;;;;;;;;;;;;;;;ACXA,SAAgB,KACd,KACA,WACS;CACT,KAAK,MAAM,CAAC,KAAK,UAAU,KACzB,IAAI,UAAU,OAAO,GAAG,GAAG,OAAO;CAEpC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;ACHA,SAAgB,WAAiB,OAAoB,IAA+B;CAClF,MAAM,yBAAS,IAAI,IAAU;CAC7B,KAAK,MAAM,QAAQ,OACjB,OAAO,IAAI,GAAG,IAAI,GAAG,IAAI;CAE3B,OAAO;AACT"}
|
package/llms.txt
CHANGED
package/meta/api.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "map",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"functions": [
|
|
5
5
|
{
|
|
6
6
|
"name": "countBy",
|
|
7
7
|
"kind": "function",
|
|
8
8
|
"description": "Groups the entries of a Map by a derived key and counts how many fall into each group.",
|
|
9
|
-
"since": "
|
|
9
|
+
"since": "3.0.3",
|
|
10
10
|
"signatures": [
|
|
11
11
|
{
|
|
12
12
|
"signature": "countBy<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<R, number>",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"name": "every",
|
|
54
54
|
"kind": "function",
|
|
55
55
|
"description": "Checks if every entry of a Map satisfies the predicate. Short-circuits on the first mismatch.",
|
|
56
|
-
"since": "
|
|
56
|
+
"since": "3.0.3",
|
|
57
57
|
"signatures": [
|
|
58
58
|
{
|
|
59
59
|
"signature": "every<K, V>(map: ReadonlyMap<K, V>, predicate: function): boolean",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"name": "filter",
|
|
103
103
|
"kind": "function",
|
|
104
104
|
"description": "Creates a new Map containing only the entries for which the predicate returns true.",
|
|
105
|
-
"since": "
|
|
105
|
+
"since": "3.0.3",
|
|
106
106
|
"signatures": [
|
|
107
107
|
{
|
|
108
108
|
"signature": "filter<K, V>(map: ReadonlyMap<K, V>, predicate: function): Map<K, V>",
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
"name": "findKey",
|
|
152
152
|
"kind": "function",
|
|
153
153
|
"description": "Returns the first key of a Map whose entry satisfies the predicate, in insertion order.",
|
|
154
|
-
"since": "
|
|
154
|
+
"since": "3.0.3",
|
|
155
155
|
"signatures": [
|
|
156
156
|
{
|
|
157
157
|
"signature": "findKey<K, V>(map: ReadonlyMap<K, V>, predicate: function): K | undefined",
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
"name": "findValue",
|
|
201
201
|
"kind": "function",
|
|
202
202
|
"description": "Returns the first value of a Map whose entry satisfies the predicate, in insertion order.",
|
|
203
|
-
"since": "
|
|
203
|
+
"since": "3.0.3",
|
|
204
204
|
"signatures": [
|
|
205
205
|
{
|
|
206
206
|
"signature": "findValue<K, V>(map: ReadonlyMap<K, V>, predicate: function): V | undefined",
|
|
@@ -249,7 +249,7 @@
|
|
|
249
249
|
"name": "hasValue",
|
|
250
250
|
"kind": "function",
|
|
251
251
|
"description": "Checks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).\nUses `Object.is`-style equality (via `===`, with `NaN` matching `NaN`).",
|
|
252
|
-
"since": "
|
|
252
|
+
"since": "3.0.3",
|
|
253
253
|
"signatures": [
|
|
254
254
|
{
|
|
255
255
|
"signature": "hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean",
|
|
@@ -298,7 +298,7 @@
|
|
|
298
298
|
"name": "mapKeys",
|
|
299
299
|
"kind": "function",
|
|
300
300
|
"description": "Creates a new Map with the same values but with each key transformed by a function.\nIf two entries derive the same new key, the later one (in insertion order) wins.",
|
|
301
|
-
"since": "
|
|
301
|
+
"since": "3.0.3",
|
|
302
302
|
"signatures": [
|
|
303
303
|
{
|
|
304
304
|
"signature": "mapKeys<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<R, V>",
|
|
@@ -345,7 +345,7 @@
|
|
|
345
345
|
"name": "mapValues",
|
|
346
346
|
"kind": "function",
|
|
347
347
|
"description": "Creates a new Map with the same keys but with each value transformed by a function.",
|
|
348
|
-
"since": "
|
|
348
|
+
"since": "3.0.3",
|
|
349
349
|
"signatures": [
|
|
350
350
|
{
|
|
351
351
|
"signature": "mapValues<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<K, R>",
|
|
@@ -392,7 +392,7 @@
|
|
|
392
392
|
"name": "reduce",
|
|
393
393
|
"kind": "function",
|
|
394
394
|
"description": "Reduces a Map to a single value by applying a function to each entry, in insertion order.",
|
|
395
|
-
"since": "
|
|
395
|
+
"since": "3.0.3",
|
|
396
396
|
"signatures": [
|
|
397
397
|
{
|
|
398
398
|
"signature": "reduce<K, V, R>(map: ReadonlyMap<K, V>, fn: function, initial: R): R",
|
|
@@ -449,7 +449,7 @@
|
|
|
449
449
|
"name": "some",
|
|
450
450
|
"kind": "function",
|
|
451
451
|
"description": "Checks if at least one entry of a Map satisfies the predicate. Short-circuits on the first match.",
|
|
452
|
-
"since": "
|
|
452
|
+
"since": "3.0.3",
|
|
453
453
|
"signatures": [
|
|
454
454
|
{
|
|
455
455
|
"signature": "some<K, V>(map: ReadonlyMap<K, V>, predicate: function): boolean",
|
|
@@ -498,7 +498,7 @@
|
|
|
498
498
|
"name": "toMapByKey",
|
|
499
499
|
"kind": "function",
|
|
500
500
|
"description": "Builds a Map from an iterable of items, keyed by a derived key. When two items derive the\nsame key, the later item wins (last-write-wins, matching `Map.prototype.set` semantics).\n\nNamed `toMapByKey`, not `keyBy` (lodash's name for the same idea) — lodash's `_.keyBy`\nreturns a plain object, not a `Map`; the `to<Type>` prefix (matching `toSorted`/`toReversed`)\nmakes the actual return type unambiguous.",
|
|
501
|
-
"since": "
|
|
501
|
+
"since": "3.0.3",
|
|
502
502
|
"signatures": [
|
|
503
503
|
{
|
|
504
504
|
"signature": "toMapByKey<T, K>(items: Iterable<T>, fn: function): Map<K, T>",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/map",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for map.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=26.0.0"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|