ow
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Predicate<number>
    • NumberPredicate

Implements

  • BasePredicate<number>

Index

Accessors

finite

  • get finite(): this

infinite

  • get infinite(): this

int16

  • get int16(): this

int32

  • get int32(): this

int8

  • get int8(): this

integer

  • get integer(): this

integerOrInfinite

  • get integerOrInfinite(): this

negative

  • get negative(): this

not

  • get not(): this

positive

  • get positive(): this

uint16

  • get uint16(): this

uint32

  • get uint32(): this

uint8

  • get uint8(): this

Methods

Protected addValidator

  • addValidator(validator: Validator<number>): this
  • Register a new validator.

    Parameters

    • validator: Validator<number>

      Validator to register.

    Returns this

equal

  • equal(expected: number): this
  • Test a number to be equal to a specified number.

    Parameters

    • expected: number

      Expected value to match.

    Returns this

greaterThan

  • greaterThan(number: number): this
  • Test a number to be greater than the provided value.

    Parameters

    • number: number

      Minimum value.

    Returns this

greaterThanOrEqual

  • greaterThanOrEqual(number: number): this
  • Test a number to be greater than or equal to the provided value.

    Parameters

    • number: number

      Minimum value.

    Returns this

inRange

  • inRange(start: number, end: number): this
  • Test a number to be in a specified range.

    Parameters

    • start: number

      Start of the range.

    • end: number

      End of the range.

    Returns this

is

  • is(validator: (value: number) => boolean | string): this
  • Test if the value matches a custom validation function. The validation function should return true if the value passes the function. If the function either returns false or a string, the function fails and the string will be used as error message.

    Parameters

    • validator: (value: number) => boolean | string

      Validation function.

        • (value: number): boolean | string
        • Parameters

          • value: number

          Returns boolean | string

    Returns this

lessThan

  • lessThan(number: number): this

lessThanOrEqual

  • lessThanOrEqual(number: number): this
  • Test a number to be less than or equal to the provided value.

    Parameters

    • number: number

      Minimum value.

    Returns this

message

  • Provide a new error message to be thrown when the validation fails.

    example
    ow('🌈', 'unicorn', ow.string.equals('🦄').message('Expected unicorn, got rainbow'));
    //=> ArgumentError: Expected unicorn, got rainbow
    example
    ow('🌈', ow.string.minLength(5).message((value, label) => `Expected ${label}, to have a minimum length of 5, got \`${value}\``));
    //=> ArgumentError: Expected string, to be have a minimum length of 5, got `🌈`

    Parameters

    • newMessage: string | ValidatorMessageBuilder<number>

      Either a string containing the new message or a function returning the new message.

    Returns this

oneOf

  • oneOf(list: readonly number[]): this
  • Test if a number is an element of the provided list.

    Parameters

    • list: readonly number[]

      List of possible values.

    Returns this

validate

  • Test if the value matches a custom validation function. The validation function should return an object containing a validator and message. If the validator is false, the validation fails and the message will be used as error message. If the message is a function, the function is invoked with the label as argument to let you further customize the error message.

    Parameters

    Returns this