Interface Validator<T, E>

A validator that can validate a given data.

interface Validator<T, E> {
    nullable: () => Validator<null | T, E>;
    validate: (data: any) => Result<T, E>;
}

Type Parameters

  • T
  • E

Properties

Properties

nullable: () => Validator<null | T, E>

Returns a new validator that can handle nullable data.

Type declaration

const validator = avery.string().nullable();
const result = validator.validate(null);
console.log(result.isOk()); // Output: true
validate: (data: any) => Result<T, E>

Validates the given data.

Type declaration

    • (data: any): Result<T, E>
    • Parameters

      • data: any

        The data to validate.

      Returns Result<T, E>

      The validation result.

const validator = avery.string();
const result = validator.validate('hello');
console.log(result.isOk()); // Output: true