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

Type parameters

  • T = unknown

Hierarchy

  • Predicate<T[]>
    • ArrayPredicate

Implements

  • BasePredicate<T[]>

Index

Accessors

empty

  • get empty(): this

nonEmpty

  • get nonEmpty(): this

not

  • get not(): this

Methods

Protected addValidator

  • addValidator(validator: Validator<T[]>): this
  • Register a new validator.

    Parameters

    • validator: Validator<T[]>

      Validator to register.

    Returns this

deepEqual

  • deepEqual(expected: readonly T[]): this
  • Test an array to be deeply equal to the provided array.

    Parameters

    • expected: readonly T[]

      Expected value to match.

    Returns this

endsWith

  • endsWith(searchElement: T): this
  • Test an array to end with a specific value. The value is tested by identity, not structure.

    Parameters

    • searchElement: T

      The value that should be the end of the array.

    Returns this

includes

  • includes(...searchElements: readonly T[]): this
  • Test an array to include all the provided elements. The values are tested by identity, not structure.

    Parameters

    • Rest ...searchElements: readonly T[]

      The values that should be included in the array.

    Returns this

includesAny

  • includesAny(...searchElements: readonly T[]): this
  • Test an array to include any of the provided elements. The values are tested by identity, not structure.

    Parameters

    • Rest ...searchElements: readonly T[]

      The values that should be included in the array.

    Returns this

is

  • is(validator: (value: T[]) => 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: T[]) => boolean | string

      Validation function.

        • (value: T[]): boolean | string
        • Parameters

          • value: T[]

          Returns boolean | string

    Returns this

length

  • length(length: number): this
  • Test an array to have a specific length.

    Parameters

    • length: number

      The length of the array.

    Returns this

maxLength

  • maxLength(length: number): this
  • Test an array to have a maximum length.

    Parameters

    • length: number

      The maximum length of the array.

    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<T[]>

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

    Returns this

minLength

  • minLength(length: number): this
  • Test an array to have a minimum length.

    Parameters

    • length: number

      The minimum length of the array.

    Returns this

ofType

  • ofType<P>(predicate: P): this
  • Test all elements in the array to match to provided predicate.

    example
    ow(['a', 1], ow.array.ofType(ow.any(ow.string, ow.number)));

    Type parameters

    • P: BasePredicate<T>

    Parameters

    • predicate: P

      The predicate that should be applied against every individual item.

    Returns this

startsWith

  • startsWith(searchElement: T): this
  • Test an array to start with a specific value. The value is tested by identity, not structure.

    Parameters

    • searchElement: T

      The value that should be the start of the array.

    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