@hedia/test
Advanced tools
Comparing version 3.2.0 to 3.3.0
export declare function randomString(length: number, { asciiOnly }?: { | ||
asciiOnly?: boolean; | ||
}): string; | ||
export declare function matchObject(object: unknown, match: unknown): void; |
@@ -0,1 +1,2 @@ | ||
import assert from "node:assert"; | ||
export function randomString(length, { asciiOnly = false } = {}) { | ||
@@ -12,2 +13,29 @@ let chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
} | ||
// In the future, this can be replaced with upcoming native node.js functionality: https://github.com/nodejs/node/issues/50399 | ||
export function matchObject(object, match) { | ||
assert(typeof object === typeof match, "Type mismatch"); | ||
assert(Array.isArray(object) === Array.isArray(match), "Type mismatch"); | ||
if (object === null || match === null) { | ||
return; | ||
} | ||
if (object === undefined || match === undefined) { | ||
return; | ||
} | ||
if (Array.isArray(object) && Array.isArray(match)) { | ||
assert(object.length === match.length, "Array length mismatch"); | ||
for (let i = 0; i < object.length; i++) { | ||
matchObject(object[i], match[i]); | ||
} | ||
return; | ||
} | ||
else if (typeof object == "object" && typeof match == "object") { | ||
for (const [key, value] of Object.entries(match)) { | ||
assert(Object.hasOwn(object, key), "Key mismatch"); | ||
matchObject(object[key], value); | ||
} | ||
} | ||
else { | ||
assert(object === match, "Value mismatch"); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@hedia/test", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Tools for testing and reporting", | ||
@@ -33,3 +33,3 @@ "homepage": "https://github.com/hedia-team/test#readme", | ||
"package:lint": "npx npm-package-json-lint .", | ||
"pretest": "mkdir -p reports", | ||
"pretest": "rm -rf reports && mkdir reports", | ||
"prettier:check": "prettier --check .", | ||
@@ -45,3 +45,3 @@ "prettier:write": "prettier --write .", | ||
"dependencies": { | ||
"@hedia/html": "^2.3.0" | ||
"@hedia/html": "^3.4.2" | ||
}, | ||
@@ -53,3 +53,3 @@ "devDependencies": { | ||
"@hedia/tsconfig": "2.1.1", | ||
"@types/node": "22.7.5" | ||
"@types/node": "22.8.6" | ||
}, | ||
@@ -56,0 +56,0 @@ "engines": { |
@@ -78,2 +78,14 @@ # Test | ||
### matchObject | ||
The matchObject function is used to compare two objects. It will throw an error if the object in the first argument does not match the object in the second argument, meaning that it has at least the same properties. | ||
```TypeScript | ||
import { matchObject } from "@hedia/test"; | ||
matchObject([{ a: 1, b: 2 }], [{ a: 1 }]); // Won't throw an error | ||
matchObject([{ a: 1, b: 2 }], [{ a: 1, b: 2 }]); // Won't throw an error | ||
matchObject([{ a: 1 }], [{ a: 1, b: 2 }]); // Will throw an error | ||
``` | ||
## Custom Test Reporters | ||
@@ -80,0 +92,0 @@ |
@@ -0,1 +1,3 @@ | ||
import assert from "node:assert"; | ||
export function randomString(length: number, { asciiOnly = false }: { asciiOnly?: boolean } = {}): string { | ||
@@ -12,1 +14,29 @@ let chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
} | ||
// In the future, this can be replaced with upcoming native node.js functionality: https://github.com/nodejs/node/issues/50399 | ||
export function matchObject(object: unknown, match: unknown): void { | ||
assert(typeof object === typeof match, "Type mismatch"); | ||
assert(Array.isArray(object) === Array.isArray(match), "Type mismatch"); | ||
if (object === null || match === null) { | ||
return; | ||
} | ||
if (object === undefined || match === undefined) { | ||
return; | ||
} | ||
if (Array.isArray(object) && Array.isArray(match)) { | ||
assert(object.length === match.length, "Array length mismatch"); | ||
for (let i = 0; i < object.length; i++) { | ||
matchObject(object[i], match[i]); | ||
} | ||
return; | ||
} else if (typeof object == "object" && typeof match == "object") { | ||
for (const [key, value] of Object.entries(match)) { | ||
assert(Object.hasOwn(object, key), "Key mismatch"); | ||
matchObject(object[key as keyof object], value); | ||
} | ||
} else { | ||
assert(object === match, "Value mismatch"); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102831
31
977
115
Updated@hedia/html@^3.4.2