@augment-vir/assert 30.2.0 → 30.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,21 +1,24 @@
1
1
  import { type MaybePromise } from '@augment-vir/core';
2
2
  /**
3
- * Runs a custom provided checker that is applied deeply to any given variables. Automatically
4
- * handles async custom checkers.
3
+ * Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
4
+ * and the custom checker is only run on primitives. This function automatically handles async
5
+ * custom checkers and circular references.
5
6
  *
6
7
  * @category Assert
7
8
  */
8
9
  export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => boolean): boolean;
9
10
  /**
10
- * Runs a custom provided checker that is applied deeply to any given variables. Automatically
11
- * handles async custom checkers.
11
+ * Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
12
+ * and the custom checker is only run on primitives. This function automatically handles async
13
+ * custom checkers and circular references.
12
14
  *
13
15
  * @category Assert
14
16
  */
15
17
  export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => Promise<boolean>): Promise<boolean>;
16
18
  /**
17
- * Runs a custom provided checker that is applied deeply to any given variables. Automatically
18
- * handles async custom checkers.
19
+ * Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
20
+ * and the custom checker is only run on primitives. This function automatically handles async
21
+ * custom checkers and circular references.
19
22
  *
20
23
  * @category Assert
21
24
  */
@@ -1,21 +1,30 @@
1
1
  import { ensureError, getObjectTypedKeys, } from '@augment-vir/core';
2
2
  import { check } from './guards/check.js';
3
3
  /**
4
- * Runs a custom provided checker that is applied deeply to any given variables. Automatically
5
- * handles async custom checkers.
4
+ * Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
5
+ * and the custom checker is only run on primitives. This function automatically handles async
6
+ * custom checkers and circular references.
6
7
  *
7
8
  * @category Assert
8
9
  */
9
10
  export function checkCustomDeepQuality(a, b, customChecker) {
11
+ return recursiveCheckCustomDeepQuality(a, b, customChecker, new Set());
12
+ }
13
+ function recursiveCheckCustomDeepQuality(a, b, customChecker, checkedObjects) {
10
14
  a = flattenComplexObject(a);
11
15
  b = flattenComplexObject(b);
12
16
  if (check.isObject(a) && check.isObject(b)) {
13
- if (!checkCustomDeepQuality(getObjectTypedKeys(a).sort(), getObjectTypedKeys(b).sort(), customChecker)) {
17
+ if (checkedObjects.has(a) || checkedObjects.has(b)) {
18
+ return true;
19
+ }
20
+ checkedObjects.add(a);
21
+ checkedObjects.add(b);
22
+ if (!recursiveCheckCustomDeepQuality(getObjectTypedKeys(a).sort(), getObjectTypedKeys(b).sort(), customChecker, checkedObjects)) {
14
23
  return false;
15
24
  }
16
25
  let receivedPromise = false;
17
26
  const results = getObjectTypedKeys(a).map((key) => {
18
- const result = checkCustomDeepQuality(a[key], b[key], customChecker);
27
+ const result = recursiveCheckCustomDeepQuality(a[key], b[key], customChecker, checkedObjects);
19
28
  if (check.isPromise(result)) {
20
29
  receivedPromise = true;
21
30
  }
@@ -24,12 +33,17 @@ export function checkCustomDeepQuality(a, b, customChecker) {
24
33
  return handleMaybePromise(receivedPromise, results);
25
34
  }
26
35
  else if (check.isArray(a) && check.isArray(b)) {
36
+ if (checkedObjects.has(a) || checkedObjects.has(b)) {
37
+ return true;
38
+ }
39
+ checkedObjects.add(a);
40
+ checkedObjects.add(b);
27
41
  if (a.length !== b.length) {
28
42
  return false;
29
43
  }
30
44
  let receivedPromise = false;
31
45
  const results = a.map((entry, index) => {
32
- const result = checkCustomDeepQuality(entry, b[index], customChecker);
46
+ const result = recursiveCheckCustomDeepQuality(entry, b[index], customChecker, checkedObjects);
33
47
  if (check.isPromise(result)) {
34
48
  receivedPromise = true;
35
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/assert",
3
- "version": "30.2.0",
3
+ "version": "30.4.0",
4
4
  "description": "A collection of assertions for test and production code alike.",
5
5
  "keywords": [
6
6
  "augment",
@@ -41,22 +41,22 @@
41
41
  "test:update": "npm test"
42
42
  },
43
43
  "dependencies": {
44
- "@augment-vir/core": "^30.2.0",
44
+ "@augment-vir/core": "^30.4.0",
45
45
  "@date-vir/duration": "^6.0.1",
46
46
  "deep-eql": "^5.0.2",
47
- "expect-type": "^0.20.0",
47
+ "expect-type": "^1.1.0",
48
48
  "type-fest": "^4.26.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/deep-eql": "^4.0.2",
52
- "@web/dev-server-esbuild": "^1.0.2",
52
+ "@web/dev-server-esbuild": "^1.0.3",
53
53
  "@web/test-runner": "^0.19.0",
54
54
  "@web/test-runner-commands": "^0.9.0",
55
55
  "@web/test-runner-playwright": "^0.11.0",
56
56
  "@web/test-runner-visual-regression": "^0.10.0",
57
57
  "c8": "^10.1.2",
58
- "istanbul-smart-text-reporter": "^1.1.4",
59
- "typescript": "^5.6.2"
58
+ "istanbul-smart-text-reporter": "^1.1.5",
59
+ "typescript": "^5.6.3"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=22"