check

The check() method is the core validation function of the library. It is used to validate that a value matches a specified type.

Usage

Validate.check(value, type);

Parameters

  • value (any): The value to validate.

  • type (string): The expected type for the value. Must be one of:

    • "number"

    • "string"

    • "boolean"

    • "bigint"

    • "undefined"

    • "null"

    • "symbol"

    • "array"

    • "object"

    • "infinity"

    • "-infinity"

    • "nan"

    • "date"

    • "regexp"

    • "map"

    • "set"

    • "weakmap"

    • "weakset"

Return Value

  • Returns true if the value matches the expected type.

  • Returns false if the value does not match the expected type.


Examples

Behavior

  • Performs a strict type check.

  • Does not coerce types (e.g., "123" is not a "number").

  • Returns true only when the type matches exactly.

  • Returns false when types do not match (unless silent mode is off, see below).

Error Messages (Silent Mode Off)

If silent mode is disabled (Validate.silent(false)), validation errors will throw clear exceptions:

Last updated