@augment-vir/common 31.26.0 → 31.28.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
+ }
@@ -0,0 +1,17 @@
1
+ import { type AnyObject } from '@augment-vir/core';
2
+ /**
3
+ * Gets the type of a nested property within `Parent` by recursively accessing each key in `Keys`.
4
+ *
5
+ * @category Object
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export type DeepValue<Parent extends AnyObject, Keys extends ReadonlyArray<PropertyKey>> = Keys extends Readonly<[infer First, ...infer Rest]> ? First extends keyof Parent ? Rest extends ReadonlyArray<PropertyKey> ? DeepValue<Parent[First], Rest> : undefined : undefined : Parent;
10
+ /**
11
+ * Gets the value of a nested property within `Parent` by recursively accessing each key in `Keys`.
12
+ *
13
+ * @category Object
14
+ * @category Package : @augment-vir/common
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export declare function getDeepValue<const Parent extends AnyObject, const Keys extends ReadonlyArray<PropertyKey>>(parent: Parent, keys: Readonly<Keys>): DeepValue<Parent, Keys>;
@@ -0,0 +1,21 @@
1
+ import { check } from '@augment-vir/assert';
2
+ /**
3
+ * Gets the value of a nested property within `Parent` by recursively accessing each key in `Keys`.
4
+ *
5
+ * @category Object
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
9
+ export function getDeepValue(parent, keys) {
10
+ if (!keys.length) {
11
+ return parent;
12
+ }
13
+ const innerParent = parent;
14
+ const currentKey = keys[0];
15
+ if (currentKey != undefined && check.hasKey(innerParent, currentKey)) {
16
+ return getDeepValue(innerParent[currentKey], keys.slice(1));
17
+ }
18
+ else {
19
+ return undefined;
20
+ }
21
+ }
@@ -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';
@@ -38,6 +39,7 @@ export * from './augments/number/scientific.js';
38
39
  export * from './augments/number/truncate-number.js';
39
40
  export * from './augments/number/wrap-number.js';
40
41
  export * from './augments/object/deep-copy.js';
42
+ export * from './augments/object/deep-value.js';
41
43
  export * from './augments/object/diff.js';
42
44
  export * from './augments/object/empty.js';
43
45
  export * from './augments/object/get-or-set.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';
@@ -38,6 +39,7 @@ export * from './augments/number/scientific.js';
38
39
  export * from './augments/number/truncate-number.js';
39
40
  export * from './augments/number/wrap-number.js';
40
41
  export * from './augments/object/deep-copy.js';
42
+ export * from './augments/object/deep-value.js';
41
43
  export * from './augments/object/diff.js';
42
44
  export * from './augments/object/empty.js';
43
45
  export * from './augments/object/get-or-set.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.28.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.28.0",
44
+ "@augment-vir/core": "^31.28.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,8 +55,8 @@
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",
59
- "execute-in-browser": "^1.0.7",
58
+ "concurrently": "^9.2.0",
59
+ "execute-in-browser": "^1.0.8",
60
60
  "istanbul-smart-text-reporter": "^1.1.5",
61
61
  "typescript": "^5.8.3"
62
62
  },