@trackunit/shared-utils 0.0.13 → 0.0.14

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/index.cjs.js CHANGED
@@ -423,24 +423,28 @@ searchTerm) => {
423
423
  /**
424
424
  * Group an array of items by a key.
425
425
  *
426
- * @param list The array of items to group.
427
- * @param getKey A function to get the key to group by.
428
- * @returns A map of the items grouped by the key.
429
- * @example groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname) // Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
426
+ * @template T The type of items in the list.
427
+ * @template K The type of the key.
428
+ * @param {T[]} list The array of items to group.
429
+ * @param {(item: T) => K} getKey A function to get the key to group by.
430
+ * @returns {Map<K, T[]>} A map of the items grouped by the key.
431
+ * @example
432
+ * groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname)
433
+ * Returns: Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
430
434
  */
431
435
  function groupBy(list, getKey) {
432
- const map = new Map();
436
+ const groupedMap = new Map();
433
437
  list.forEach(item => {
434
438
  const key = getKey(item);
435
- const collection = map.get(key);
439
+ const collection = groupedMap.get(key);
436
440
  if (!collection) {
437
- map.set(key, [item]);
441
+ groupedMap.set(key, [item]);
438
442
  }
439
443
  else {
440
444
  collection.push(item);
441
445
  }
442
446
  });
443
- return map;
447
+ return groupedMap;
444
448
  }
445
449
 
446
450
  const UUID_HYPHEN_POSITIONS = [8, 12, 16, 20];
package/index.esm.js CHANGED
@@ -419,24 +419,28 @@ searchTerm) => {
419
419
  /**
420
420
  * Group an array of items by a key.
421
421
  *
422
- * @param list The array of items to group.
423
- * @param getKey A function to get the key to group by.
424
- * @returns A map of the items grouped by the key.
425
- * @example groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname) // Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
422
+ * @template T The type of items in the list.
423
+ * @template K The type of the key.
424
+ * @param {T[]} list The array of items to group.
425
+ * @param {(item: T) => K} getKey A function to get the key to group by.
426
+ * @returns {Map<K, T[]>} A map of the items grouped by the key.
427
+ * @example
428
+ * groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname)
429
+ * Returns: Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
426
430
  */
427
431
  function groupBy(list, getKey) {
428
- const map = new Map();
432
+ const groupedMap = new Map();
429
433
  list.forEach(item => {
430
434
  const key = getKey(item);
431
- const collection = map.get(key);
435
+ const collection = groupedMap.get(key);
432
436
  if (!collection) {
433
- map.set(key, [item]);
437
+ groupedMap.set(key, [item]);
434
438
  }
435
439
  else {
436
440
  collection.push(item);
437
441
  }
438
442
  });
439
- return map;
443
+ return groupedMap;
440
444
  }
441
445
 
442
446
  const UUID_HYPHEN_POSITIONS = [8, 12, 16, 20];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/shared-utils",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * Group an array of items by a key.
3
3
  *
4
- * @param list The array of items to group.
5
- * @param getKey A function to get the key to group by.
6
- * @returns A map of the items grouped by the key.
7
- * @example groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname) // Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
4
+ * @template T The type of items in the list.
5
+ * @template K The type of the key.
6
+ * @param {T[]} list The array of items to group.
7
+ * @param {(item: T) => K} getKey A function to get the key to group by.
8
+ * @returns {Map<K, T[]>} A map of the items grouped by the key.
9
+ * @example
10
+ * groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname)
11
+ * Returns: Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
8
12
  */
9
13
  export declare function groupBy<T, K>(list: T[], getKey: (item: T) => K): Map<K, T[]>;