The object to be tested.
The base object that defines the structure and types to test against.
true
if objectToTest
conforms to the structure and types of base
, otherwise false
.
// Example 1: Simple type check
const objectToTest1 = { a: 1, b: "string" };
const base1 = { a: "number", b: "string" };
console.log(testForObjectTypeExtension(objectToTest1, base1)); // true
// Example 2: Nested object type check
const objectToTest2 = { a: { b: 2 } };
const base2 = { a: { b: "number" } };
console.log(testForObjectTypeExtension(objectToTest2, base2)); // true
// Example 3: Constructor name check
const objectToTest3 = { a: new Date() };
const base3 = { a: "[object Date]" };
console.log(testForObjectTypeExtension(objectToTest3, base3)); // true
// Example 4: Failing type check
const objectToTest4 = { a: 1, b: "string" };
const base4 = { a: "string", b: "number" };
console.log(testForObjectTypeExtension(objectToTest4, base4)); // false
// Example 5: Type check with [typeof ] syntax
const objectToTest5 = { a: 1, b: "string" };
const base5 = { a: "[typeof number]", b: "[typeof string]" };
console.log(testForObjectTypeExtension(objectToTest5, base5)); // true
// Example 6: Exact string match with [string ] syntax
const objectToTest6 = { a: "hello" };
const base6 = { a: "[string \"hello\"]" };
console.log(testForObjectTypeExtension(objectToTest6, base6)); // true
// Example 7: Exact number match with [number ] syntax
const objectToTest7 = { a: 42.45327 };
const base7 = { a: "[number 42.45327]" };
console.log(testForObjectTypeExtension(objectToTest7, base7)); // true
Tests if an object conforms to the structure and types defined by a base object.