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

Hierarchy

  • Predicate<string>
    • StringPredicate

Implements

  • BasePredicate<string>

Index

Accessors

alphabetical

  • get alphabetical(): this

alphanumeric

  • get alphanumeric(): this

date

  • get date(): this

empty

  • get empty(): this

lowercase

  • get lowercase(): this

nonEmpty

  • get nonEmpty(): this

not

  • get not(): this

numeric

  • get numeric(): this

uppercase

  • get uppercase(): this

url

  • get url(): this

Methods

Protected addValidator

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

    Parameters

    • validator: Validator<string>

      Validator to register.

    Returns this

endsWith

  • endsWith(searchString: string): this
  • Test a string to end with a specific value.

    Parameters

    • searchString: string

      The value that should be the end of the string.

    Returns this

equals

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

    Parameters

    • expected: string

      Expected value to match.

    Returns this

includes

  • includes(searchString: string): this
  • Test a string to include a specific value.

    Parameters

    • searchString: string

      The value that should be included in the string.

    Returns this

is

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

      Validation function.

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

          • value: string

          Returns boolean | string

    Returns this

length

  • length(length: number): this

matches

  • matches(regex: RegExp): this
  • Test a string against a regular expression.

    Parameters

    • regex: RegExp

      The regular expression to match the value with.

    Returns this

maxLength

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

    Parameters

    • length: number

      The maximum length of the string.

    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<string>

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

    Returns this

minLength

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

    Parameters

    • length: number

      The minimum length of the string.

    Returns this

oneOf

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

    Parameters

    • list: readonly string[]

      List of possible values.

    Returns this

startsWith

  • startsWith(searchString: string): this
  • Test a string to start with a specific value.

    Parameters

    • searchString: string

      The value that should be the start of the string.

    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