Skip to content

Overview

Semantic validators ensure that a value not only meets its basic primitive or structural type but also conforms to a conventional meaning or format, such as date strings, email addresses, or specific identifier patterns. They return a structured ValidationResult<T>, never throw exceptions, and never mutate the input value.

  • validateDate: Ensures a value is a valid Date instance with a finite timestamp. Rejects invalid Date objects such as new Date("invalid").
  • validateEmail: Ensures a value is a syntactically valid email address according to common RFC‑compliant patterns, rejecting malformed or ambiguous inputs.
  • validateEnumValue: Ensures a value is one of the allowed values of a specific enum, including both string and numeric enums.
  • validateError: Ensures a value is an Error object, including native error types and custom error subclasses.
  • validateFunction: Ensures a value is a callable function with a specific parameter and return type, including arrow functions and class constructors.
  • validateHexString:
  • validateJSON: Ensures a value is a valid JSONValue, including primitives, arrays, and plain objects; rejects circular references and non-plain prototypes.
  • validateKeyOf: Ensures a value is a lowercase or uppercase hexadecimal string of even length, containing only characters 0–9 and A–F.
  • validatePhone: Ensures a value is a normalized E.164‑compatible phone number string, rejecting ambiguous or region‑dependent formats.
  • validatePort: Ensures a value is an integer between 0 and 65535 inclusive, representing a valid TCP/UDP port number.
  • validateRegExp: Ensures a value is a genuine RegExp instance, not a wrapper or custom object.
  • validateTimestamp: Ensures a value is a finite integer number representing a Unix timestamp in milliseconds.
  • validateURL: Ensures a value is a syntactically valid absolute URL, rejecting relative paths and malformed schemes.
  • validateUUID: Ensures a value is a valid RFC 4122 UUID string, supporting canonical v1–v5 formats.
  • validateValueOf: Ensures a value is one of the allowed values of a union type, rejecting anything outside the explicitly permitted set.

All semantic validators are pure, predictable, and crucial for enforcing data quality based on domain-specific conventions and industry standards.