@augment-vir/common 23.3.4 → 23.4.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,7 +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 object_entries_1 = require("./object/object-entries");
4
+ const object_entries_1 = require("../object/object-entries");
5
5
  function filterOutIndexes(array, indexes) {
6
6
  return array.filter((_, index) => !indexes.includes(index));
7
7
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeDuplicates = void 0;
4
+ function removeDuplicates(originalArray, calculateUniqueIdCallback) {
5
+ const grouped = new Map();
6
+ return originalArray.filter((entry) => {
7
+ const uniqueId = calculateUniqueIdCallback(entry);
8
+ if (grouped.get(uniqueId)) {
9
+ return false;
10
+ }
11
+ else {
12
+ grouped.set(uniqueId, entry);
13
+ return true;
14
+ }
15
+ });
16
+ }
17
+ exports.removeDuplicates = removeDuplicates;
package/dist/cjs/index.js CHANGED
@@ -15,7 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./augments/ansi"), exports);
18
- __exportStar(require("./augments/array"), exports);
18
+ __exportStar(require("./augments/array/array"), exports);
19
+ __exportStar(require("./augments/array/remove-duplicates"), exports);
19
20
  __exportStar(require("./augments/async"), exports);
20
21
  __exportStar(require("./augments/boolean"), exports);
21
22
  __exportStar(require("./augments/common-number"), exports);
@@ -1,4 +1,4 @@
1
- import { typedObjectFromEntries } from './object/object-entries';
1
+ import { typedObjectFromEntries } from '../object/object-entries';
2
2
  export function filterOutIndexes(array, indexes) {
3
3
  return array.filter((_, index) => !indexes.includes(index));
4
4
  }
@@ -0,0 +1,13 @@
1
+ export function removeDuplicates(originalArray, calculateUniqueIdCallback) {
2
+ const grouped = new Map();
3
+ return originalArray.filter((entry) => {
4
+ const uniqueId = calculateUniqueIdCallback(entry);
5
+ if (grouped.get(uniqueId)) {
6
+ return false;
7
+ }
8
+ else {
9
+ grouped.set(uniqueId, entry);
10
+ return true;
11
+ }
12
+ });
13
+ }
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './augments/ansi';
2
- export * from './augments/array';
2
+ export * from './augments/array/array';
3
+ export * from './augments/array/remove-duplicates';
3
4
  export * from './augments/async';
4
5
  export * from './augments/boolean';
5
6
  export * from './augments/common-number';
@@ -1,5 +1,5 @@
1
- import { AtLeastTuple } from './tuple';
2
- import { ArrayElement } from './type';
1
+ import { AtLeastTuple } from '../tuple';
2
+ import { ArrayElement } from '../type';
3
3
  export declare function filterOutIndexes<T>(array: ReadonlyArray<T>, indexes: ReadonlyArray<number>): T[];
4
4
  export declare function flatten2dArray<T>(array2d: ReadonlyArray<ReadonlyArray<T>>): T[];
5
5
  export type AtLeastOneEntryArray<ArrayGeneric extends ReadonlyArray<any>> = AtLeastTuple<ArrayElement<ArrayGeneric>, 1>;
@@ -0,0 +1 @@
1
+ export declare function removeDuplicates<Entry, UniqueId>(originalArray: ReadonlyArray<Readonly<Entry>>, calculateUniqueIdCallback: (entry: Readonly<Entry>) => UniqueId): Readonly<Entry>[];
@@ -1,4 +1,4 @@
1
- import { AtLeastOneEntryArray } from '../array';
1
+ import { AtLeastOneEntryArray } from '../array/array';
2
2
  import { NoInfer } from '../type';
3
3
  /**
4
4
  * Checks that the first input, testThisOne, matches the object shape of the second input,
@@ -1,5 +1,6 @@
1
1
  export * from './augments/ansi';
2
- export * from './augments/array';
2
+ export * from './augments/array/array';
3
+ export * from './augments/array/remove-duplicates';
3
4
  export * from './augments/async';
4
5
  export * from './augments/boolean';
5
6
  export * from './augments/common-number';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "23.3.4",
3
+ "version": "23.4.0",
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"