Interface for validating date values.

example

const dateSchema = val.DateSchema(); dateSchema.validate(new Date()); // Validates a date object.

throws

ValidationError If the input is not a valid date.

example

// Example error message: // "Date Failed Validation for: ✖ Expected a valid date, but received a string."

Hierarchy

Index

Properties

isOptional

isOptional: boolean

Indicates whether the schema allows undefined as a valid value.

example

const schema = val.string().optional(); console.log(schema.isOptional); // true

type

type: string

The type of data that the schema validates, represented as a string.

example

const schema = val.string(); console.log(schema.type); // "string"

Methods

coerce

  • coerce(): this
  • Coerces the input into a valid date object.

    example

    const dateSchema = val.DateSchema().coerce(); dateSchema.validate("2025-04-30"); // Coerces the string into a Date object.

    throws

    ValidationError If coercion fails or the input cannot be converted to a valid date.

    example

    // Example error message: // "Date Failed Validation for: ✖ Expected a valid date, but received an invalid string."

    Returns this

    The current schema instance.

optional

  • optional(): this
  • Marks the schema as optional, allowing undefined as a valid value.

    example

    const dateSchema = val.DateSchema().optional(); dateSchema.validate(undefined); // Passes validation

    Returns this

    The current schema instance.

parse

  • parse(data: unknown): Date
  • Parses the input data and returns the parsed value.

    This method is typically used to coerce or transform the input data into the desired format.

    throws

    ValidationError If the input data cannot be parsed into the desired format.

    example

    const schema = val.number().coerce(); const parsedValue = schema.parse("42"); // Returns 42 as a number

    Parameters

    • data: unknown

      The input data to parse.

    Returns Date

    The parsed value.

validate

  • validate(data: unknown): Date
  • Validates the input data against the date schema.

    throws

    ValidationError If the input is not a valid date.

    example

    const dateSchema = val.DateSchema(); dateSchema.validate("not-a-date"); // Throws ValidationError // Example error message: // "Date Failed Validation for: ✖ Expected a valid date, but received a string."

    Parameters

    • data: unknown

      The data to validate.

    Returns Date

    The validated date object.

Generated using TypeDoc