node-env
    Preparing search index...

    Variable validationConst

    validation: {
        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>(
            schema: S,
            options?: { unknown_keys?: "strip" | "allow" | "error" },
        ) => Validator<InferSchemaShape<S> & Record<string, unknown>>;
        optional: <T>(inner: Validator<T>) => Validator<T | undefined>;
        parse: <T>(validator: Validator<T>, value: unknown) => 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>;
        string: (
            options?: {
                max?: number;
                min?: number;
                non_empty?: boolean;
                pattern?: RegExp;
                trim?: boolean;
            },
        ) => Validator<string>;
        union: <A, B>(a: Validator<A>, b: Validator<B>) => Validator<A | B>;
    } = ...

    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>(
          schema: S,
          options?: { unknown_keys?: "strip" | "allow" | "error" },
      ) => Validator<InferSchemaShape<S> & Record<string, unknown>>

      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.

    • 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.

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

      Validates a string value.

    • union: <A, B>(a: Validator<A>, b: Validator<B>) => Validator<A | B>

      Validates a value against either of two validators.