node-validator
    Preparing search index...

    Variable Validator

    Validator: {
        array: <T>(
            inner: Validator<T>,
            options?: { max?: number; min?: number },
        ) => Validator<T[]>;
        boolean: () => Validator<boolean>;
        enum: <const T extends readonly string[]>(
            values: T,
        ) => Validator<T[number]>;
        literal: <T extends string | number | boolean | null>(
            expected: T,
        ) => Validator<T>;
        nullable: <T>(inner: Validator<T>) => Validator<T | null>;
        number: (
            options?: {
                finite?: boolean;
                integer?: boolean;
                max?: number;
                min?: number;
            },
        ) => Validator<number>;
        object: <S extends SchemaShape, U extends UnknownKeyBehavior = "strip">(
            schema: S,
            options?: ObjectOptions<U>,
        ) => Validator<InferObjectShape<S, U>>;
        optional: <T>(inner: Validator<T>) => Validator<T | undefined>;
        parse: <T>(validator: Validator<T>, value: unknown) => T;
        parseFormData: <T>(validator: Validator<T>, value: FormData) => T;
        record: <T>(
            valueValidator: Validator<T>,
            options?: { key?: Validator<string> },
        ) => Validator<Record<string, T>>;
        refine: <T>(
            base: Validator<T>,
            predicate: (value: T) => boolean,
            message: string,
            code?: string,
        ) => Validator<T>;
        safeParse: <T>(
            validator: Validator<T>,
            value: unknown,
        ) => ValidationResult<T>;
        safeParseFormData: <T>(
            validator: Validator<T>,
            value: FormData,
        ) => ValidationResult<T>;
        string: (
            options?: {
                max?: number;
                min?: number;
                non_empty?: boolean;
                pattern?: RegExp;
                trim?: boolean;
            },
        ) => Validator<string>;
        transform: <T, U>(
            base: Validator<T>,
            mapper: (value: T) => U,
            message?: string,
            code?: string,
        ) => Validator<U>;
        tuple: <const T extends readonly [Validator<any>, Validator<any>]>(
            shape: T,
        ) => Validator<InferTupleShape<T>>;
        union: <
            const T extends
                readonly [Validator<any>, Validator<any>, Validator<any>],
        >(
            ...validators: T,
        ) => Validator<InferValidator<T[number]>>;
        withDefault: <T>(inner: Validator<T>, fallback: T) => Validator<T>;
    }

    Generic validation primitives that work on plain runtime values.

    Type Declaration

    • array: <T>(
          inner: Validator<T>,
          options?: { max?: number; min?: number },
      ) => Validator<T[]>

      Validates an array and each of its items.

    • boolean: () => Validator<boolean>

      Validates a boolean value.

    • enum: <const T extends readonly string[]>(values: T) => Validator<T[number]>

      Validates one of the provided string literal values.

    • literal: <T extends string | number | boolean | null>(expected: T) => Validator<T>

      Validates a literal value.

    • nullable: <T>(inner: Validator<T>) => Validator<T | null>

      Makes another validator nullable.

    • number: (
          options?: {
              finite?: boolean;
              integer?: boolean;
              max?: number;
              min?: number;
          },
      ) => Validator<number>

      Validates a number value.

    • object: <S extends SchemaShape, U extends UnknownKeyBehavior = "strip">(
          schema: S,
          options?: ObjectOptions<U>,
      ) => Validator<InferObjectShape<S, U>>

      Validates an object against a schema shape.

    • optional: <T>(inner: Validator<T>) => Validator<T | undefined>

      Makes another validator optional.

    • parse: <T>(validator: Validator<T>, value: unknown) => T

      Runs a validator and throws SchemaValidationError on failure.

    • parseFormData: <T>(validator: Validator<T>, value: FormData) => T

      Runs a validator against a FormData payload and throws on failure. Repeated keys are exposed as arrays in insertion order.

    • record: <T>(
          valueValidator: Validator<T>,
          options?: { key?: Validator<string> },
      ) => Validator<Record<string, T>>

      Validates a plain object record.

    • refine: <T>(
          base: Validator<T>,
          predicate: (value: T) => boolean,
          message: string,
          code?: string,
      ) => Validator<T>

      Adds a custom predicate to an existing validator.

    • safeParse: <T>(validator: Validator<T>, value: unknown) => ValidationResult<T>

      Runs a validator and returns a result object instead of throwing.

    • safeParseFormData: <T>(validator: Validator<T>, value: FormData) => ValidationResult<T>

      Runs a validator against a FormData payload and returns a result object. Repeated keys are exposed as arrays in insertion order.

    • string: (
          options?: {
              max?: number;
              min?: number;
              non_empty?: boolean;
              pattern?: RegExp;
              trim?: boolean;
          },
      ) => Validator<string>

      Validates a string value.

    • transform: <T, U>(
          base: Validator<T>,
          mapper: (value: T) => U,
          message?: string,
          code?: string,
      ) => Validator<U>

      Maps a validated value into a new output type.

    • tuple: <const T extends readonly [Validator<any>, Validator<any>]>(
          shape: T,
      ) => Validator<InferTupleShape<T>>

      Validates a tuple with a fixed number of items and validators.

    • union: <const T extends readonly [Validator<any>, Validator<any>, Validator<any>]>(
          ...validators: T,
      ) => Validator<InferValidator<T[number]>>

      Validates a value against either of two validators.

    • withDefault: <T>(inner: Validator<T>, fallback: T) => Validator<T>

      Applies a fallback value when the input is undefined.