Class ArrayBufferPredicate<T>

Type Parameters

  • T extends ArrayBufferLike

Hierarchy

  • Predicate<T>
    • ArrayBufferPredicate

Constructors

Accessors

Methods

  • Register a new validator.

    Parameters

    • validator: Validator<T>

      Validator to register.

    Returns this

  • Test an array buffer to have a specific byte length.

    Parameters

    • byteLength: number

      The byte length of the array buffer.

    Returns 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) => string | boolean)

      Validation function.

        • (value): string | boolean
        • Parameters

          • value: T

          Returns string | boolean

    Returns this

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

    Parameters

    • newMessage: string | ValidatorMessageBuilder<T>

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

    Returns this

    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 `🌈`
  • Test an array buffer to have a minimum byte length.

    Parameters

    • byteLength: number

      The minimum byte length of the array buffer.

    Returns this

  • 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

    • customValidator: CustomValidator<T>

      Custom validation function.

    Returns this