es-toolkit 1.46.0-dev.1789 → 1.46.0-dev.1791

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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Counts the occurrences of items in a Map based on a transformation function.
3
+ *
4
+ * This function takes a Map and a function that generates a key from each value-key pair.
5
+ * It returns an object with the generated keys as properties and their counts as values.
6
+ * The count is incremented for each entry for which the transformation produces the same key.
7
+ *
8
+ * @template K - The type of the Map's keys.
9
+ * @template V - The type of the Map's values.
10
+ * @template K2 - The type of keys produced by the transformation function.
11
+ * @param {Map<K, V>} map - The Map to count occurrences from.
12
+ * @param {(value: V, key: K, object: Map<K, V>) => K2} mapper - The function to produce a key for counting.
13
+ * @returns {Record<K2, number>} An object containing the mapped keys and their counts.
14
+ *
15
+ * @example
16
+ * const map = new Map([
17
+ * ['a', 1],
18
+ * ['b', 2],
19
+ * ['c', 1]
20
+ * ]);
21
+ * const result = countBy(map, (value) => value);
22
+ * // result will be { 1: 2, 2: 1 }
23
+ *
24
+ * @example
25
+ * const map = new Map([
26
+ * ['alice', 20],
27
+ * ['bob', 30],
28
+ * ['carol', 20]
29
+ * ]);
30
+ * const result = countBy(map, (value, key) => key[0]);
31
+ * // result will be { a: 1, b: 1, c: 1 }
32
+ */
33
+ declare function countBy<K, V, K2 extends PropertyKey>(map: Map<K, V>, mapper: (value: V, key: K, object: Map<K, V>) => K2): Map<K2, number>;
34
+
35
+ export { countBy };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Counts the occurrences of items in a Map based on a transformation function.
3
+ *
4
+ * This function takes a Map and a function that generates a key from each value-key pair.
5
+ * It returns an object with the generated keys as properties and their counts as values.
6
+ * The count is incremented for each entry for which the transformation produces the same key.
7
+ *
8
+ * @template K - The type of the Map's keys.
9
+ * @template V - The type of the Map's values.
10
+ * @template K2 - The type of keys produced by the transformation function.
11
+ * @param {Map<K, V>} map - The Map to count occurrences from.
12
+ * @param {(value: V, key: K, object: Map<K, V>) => K2} mapper - The function to produce a key for counting.
13
+ * @returns {Record<K2, number>} An object containing the mapped keys and their counts.
14
+ *
15
+ * @example
16
+ * const map = new Map([
17
+ * ['a', 1],
18
+ * ['b', 2],
19
+ * ['c', 1]
20
+ * ]);
21
+ * const result = countBy(map, (value) => value);
22
+ * // result will be { 1: 2, 2: 1 }
23
+ *
24
+ * @example
25
+ * const map = new Map([
26
+ * ['alice', 20],
27
+ * ['bob', 30],
28
+ * ['carol', 20]
29
+ * ]);
30
+ * const result = countBy(map, (value, key) => key[0]);
31
+ * // result will be { a: 1, b: 1, c: 1 }
32
+ */
33
+ declare function countBy<K, V, K2 extends PropertyKey>(map: Map<K, V>, mapper: (value: V, key: K, object: Map<K, V>) => K2): Map<K2, number>;
34
+
35
+ export { countBy };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ function countBy(map, mapper) {
6
+ const result = new Map();
7
+ for (const [key, value] of map) {
8
+ const mappedKey = mapper(value, key, map);
9
+ result.set(mappedKey, (result.get(mappedKey) ?? 0) + 1);
10
+ }
11
+ return result;
12
+ }
13
+
14
+ exports.countBy = countBy;
@@ -0,0 +1,10 @@
1
+ function countBy(map, mapper) {
2
+ const result = new Map();
3
+ for (const [key, value] of map) {
4
+ const mappedKey = mapper(value, key, map);
5
+ result.set(mappedKey, (result.get(mappedKey) ?? 0) + 1);
6
+ }
7
+ return result;
8
+ }
9
+
10
+ export { countBy };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Executes a provided function once for each entry in a Map.
3
+ *
4
+ * This function iterates through all entries of the Map and executes the callback function
5
+ * for each entry. The callback receives the value, key, and the Map itself as arguments.
6
+ *
7
+ * @template K - The type of keys in the Map.
8
+ * @template V - The type of values in the Map.
9
+ * @param {Map<K, V>} map - The Map to iterate over.
10
+ * @param {(value: V, key: K, map: Map<K, V>) => void} callback - A function to execute for each entry.
11
+ * @returns {void}
12
+ *
13
+ * @example
14
+ * const map = new Map([
15
+ * ['a', 1],
16
+ * ['b', 2],
17
+ * ['c', 3]
18
+ * ]);
19
+ * forEach(map, (value, key) => {
20
+ * console.log(`${key}: ${value}`);
21
+ * });
22
+ * // Output:
23
+ * // a: 1
24
+ * // b: 2
25
+ * // c: 3
26
+ */
27
+ declare function forEach<K, V>(map: Map<K, V>, callback: (value: V, key: K, map: Map<K, V>) => void): void;
28
+
29
+ export { forEach };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Executes a provided function once for each entry in a Map.
3
+ *
4
+ * This function iterates through all entries of the Map and executes the callback function
5
+ * for each entry. The callback receives the value, key, and the Map itself as arguments.
6
+ *
7
+ * @template K - The type of keys in the Map.
8
+ * @template V - The type of values in the Map.
9
+ * @param {Map<K, V>} map - The Map to iterate over.
10
+ * @param {(value: V, key: K, map: Map<K, V>) => void} callback - A function to execute for each entry.
11
+ * @returns {void}
12
+ *
13
+ * @example
14
+ * const map = new Map([
15
+ * ['a', 1],
16
+ * ['b', 2],
17
+ * ['c', 3]
18
+ * ]);
19
+ * forEach(map, (value, key) => {
20
+ * console.log(`${key}: ${value}`);
21
+ * });
22
+ * // Output:
23
+ * // a: 1
24
+ * // b: 2
25
+ * // c: 3
26
+ */
27
+ declare function forEach<K, V>(map: Map<K, V>, callback: (value: V, key: K, map: Map<K, V>) => void): void;
28
+
29
+ export { forEach };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ function forEach(map, callback) {
6
+ for (const [key, value] of map) {
7
+ callback(value, key, map);
8
+ }
9
+ }
10
+
11
+ exports.forEach = forEach;
@@ -0,0 +1,7 @@
1
+ function forEach(map, callback) {
2
+ for (const [key, value] of map) {
3
+ callback(value, key, map);
4
+ }
5
+ }
6
+
7
+ export { forEach };
@@ -1,7 +1,9 @@
1
+ export { countBy } from './countBy.mjs';
1
2
  export { every } from './every.mjs';
2
3
  export { filter } from './filter.mjs';
3
4
  export { findKey } from './findKey.mjs';
4
5
  export { findValue } from './findValue.mjs';
6
+ export { forEach } from './forEach.mjs';
5
7
  export { hasValue } from './hasValue.mjs';
6
8
  export { keyBy } from './keyBy.mjs';
7
9
  export { mapKeys } from './mapKeys.mjs';
@@ -1,7 +1,9 @@
1
+ export { countBy } from './countBy.js';
1
2
  export { every } from './every.js';
2
3
  export { filter } from './filter.js';
3
4
  export { findKey } from './findKey.js';
4
5
  export { findValue } from './findValue.js';
6
+ export { forEach } from './forEach.js';
5
7
  export { hasValue } from './hasValue.js';
6
8
  export { keyBy } from './keyBy.js';
7
9
  export { mapKeys } from './mapKeys.js';
package/dist/map/index.js CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
+ const countBy = require('./countBy.js');
5
6
  const every = require('./every.js');
6
7
  const filter = require('./filter.js');
7
8
  const findKey = require('./findKey.js');
8
9
  const findValue = require('./findValue.js');
10
+ const forEach = require('./forEach.js');
9
11
  const hasValue = require('./hasValue.js');
10
12
  const keyBy = require('./keyBy.js');
11
13
  const mapKeys = require('./mapKeys.js');
@@ -15,10 +17,12 @@ const some = require('./some.js');
15
17
 
16
18
 
17
19
 
20
+ exports.countBy = countBy.countBy;
18
21
  exports.every = every.every;
19
22
  exports.filter = filter.filter;
20
23
  exports.findKey = findKey.findKey;
21
24
  exports.findValue = findValue.findValue;
25
+ exports.forEach = forEach.forEach;
22
26
  exports.hasValue = hasValue.hasValue;
23
27
  exports.keyBy = keyBy.keyBy;
24
28
  exports.mapKeys = mapKeys.mapKeys;
@@ -1,7 +1,9 @@
1
+ export { countBy } from './countBy.mjs';
1
2
  export { every } from './every.mjs';
2
3
  export { filter } from './filter.mjs';
3
4
  export { findKey } from './findKey.mjs';
4
5
  export { findValue } from './findValue.mjs';
6
+ export { forEach } from './forEach.mjs';
5
7
  export { hasValue } from './hasValue.mjs';
6
8
  export { keyBy } from './keyBy.mjs';
7
9
  export { mapKeys } from './mapKeys.mjs';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Executes a provided function once for each element in a Set.
3
+ *
4
+ * This function iterates through all elements of the Set and executes the callback function
5
+ * for each element. The callback receives the value twice (for consistency with Map.forEach)
6
+ * and the Set itself as arguments.
7
+ *
8
+ * @template T - The type of elements in the Set.
9
+ * @param {Set<T>} set - The Set to iterate over.
10
+ * @param {(value: T, value2: T, set: Set<T>) => void} callback - A function to execute for each element.
11
+ * @returns {void}
12
+ *
13
+ * @example
14
+ * const set = new Set([1, 2, 3]);
15
+ * forEach(set, (value) => {
16
+ * console.log(value * 2);
17
+ * });
18
+ * // Output:
19
+ * // 2
20
+ * // 4
21
+ * // 6
22
+ */
23
+ declare function forEach<T>(set: Set<T>, callback: (value: T, value2: T, set: Set<T>) => void): void;
24
+
25
+ export { forEach };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Executes a provided function once for each element in a Set.
3
+ *
4
+ * This function iterates through all elements of the Set and executes the callback function
5
+ * for each element. The callback receives the value twice (for consistency with Map.forEach)
6
+ * and the Set itself as arguments.
7
+ *
8
+ * @template T - The type of elements in the Set.
9
+ * @param {Set<T>} set - The Set to iterate over.
10
+ * @param {(value: T, value2: T, set: Set<T>) => void} callback - A function to execute for each element.
11
+ * @returns {void}
12
+ *
13
+ * @example
14
+ * const set = new Set([1, 2, 3]);
15
+ * forEach(set, (value) => {
16
+ * console.log(value * 2);
17
+ * });
18
+ * // Output:
19
+ * // 2
20
+ * // 4
21
+ * // 6
22
+ */
23
+ declare function forEach<T>(set: Set<T>, callback: (value: T, value2: T, set: Set<T>) => void): void;
24
+
25
+ export { forEach };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ function forEach(set, callback) {
6
+ for (const value of set) {
7
+ callback(value, value, set);
8
+ }
9
+ }
10
+
11
+ exports.forEach = forEach;
@@ -0,0 +1,7 @@
1
+ function forEach(set, callback) {
2
+ for (const value of set) {
3
+ callback(value, value, set);
4
+ }
5
+ }
6
+
7
+ export { forEach };
@@ -2,6 +2,7 @@ export { countBy } from './countBy.mjs';
2
2
  export { every } from './every.mjs';
3
3
  export { filter } from './filter.mjs';
4
4
  export { find } from './find.mjs';
5
+ export { forEach } from './forEach.mjs';
5
6
  export { keyBy } from './keyBy.mjs';
6
7
  export { map } from './map.mjs';
7
8
  export { reduce } from './reduce.mjs';
@@ -2,6 +2,7 @@ export { countBy } from './countBy.js';
2
2
  export { every } from './every.js';
3
3
  export { filter } from './filter.js';
4
4
  export { find } from './find.js';
5
+ export { forEach } from './forEach.js';
5
6
  export { keyBy } from './keyBy.js';
6
7
  export { map } from './map.js';
7
8
  export { reduce } from './reduce.js';
package/dist/set/index.js CHANGED
@@ -6,6 +6,7 @@ const countBy = require('./countBy.js');
6
6
  const every = require('./every.js');
7
7
  const filter = require('./filter.js');
8
8
  const find = require('./find.js');
9
+ const forEach = require('./forEach.js');
9
10
  const keyBy = require('./keyBy.js');
10
11
  const map = require('./map.js');
11
12
  const reduce = require('./reduce.js');
@@ -17,6 +18,7 @@ exports.countBy = countBy.countBy;
17
18
  exports.every = every.every;
18
19
  exports.filter = filter.filter;
19
20
  exports.find = find.find;
21
+ exports.forEach = forEach.forEach;
20
22
  exports.keyBy = keyBy.keyBy;
21
23
  exports.map = map.map;
22
24
  exports.reduce = reduce.reduce;
@@ -2,6 +2,7 @@ export { countBy } from './countBy.mjs';
2
2
  export { every } from './every.mjs';
3
3
  export { filter } from './filter.mjs';
4
4
  export { find } from './find.mjs';
5
+ export { forEach } from './forEach.mjs';
5
6
  export { keyBy } from './keyBy.mjs';
6
7
  export { map } from './map.mjs';
7
8
  export { reduce } from './reduce.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
- "version": "1.46.0-dev.1789+a1c32498",
3
+ "version": "1.46.0-dev.1791+50d799e5",
4
4
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
5
5
  "homepage": "https://es-toolkit.dev",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",