Type Alias NumberValidator

NumberValidator: Validator<number, string[]> & {
    eq: (n: number) => NumberValidator;
    finite: () => NumberValidator;
    gt: (n: number) => NumberValidator;
    gte: (n: number) => NumberValidator;
    int: () => NumberValidator;
    lt: (n: number) => NumberValidator;
    lte: (n: number) => NumberValidator;
}

A validator that can validate a number value.

Type declaration

  • eq: (n: number) => NumberValidator

    Checks if the value is equal to the given value.

    const validator = avery.number().eq(10);
    console.log(validator.validate(10).isOk()); // Output: true
    console.log(validator.validate(5).isOk()); // Output: false
  • finite: () => NumberValidator

    Checks if the value is finite.

    const validator = avery.number().finite();
    console.log(validator.validate(10).isOk()); // Output: true
    console.log(validator.validate(Infinity).isOk()); // Output: false
  • gt: (n: number) => NumberValidator

    Checks if the value is greater than n.

    const validator = avery.number().gt(10);
    console.log(validator.validate(15).isOk()); // Output: true
    console.log(validator.validate(10).isOk()); // Output: false
  • gte: (n: number) => NumberValidator

    Checks if the value is greater than or equal to n.

    const validator = avery.number().gte(10);
    console.log(validator.validate(10).isOk()); // Output: true
    console.log(validator.validate(5).isOk()); // Output: false
  • int: () => NumberValidator

    Checks if the value is an integer.

    const validator = avery.number().int();
    console.log(validator.validate(10).isOk()); // Output: true
    console.log(validator.validate(10.5).isOk()); // Output: false
  • lt: (n: number) => NumberValidator

    Checks if the value is less than n.

    const validator = avery.number().lt(10);
    console.log(validator.validate(5).isOk()); // Output: true
    console.log(validator.validate(10).isOk()); // Output: false
  • lte: (n: number) => NumberValidator

    Checks if the value is less than or equal to n.

    const validator = avery.number().lte(10);
    console.log(validator.validate(10).isOk()); // Output: true
    console.log(validator.validate(15).isOk()); // Output: false
const validator = avery.number();
const result = validator.validate(42);
console.log(result.isOk()); // Output: true