Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WeakMapPredicate<KeyType>

Type parameters

  • KeyType: object = object

Hierarchy

  • Predicate<WeakMap<KeyType, unknown>>
    • WeakMapPredicate

Index

Accessors

not

  • get not(): this

Methods

addValidator

  • addValidator(validator: Validator<WeakMap<KeyType, unknown>>): WeakMapPredicate<KeyType>

hasAnyKeys

  • Test a WeakMap to include any of the provided keys. The keys are tested by identity, not structure.

    Parameters

    • Rest ...keys: readonly KeyType[]

      The keys that could be a key in the WeakMap.

    Returns WeakMapPredicate<KeyType>

hasKeys

  • Test a WeakMap to include all the provided keys. The keys are tested by identity, not structure.

    Parameters

    • Rest ...keys: readonly KeyType[]

      The keys that should be a key in the WeakMap.

    Returns WeakMapPredicate<KeyType>

is

  • is(validator: (value: WeakMap<KeyType, unknown>) => string | boolean): WeakMapPredicate<KeyType>
  • 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: WeakMap<KeyType, unknown>) => string | boolean

      Validation function.

        • (value: WeakMap<KeyType, unknown>): string | boolean
        • Parameters

          • value: WeakMap<KeyType, unknown>

          Returns string | boolean

    Returns WeakMapPredicate<KeyType>

message

  • message(newMessage: string | ValidatorMessageBuilder<WeakMap<KeyType, unknown>>): WeakMapPredicate<KeyType>
  • 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<WeakMap<KeyType, unknown>>

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

    Returns WeakMapPredicate<KeyType>

validate

  • validate(customValidator: CustomValidator<WeakMap<KeyType, unknown>>): WeakMapPredicate<KeyType>
  • 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<WeakMap<KeyType, unknown>>

      Custom validation function.

    Returns WeakMapPredicate<KeyType>