@augment-vir/common 28.0.0 → 28.0.1

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterMap = exports.arrayToObject = exports.groupArrayBy = exports.repeatArray = exports.typedMap = exports.typedArrayIncludes = exports.trimArrayStrings = exports.flatten2dArray = exports.filterOutIndexes = void 0;
4
+ const get_or_set_1 = require("../object/get-or-set");
4
5
  const object_entries_1 = require("../object/object-entries");
5
6
  function filterOutIndexes(array, indexes) {
6
7
  return array.filter((_, index) => !indexes.includes(index));
@@ -35,10 +36,8 @@ exports.repeatArray = repeatArray;
35
36
  function groupArrayBy(inputArray, callback) {
36
37
  return inputArray.reduce((accum, entry, index, originalArray) => {
37
38
  const key = callback(entry, index, originalArray);
38
- if (!(key in accum)) {
39
- accum[key] = [];
40
- }
41
- accum[key].push(entry);
39
+ const entryArray = (0, get_or_set_1.getOrSet)(accum, key, () => []);
40
+ entryArray.push(entry);
42
41
  return accum;
43
42
  }, {});
44
43
  }
@@ -1,3 +1,4 @@
1
+ import { getOrSet } from '../object/get-or-set';
1
2
  import { typedObjectFromEntries } from '../object/object-entries';
2
3
  export function filterOutIndexes(array, indexes) {
3
4
  return array.filter((_, index) => !indexes.includes(index));
@@ -26,10 +27,8 @@ export function repeatArray(repeatCount, array) {
26
27
  export function groupArrayBy(inputArray, callback) {
27
28
  return inputArray.reduce((accum, entry, index, originalArray) => {
28
29
  const key = callback(entry, index, originalArray);
29
- if (!(key in accum)) {
30
- accum[key] = [];
31
- }
32
- accum[key].push(entry);
30
+ const entryArray = getOrSet(accum, key, () => []);
31
+ entryArray.push(entry);
33
32
  return accum;
34
33
  }, {});
35
34
  }
@@ -15,12 +15,12 @@ export declare function repeatArray<T>(repeatCount: number, array: T[]): T[];
15
15
  * Polyfill for `Object.groupBy`:
16
16
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy
17
17
  */
18
- export declare function groupArrayBy<ElementType, NewKey extends PropertyKey>(inputArray: ReadonlyArray<ElementType>, callback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => NewKey): Record<NewKey, ElementType[]>;
18
+ export declare function groupArrayBy<ElementType, NewKey extends PropertyKey>(inputArray: ReadonlyArray<ElementType>, callback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => NewKey): Partial<Record<NewKey, ElementType[]>>;
19
19
  /**
20
20
  * Like `groupArrayBy` but maps array entries to a single key. Meaning, the resulting object does
21
21
  * not have an array of elements (unless the original array itself contains arrays).
22
22
  */
23
- export declare function arrayToObject<ElementType, NewKey extends PropertyKey>(inputArray: ReadonlyArray<ElementType>, callback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => NewKey): Record<NewKey, ElementType>;
23
+ export declare function arrayToObject<ElementType, NewKey extends PropertyKey>(inputArray: ReadonlyArray<ElementType>, callback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => NewKey): Partial<Record<NewKey, ElementType>>;
24
24
  export declare function filterMap<ElementType, MappedEntry, TypeGuarded extends MappedEntry>(inputArray: ReadonlyArray<ElementType>, mapCallback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => MappedEntry, filterCallback: (mappedOutput: MappedEntry, originalEntry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => mappedOutput is TypeGuarded): TypeGuarded[];
25
25
  export declare function filterMap<ElementType, MappedEntry>(inputArray: ReadonlyArray<ElementType>, mapCallback: (entry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => MappedEntry, filterCallback: (mappedOutput: MappedEntry, originalEntry: ElementType, index: number, originalArray: ReadonlyArray<ElementType>) => boolean): MappedEntry[];
26
26
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "28.0.0",
3
+ "version": "28.0.1",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"