Constructors

Properties

name: string = 'numbers'

Descriptive name for this validation

Accessors

Methods

  • Specify the numbers to validate

    Parameters

    • numbers: number[]

    Returns this

  • Parameters

    • from: number
    • to: number
    • Optionalmsg: string

    Returns this

    NumberValidationError if numbers are not all between from and to

  • Parameters

    • from: number
    • to: number
    • Optionalmsg: string

    Returns this

    NumberValidationError if numbers are not all between or equal to from and to

  • Get the sum of our numbers

    Returns number

  • Validates whether the total of all of our numbers is close to sum, with a maximum difference of diff

    Parameters

    • sum: number

      The sum

    • diff: number = 0.0001

      The maximum difference

    • Optionalmsg: string

      Error message

    Returns this

    NumberValidationError If they do not sum close to the correct amount

  • Validates whether the total of all of our numbers is equal (===) to sum

    Parameters

    • sum: number

      The sum

    • Optionalmsg: string

      Error message

    Returns this

    NumberValidationError If they do not total to the correct amount

  • Validates whether the total of all of our numbers is > sum

    Parameters

    • sum: number

      The sum

    • Optionalmsg: string

      Error message

    Returns this

    NumberValidationError If they do not total to > sum

  • Validates whether the total of all of our numbers is >= sum

    Parameters

    • sum: number

      The sum

    • Optionalmsg: string

      Error message

    Returns this

    NumberValidationError If they do not total to >= sum

  • Validates whether the total of all of our numbers is < sum

    Parameters

    • sum: number

      The sum

    • Optionalmsg: string

      Error message

    Returns this

    NumberValidationError If they do not total to < sum

  • Validates whether the total of all of our numbers is <= sum

    Parameters

    • sum: number

      The sum

    • Optionalmsg: string

      Error message

    Returns this

    NumberValidationError If they do not total to <= sum

  • Pass a string decribing the varname to this to make the error messages make more sense in your context.

    Parameters

    • name: string

    Returns this

    const potatoes = [0, 1];
    validate(potatoes).varname('potatoes').gt(2); // "Expected every component of potatoes to be > 2, got 0"