Interface for validating boolean values.

example

const booleanSchema = val.BooleanSchema(); booleanSchema.validate(true); // Validates a boolean value.

throws

ValidationError If the input is not a valid boolean.

example

// Example error message: // "Boolean Failed Validation for: ✖ Expected a boolean value, 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 boolean value.

    example

    const booleanSchema = val.BooleanSchema().coerce(); booleanSchema.validate("true"); // Coerces the string "true" into a boolean.

    throws

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

    example

    // Example error message: // "Boolean Failed Validation for: ✖ Expected a boolean value, but received an invalid coercible value."

    Returns this

    The current schema instance.

optional

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

    example

    const booleanSchema = val.BooleanSchema().optional(); booleanSchema.validate(undefined); // Passes validation

    Returns this

    The current schema instance.

parse

  • parse(data: unknown): boolean
  • 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 boolean

    The parsed value.

validate

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

    throws

    ValidationError If the input is not a valid boolean.

    example

    const booleanSchema = val.BooleanSchema(); booleanSchema.validate("not-a-boolean"); // Throws ValidationError // Example error message: // "Boolean Failed Validation for: ✖ Expected a boolean value, but received a string."

    Parameters

    • data: unknown

      The data to validate.

    Returns boolean

    The validated boolean value.

Generated using TypeDoc