Function hasProperties

  • Checks if an object has all the specified properties.

    Remarks

    This function uses the hasProperty function to check if the object has each property specified in the props array.

    Example

    const user = { name: "John", age: 25 };
    hasProperties(user, ["name", "age"]);
    // => { ok: true, value: 'true' }

    hasProperties(user, ["name", "email"]);
    // => { ok: true, value: 'false' }

    Example

    Handle invalid input parameters:

    const user = { name: "John", age: 25 };
    hasProperties(null, ["name", "age"]);
    // => { ok: false, error: Error('[objects.hasProperties] Expected a plain javascript object') }

    hasProperties(user, null);
    // => { ok: false, error: Error('[objects.hasProperties] Expected an array of property keys') }

    Type Parameters

    • T extends Record<string, any>

    • K extends PropertyKey

    Parameters

    • obj: T

      The object to check for the properties.

    • keys: K[]

    Returns Result<boolean, Error>

    A Result object with either a boolean value indicating whether the object has all the specified properties or not, or an Error object if any of the inputs are invalid.

Generated using TypeDoc v0.24.7