Function default

  • Test if the value matches the predicate. Throws an ArgumentError if the test fails.

    Type Parameters

    • T

    Parameters

    • value: unknown

      Value to test.

    • predicate: BasePredicate<T>

      Predicate to test against.

    Returns asserts value is T

  • Test if value matches the provided predicate. Throws an ArgumentError with the specified label if the test fails.

    Type Parameters

    • T

    Parameters

    • value: unknown

      Value to test.

    • label: string

      Label which should be used in error messages.

    • predicate: BasePredicate<T>

      Predicate to test against.

    Returns asserts value is T

Properties

any: (<T1>(p1) => AnyPredicate<T1>) & (<T1, T2>(p1, p2) => AnyPredicate<T1 | T2>) & (<T1, T2, T3>(p1, p2, p3) => AnyPredicate<T1 | T2 | T3>) & (<T1, T2, T3, T4>(p1, p2, p3, p4) => AnyPredicate<T1 | T2 | T3 | T4>) & (<T1, T2, T3, T4, T5>(p1, p2, p3, p4, p5) => AnyPredicate<T1 | T2 | T3 | T4 | T5>) & (<T1, T2, T3, T4, T5, T6>(p1, p2, p3, p4, p5, p6) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>) & (<T1, T2, T3, T4, T5, T6, T7>(p1, p2, p3, p4, p5, p6, p7) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>) & (<T1, T2, T3, T4, T5, T6, T7, T8>(p1, p2, p3, p4, p5, p6, p7, p8) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>) & (<T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1, p2, p3, p4, p5, p6, p7, p8, p9) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>) & (<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>) & ((...predicate) => AnyPredicate<unknown>)

Test that the value matches at least one of the given predicates.

Type declaration

    • <T1>(p1): AnyPredicate<T1>
    • Type Parameters

      • T1

      Parameters

      • p1: BasePredicate<T1>

      Returns AnyPredicate<T1>

Type declaration

    • <T1, T2>(p1, p2): AnyPredicate<T1 | T2>
    • Type Parameters

      • T1
      • T2

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>

      Returns AnyPredicate<T1 | T2>

Type declaration

    • <T1, T2, T3>(p1, p2, p3): AnyPredicate<T1 | T2 | T3>
    • Type Parameters

      • T1
      • T2
      • T3

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>

      Returns AnyPredicate<T1 | T2 | T3>

Type declaration

    • <T1, T2, T3, T4>(p1, p2, p3, p4): AnyPredicate<T1 | T2 | T3 | T4>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>

      Returns AnyPredicate<T1 | T2 | T3 | T4>

Type declaration

    • <T1, T2, T3, T4, T5>(p1, p2, p3, p4, p5): AnyPredicate<T1 | T2 | T3 | T4 | T5>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>
      • p5: BasePredicate<T5>

      Returns AnyPredicate<T1 | T2 | T3 | T4 | T5>

Type declaration

    • <T1, T2, T3, T4, T5, T6>(p1, p2, p3, p4, p5, p6): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5
      • T6

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>
      • p5: BasePredicate<T5>
      • p6: BasePredicate<T6>

      Returns AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>

Type declaration

    • <T1, T2, T3, T4, T5, T6, T7>(p1, p2, p3, p4, p5, p6, p7): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5
      • T6
      • T7

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>
      • p5: BasePredicate<T5>
      • p6: BasePredicate<T6>
      • p7: BasePredicate<T7>

      Returns AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>

Type declaration

    • <T1, T2, T3, T4, T5, T6, T7, T8>(p1, p2, p3, p4, p5, p6, p7, p8): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5
      • T6
      • T7
      • T8

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>
      • p5: BasePredicate<T5>
      • p6: BasePredicate<T6>
      • p7: BasePredicate<T7>
      • p8: BasePredicate<T8>

      Returns AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>

Type declaration

    • <T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1, p2, p3, p4, p5, p6, p7, p8, p9): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5
      • T6
      • T7
      • T8
      • T9

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>
      • p5: BasePredicate<T5>
      • p6: BasePredicate<T6>
      • p7: BasePredicate<T7>
      • p8: BasePredicate<T8>
      • p9: BasePredicate<T9>

      Returns AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>

Type declaration

    • <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>
    • Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5
      • T6
      • T7
      • T8
      • T9
      • T10

      Parameters

      • p1: BasePredicate<T1>
      • p2: BasePredicate<T2>
      • p3: BasePredicate<T3>
      • p4: BasePredicate<T4>
      • p5: BasePredicate<T5>
      • p6: BasePredicate<T6>
      • p7: BasePredicate<T7>
      • p8: BasePredicate<T8>
      • p9: BasePredicate<T9>
      • p10: BasePredicate<T10>

      Returns AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>

Type declaration

    • (...predicate): AnyPredicate<unknown>
    • Parameters

      • Rest ...predicate: BasePredicate[]

      Returns AnyPredicate<unknown>

array: ArrayPredicate<unknown>

Test the value to be an array.

arrayBuffer: ArrayBufferPredicate<ArrayBuffer>

Test the value to be a ArrayBuffer.

Test the value to be an bigint.

Test the value to be a boolean.

buffer: Predicate<Buffer>

Test the value to be a Buffer.

create: (<T>(predicate) => ReusableValidator<T>) & (<T>(label, predicate) => ReusableValidator<T>)

Create a reusable validator.

Type declaration

Type declaration

Param: predicate

Predicate used in the validator function.

Test the value to be a DataView.

Test the value to be a Date.

Test the value to be an Error.

float32Array: TypedArrayPredicate<Float32Array>

Test the value to be a Float32Array.

float64Array: TypedArrayPredicate<Float64Array>

Test the value to be a Float64Array.

function: Predicate<Function>

Test the value to be a Function.

int16Array: TypedArrayPredicate<Int16Array>

Test the value to be a Int16Array.

int32Array: TypedArrayPredicate<Int32Array>

Test the value to be a Int32Array.

int8Array: TypedArrayPredicate<Int8Array>

Test the value to be a Int8Array.

isValid: (<T>(value, predicate) => value is T)

Returns true if the value matches the predicate, otherwise returns false.

Type declaration

    • <T>(value, predicate): value is T
    • Type Parameters

      • T

      Parameters

      • value: unknown

        Value to test.

      • predicate: BasePredicate<T>

        Predicate to test against.

      Returns value is T

iterable: Predicate<Iterable<unknown>>

Test the value to be Iterable.

map: MapPredicate<unknown, unknown>

Test the value to be a Map.

nan: Predicate<number>

Test the value to be not a number.

null: Predicate<null>

Test the value to be null.

nullOrUndefined: Predicate<undefined | null>

Test the value to be null or undefined.

Test the value to be a number.

object: ObjectPredicate<object>

Test the value to be an object.

optional: {
    any: (<T1>(p1) => AnyPredicate<T1>) & (<T1, T2>(p1, p2) => AnyPredicate<T1 | T2>) & (<T1, T2, T3>(p1, p2, p3) => AnyPredicate<T1 | T2 | T3>) & (<T1, T2, T3, T4>(p1, p2, p3, p4) => AnyPredicate<T1 | T2 | T3 | T4>) & (<T1, T2, T3, T4, T5>(p1, p2, p3, p4, p5) => AnyPredicate<T1 | T2 | T3 | T4 | T5>) & (<T1, T2, T3, T4, T5, T6>(p1, p2, p3, p4, p5, p6) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>) & (<T1, T2, T3, T4, T5, T6, T7>(p1, p2, p3, p4, p5, p6, p7) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>) & (<T1, T2, T3, T4, T5, T6, T7, T8>(p1, p2, p3, p4, p5, p6, p7, p8) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>) & (<T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1, p2, p3, p4, p5, p6, p7, p8, p9) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>) & (<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>) & ((...predicate) => AnyPredicate<unknown>);
    array: ArrayPredicate<unknown> & BasePredicate<undefined | unknown[]>;
    arrayBuffer: ArrayBufferPredicate<ArrayBuffer> & BasePredicate<undefined | ArrayBuffer>;
    bigint: BigIntPredicate & BasePredicate<undefined | bigint>;
    boolean: BooleanPredicate & BasePredicate<undefined | boolean>;
    buffer: Predicate<Buffer> & BasePredicate<undefined | Buffer>;
    dataView: DataViewPredicate & BasePredicate<undefined | DataView>;
    date: DatePredicate & BasePredicate<undefined | Date>;
    error: ErrorPredicate & BasePredicate<undefined | Error>;
    float32Array: TypedArrayPredicate<Float32Array> & BasePredicate<undefined | Float32Array>;
    float64Array: TypedArrayPredicate<Float64Array> & BasePredicate<undefined | Float64Array>;
    function: Predicate<Function> & BasePredicate<undefined | Function>;
    int16Array: TypedArrayPredicate<Int16Array> & BasePredicate<undefined | Int16Array>;
    int32Array: TypedArrayPredicate<Int32Array> & BasePredicate<undefined | Int32Array>;
    int8Array: TypedArrayPredicate<Int8Array> & BasePredicate<undefined | Int8Array>;
    iterable: Predicate<Iterable<unknown>> & BasePredicate<undefined | Iterable<unknown>>;
    map: MapPredicate<unknown, unknown> & BasePredicate<undefined | Map<unknown, unknown>>;
    nan: Predicate<number> & BasePredicate<undefined | number>;
    null: Predicate<null> & BasePredicate<undefined | null>;
    nullOrUndefined: Predicate<undefined | null> & BasePredicate<undefined | null>;
    number: NumberPredicate & BasePredicate<undefined | number>;
    object: ObjectPredicate<object> & BasePredicate<undefined | object>;
    promise: Predicate<Promise<unknown>> & BasePredicate<undefined | Promise<unknown>>;
    regExp: Predicate<RegExp> & BasePredicate<undefined | RegExp>;
    set: SetPredicate<any> & BasePredicate<undefined | Set<any>>;
    sharedArrayBuffer: ArrayBufferPredicate<SharedArrayBuffer> & BasePredicate<undefined | SharedArrayBuffer>;
    string: StringPredicate & BasePredicate<undefined | string>;
    symbol: Predicate<symbol> & BasePredicate<undefined | symbol>;
    typedArray: TypedArrayPredicate<TypedArray> & BasePredicate<undefined | TypedArray>;
    uint16Array: TypedArrayPredicate<Uint16Array> & BasePredicate<undefined | Uint16Array>;
    uint32Array: TypedArrayPredicate<Uint32Array> & BasePredicate<undefined | Uint32Array>;
    uint8Array: TypedArrayPredicate<Uint8Array> & BasePredicate<undefined | Uint8Array>;
    uint8ClampedArray: TypedArrayPredicate<Uint8ClampedArray> & BasePredicate<undefined | Uint8ClampedArray>;
    undefined: Predicate<undefined> & BasePredicate<undefined>;
    weakMap: WeakMapPredicate<object> & BasePredicate<undefined | WeakMap<object, unknown>>;
    weakSet: WeakSetPredicate<object> & BasePredicate<undefined | WeakSet<object>>;
}

Make the following predicate optional so it doesn't fail when the value is undefined.

Type declaration

  • any: (<T1>(p1) => AnyPredicate<T1>) & (<T1, T2>(p1, p2) => AnyPredicate<T1 | T2>) & (<T1, T2, T3>(p1, p2, p3) => AnyPredicate<T1 | T2 | T3>) & (<T1, T2, T3, T4>(p1, p2, p3, p4) => AnyPredicate<T1 | T2 | T3 | T4>) & (<T1, T2, T3, T4, T5>(p1, p2, p3, p4, p5) => AnyPredicate<T1 | T2 | T3 | T4 | T5>) & (<T1, T2, T3, T4, T5, T6>(p1, p2, p3, p4, p5, p6) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>) & (<T1, T2, T3, T4, T5, T6, T7>(p1, p2, p3, p4, p5, p6, p7) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>) & (<T1, T2, T3, T4, T5, T6, T7, T8>(p1, p2, p3, p4, p5, p6, p7, p8) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>) & (<T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1, p2, p3, p4, p5, p6, p7, p8, p9) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>) & (<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>) & ((...predicate) => AnyPredicate<unknown>)

    Test that the value matches at least one of the given predicates.

  • Readonly array: ArrayPredicate<unknown> & BasePredicate<undefined | unknown[]>

    Test the value to be an array.

  • Readonly arrayBuffer: ArrayBufferPredicate<ArrayBuffer> & BasePredicate<undefined | ArrayBuffer>

    Test the value to be a ArrayBuffer.

  • Readonly bigint: BigIntPredicate & BasePredicate<undefined | bigint>

    Test the value to be an bigint.

  • Readonly boolean: BooleanPredicate & BasePredicate<undefined | boolean>

    Test the value to be a boolean.

  • Readonly buffer: Predicate<Buffer> & BasePredicate<undefined | Buffer>

    Test the value to be a Buffer.

  • Readonly dataView: DataViewPredicate & BasePredicate<undefined | DataView>

    Test the value to be a DataView.

  • Readonly date: DatePredicate & BasePredicate<undefined | Date>

    Test the value to be a Date.

  • Readonly error: ErrorPredicate & BasePredicate<undefined | Error>

    Test the value to be an Error.

  • Readonly float32Array: TypedArrayPredicate<Float32Array> & BasePredicate<undefined | Float32Array>

    Test the value to be a Float32Array.

  • Readonly float64Array: TypedArrayPredicate<Float64Array> & BasePredicate<undefined | Float64Array>

    Test the value to be a Float64Array.

  • Readonly function: Predicate<Function> & BasePredicate<undefined | Function>

    Test the value to be a Function.

  • Readonly int16Array: TypedArrayPredicate<Int16Array> & BasePredicate<undefined | Int16Array>

    Test the value to be a Int16Array.

  • Readonly int32Array: TypedArrayPredicate<Int32Array> & BasePredicate<undefined | Int32Array>

    Test the value to be a Int32Array.

  • Readonly int8Array: TypedArrayPredicate<Int8Array> & BasePredicate<undefined | Int8Array>

    Test the value to be a Int8Array.

  • Readonly iterable: Predicate<Iterable<unknown>> & BasePredicate<undefined | Iterable<unknown>>

    Test the value to be Iterable.

  • Readonly map: MapPredicate<unknown, unknown> & BasePredicate<undefined | Map<unknown, unknown>>

    Test the value to be a Map.

  • Readonly nan: Predicate<number> & BasePredicate<undefined | number>

    Test the value to be not a number.

  • Readonly null: Predicate<null> & BasePredicate<undefined | null>

    Test the value to be null.

  • Readonly nullOrUndefined: Predicate<undefined | null> & BasePredicate<undefined | null>

    Test the value to be null or undefined.

  • Readonly number: NumberPredicate & BasePredicate<undefined | number>

    Test the value to be a number.

  • Readonly object: ObjectPredicate<object> & BasePredicate<undefined | object>

    Test the value to be an object.

  • Readonly promise: Predicate<Promise<unknown>> & BasePredicate<undefined | Promise<unknown>>

    Test the value to be a Promise.

  • Readonly regExp: Predicate<RegExp> & BasePredicate<undefined | RegExp>

    Test the value to be a RegExp.

  • Readonly set: SetPredicate<any> & BasePredicate<undefined | Set<any>>

    Test the value to be a Set.

  • Readonly sharedArrayBuffer: ArrayBufferPredicate<SharedArrayBuffer> & BasePredicate<undefined | SharedArrayBuffer>

    Test the value to be a SharedArrayBuffer.

  • Readonly string: StringPredicate & BasePredicate<undefined | string>

    Test the value to be a string.

  • Readonly symbol: Predicate<symbol> & BasePredicate<undefined | symbol>

    Test the value to be a Symbol.

  • Readonly typedArray: TypedArrayPredicate<TypedArray> & BasePredicate<undefined | TypedArray>

    Test the value to be a typed array.

  • Readonly uint16Array: TypedArrayPredicate<Uint16Array> & BasePredicate<undefined | Uint16Array>

    Test the value to be a Uint16Array.

  • Readonly uint32Array: TypedArrayPredicate<Uint32Array> & BasePredicate<undefined | Uint32Array>

    Test the value to be a Uint32Array.

  • Readonly uint8Array: TypedArrayPredicate<Uint8Array> & BasePredicate<undefined | Uint8Array>

    Test the value to be a Uint8Array.

  • Readonly uint8ClampedArray: TypedArrayPredicate<Uint8ClampedArray> & BasePredicate<undefined | Uint8ClampedArray>

    Test the value to be a Uint8ClampedArray.

  • Readonly undefined: Predicate<undefined> & BasePredicate<undefined>

    Test the value to be undefined.

  • Readonly weakMap: WeakMapPredicate<object> & BasePredicate<undefined | WeakMap<object, unknown>>

    Test the value to be a WeakMap.

  • Readonly weakSet: WeakSetPredicate<object> & BasePredicate<undefined | WeakSet<object>>

    Test the value to be a WeakSet.

promise: Predicate<Promise<unknown>>

Test the value to be a Promise.

regExp: Predicate<RegExp>

Test the value to be a RegExp.

set: SetPredicate<any>

Test the value to be a Set.

sharedArrayBuffer: ArrayBufferPredicate<SharedArrayBuffer>

Test the value to be a SharedArrayBuffer.

Test the value to be a string.

symbol: Predicate<symbol>

Test the value to be a Symbol.

typedArray: TypedArrayPredicate<TypedArray>

Test the value to be a typed array.

uint16Array: TypedArrayPredicate<Uint16Array>

Test the value to be a Uint16Array.

uint32Array: TypedArrayPredicate<Uint32Array>

Test the value to be a Uint32Array.

uint8Array: TypedArrayPredicate<Uint8Array>

Test the value to be a Uint8Array.

uint8ClampedArray: TypedArrayPredicate<Uint8ClampedArray>

Test the value to be a Uint8ClampedArray.

undefined: Predicate<undefined>

Test the value to be undefined.

weakMap: WeakMapPredicate<object>

Test the value to be a WeakMap.

weakSet: WeakSetPredicate<object>

Test the value to be a WeakSet.