@augment-vir/common 31.26.0 → 31.27.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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Finds all duplicates.
3
+ *
4
+ * @category Array
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {extractDuplicates} from '@augment-vir/common';
10
+ *
11
+ * const result = extractDuplicates([
12
+ * 'a',
13
+ * 'b',
14
+ * '',
15
+ * 'a',
16
+ * ]);
17
+ * // result is `{duplicates: ['a'], uniques: ['b', '']}`
18
+ * ```
19
+ *
20
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
21
+ */
22
+ export declare function extractDuplicates<T>(items: ReadonlyArray<T>, comparator?: (a: T, b: T) => boolean): {
23
+ duplicates: T[];
24
+ uniques: T[];
25
+ };
@@ -0,0 +1,43 @@
1
+ import { check } from '@augment-vir/assert';
2
+ /**
3
+ * Finds all duplicates.
4
+ *
5
+ * @category Array
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {extractDuplicates} from '@augment-vir/common';
11
+ *
12
+ * const result = extractDuplicates([
13
+ * 'a',
14
+ * 'b',
15
+ * '',
16
+ * 'a',
17
+ * ]);
18
+ * // result is `{duplicates: ['a'], uniques: ['b', '']}`
19
+ * ```
20
+ *
21
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
+ */
23
+ export function extractDuplicates(items, comparator = check.strictEquals) {
24
+ const duplicates = [];
25
+ const uniques = [];
26
+ items.forEach((item) => {
27
+ const duplicatesIndex = duplicates.findIndex((duplicateEntry) => comparator(duplicateEntry, item));
28
+ if (duplicatesIndex < 0) {
29
+ const uniquesIndex = uniques.findIndex((uniqueEntry) => comparator(uniqueEntry, item));
30
+ if (uniquesIndex < 0) {
31
+ uniques.push(item);
32
+ }
33
+ else {
34
+ uniques.splice(uniquesIndex, 1);
35
+ duplicates.push(item);
36
+ }
37
+ }
38
+ });
39
+ return {
40
+ duplicates,
41
+ uniques,
42
+ };
43
+ }
@@ -30,7 +30,10 @@ export class PromiseTimeoutError extends Error {
30
30
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
31
31
  */
32
32
  export function wrapPromiseInTimeout(duration, originalPromise, failureMessage) {
33
- const milliseconds = convertDuration(duration, { milliseconds: true }).milliseconds;
33
+ const isInfinity = Object.values(duration).some((value) => value && check.isInfinite(value));
34
+ const milliseconds = isInfinity
35
+ ? Infinity
36
+ : convertDuration(duration, { milliseconds: true }).milliseconds;
34
37
  return new Promise(async (resolve, reject) => {
35
38
  const timeoutId = milliseconds === Infinity
36
39
  ? undefined
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './augments/array/awaited/awaited-filter.js';
5
5
  export * from './augments/array/awaited/awaited-for-each.js';
6
6
  export * from './augments/array/awaited/awaited-map.js';
7
7
  export * from './augments/array/create-array.js';
8
+ export * from './augments/array/extract-duplicates.js';
8
9
  export * from './augments/array/filter.js';
9
10
  export * from './augments/array/remove-duplicates.js';
10
11
  export * from './augments/array/repeat-array.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './augments/array/awaited/awaited-filter.js';
5
5
  export * from './augments/array/awaited/awaited-for-each.js';
6
6
  export * from './augments/array/awaited/awaited-map.js';
7
7
  export * from './augments/array/create-array.js';
8
+ export * from './augments/array/extract-duplicates.js';
8
9
  export * from './augments/array/filter.js';
9
10
  export * from './augments/array/remove-duplicates.js';
10
11
  export * from './augments/array/repeat-array.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.26.0",
3
+ "version": "31.27.0",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -40,9 +40,9 @@
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.26.0",
44
- "@augment-vir/core": "^31.26.0",
45
- "@date-vir/duration": "^7.3.1",
43
+ "@augment-vir/assert": "^31.27.0",
44
+ "@augment-vir/core": "^31.27.0",
45
+ "@date-vir/duration": "^7.3.2",
46
46
  "ansi-styles": "^6.2.1",
47
47
  "deepcopy-esm": "^2.1.1",
48
48
  "json5": "^2.2.3",
@@ -55,7 +55,7 @@
55
55
  "@web/test-runner-commands": "^0.9.0",
56
56
  "@web/test-runner-playwright": "^0.11.1",
57
57
  "@web/test-runner-visual-regression": "^0.10.0",
58
- "concurrently": "^9.1.2",
58
+ "concurrently": "^9.2.0",
59
59
  "execute-in-browser": "^1.0.7",
60
60
  "istanbul-smart-text-reporter": "^1.1.5",
61
61
  "typescript": "^5.8.3"