• Tests if an object conforms to the structure and types defined by a base object.

    Parameters

    • objectToTest: object

      The object to be tested.

    • base: object

      The base object that defines the structure and types to test against.

    Returns boolean

    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
    // Example 8: Exact bigint match with [bigint ] syntax
    const objectToTest8 = { a: 42n, b: -57n };
    const base8 = { a: "[bigint 42n]", b: "[bigint -57]" };
    console.log(testForObjectTypeExtension(objectToTest8, base8)); // true
    // Example 9: Exact boolean match with [boolean ] syntax
    const objectToTest9 = { a: true };
    const base9 = { a: "[boolean true]" };
    console.log(testForObjectTypeExtension(objectToTest9, base9)); // true