Options
All
  • Public
  • Public/Protected
  • All
Menu

@jguyon/check

Index

Type aliases

Check

Check<I, O, A>: (value: I, ...args: A) => Result<O>

A check function.

Type parameters

  • I

    The type of input values.

  • O

    The type of valid output values.

  • A: unknown[]

    The type of additional arguments to the function.

Type declaration

    • (value: I, ...args: A): Result<O>
    • Parameters

      • value: I
      • Rest ...args: A

      Returns Result<O>

Result

Result<T>: OkResult<T> | ErrorResult

A validation result.

Type parameters

  • T

    The type of valid values.

Functions

NotANumber

  • NotANumber(error?: string): Check<unknown, number, unknown[]>
  • Creates a check function that fails when the given value coerced to a number is not NaN.

    const check = NaN();
    
    check(NaN);
    // => { isOk: true, ... }
    check(new Date("invalid date"));
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }
    check(new Date());
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not NaN"

      The error to given when the value is not NaN.

    Returns Check<unknown, number, unknown[]>

    A check function.

array

  • array(error?: string): Check<unknown, unknown[]>
  • Creates a check function that fails when the given value is not an array.

    const check = array();
    
    check([]);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: true, ... }

    Parameters

    • Default value error: string = "is not an array"

      The error to give when the value is not an array.

    Returns Check<unknown, unknown[]>

    A check function.

boolean

  • boolean(error?: string): Check<unknown, boolean>
  • Creates a check function that fails when the given value is not a boolean.

    const check = boolean();
    
    check(false);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not a boolean"

      The error to give when the value is not a boolean.

    Returns Check<unknown, boolean>

    A check function.

ceil

  • Creates a check function that rounds a number up to the next integer.

    const check = ceil();
    
    check(3.14);
    // => {
    //   isOk: true,
    //   value: 4,
    // }
    
    check(-3.14);
    // => {
    //   isOk: true,
    //   value: -3,
    // }

    Returns Check<number>

    A check function.

chain

  • chain<V1, A>(): Check<V1, V1, A>
  • chain<V1, V2, A>(...checks: [Check<V1, V2, A>]): Check<V1, V2, A>
  • chain<V1, V2, V3, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>]): Check<V1, V3, A>
  • chain<V1, V2, V3, V4, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>]): Check<V1, V4, A>
  • chain<V1, V2, V3, V4, V5, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>]): Check<V1, V5, A>
  • chain<V1, V2, V3, V4, V5, V6, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>]): Check<V1, V6, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>]): Check<V1, V7, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, V8, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>]): Check<V1, V8, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, V8, V9, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>, Check<V8, V9, A>]): Check<V1, V9, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>, Check<V8, V9, A>, Check<V9, V10, A>]): Check<V1, V10, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>, Check<V8, V9, A>, Check<V9, V10, A>, Check<V10, V11, A>]): Check<V1, V11, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>, Check<V8, V9, A>, Check<V9, V10, A>, Check<V10, V11, A>, Check<V11, V12, A>]): Check<V1, V12, A>
  • chain<V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, A>(...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>, Check<V8, V9, A>, Check<V9, V10, A>, Check<V10, V11, A>, Check<V11, V12, A>, Check<V12, V13, A>]): Check<V1, V13, A>
  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • A: unknown[]

    Returns Check<V1, V1, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>]

      The check functions to chain together.

    Returns Check<V1, V2, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>]

      The check functions to chain together.

    Returns Check<V1, V3, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>]

      The check functions to chain together.

    Returns Check<V1, V4, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>]

      The check functions to chain together.

    Returns Check<V1, V5, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>]

      The check functions to chain together.

    Returns Check<V1, V6, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>]

      The check functions to chain together.

    Returns Check<V1, V7, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>]

      The check functions to chain together.

    Returns Check<V1, V8, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<V1, V2, A>, Check<V2, V3, A>, Check<V3, V4, A>, Check<V4, V5, A>, Check<V5, V6, A>, Check<V6, V7, A>, Check<V7, V8, A>, Check<V8, V9, A>]

      The check functions to chain together.

    Returns Check<V1, V9, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    • V10

    • A: unknown[]

    Parameters

    Returns Check<V1, V10, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    • V10

    • V11

    • A: unknown[]

    Parameters

    Returns Check<V1, V11, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    • V10

    • V11

    • V12

    • A: unknown[]

    Parameters

    Returns Check<V1, V12, A>

    A check function.

  • Creates a check function that chains a set of child check functions.

    The chain stops at the first failure.

    const check = chain(
      string(),
      trim(),
      maxLength(6),
    );
    
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check("johann sebastian");
    // => { isOk: false, ... }

    Type parameters

    • V1

    • V2

    • V3

    • V4

    • V5

    • V6

    • V7

    • V8

    • V9

    • V10

    • V11

    • V12

    • V13

    • A: unknown[]

    Parameters

    Returns Check<V1, V13, A>

    A check function.

date

  • date(error?: string): Check<unknown, Date>
  • Creates a check function that fails when the given value is not a date.

    const check = date();
    
    check(new Date());
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not a date"

      The error to give when the value is not a date.

    Returns Check<unknown, Date>

    A check function.

entries

  • entries<I, O, A>(checkKey: Check<string, string, A>, checkValue: Check<I, O, A>): Check<{}, {}, A>
  • Creates a check function that validates the key-value pairs of an object.

    const check = entries(pattern(/^[0-9]+$/), chain(string(), trim()));
    
    check({
      1: " one  ",
      2: "   two  "
    });
    // => {
    //   isOk: true,
    //   value: {
    //      1: "one",
    //      2: "two",
    //   },
    // }
    
    check({ 1: 1 });
    // => { isOk: false, ... }
    
    check({ one: "one" });
    // => { isOk: false, ... }

    Type parameters

    • I

    • O

    • A: unknown[]

    Parameters

    • checkKey: Check<string, string, A>
    • checkValue: Check<I, O, A>

    Returns Check<{}, {}, A>

error

  • error(invalidValue: unknown, error: string, path?: unknown[]): ErrorResult
  • Creates an invalid result.

    Without a path:

    error("value", "is invalid");
    // => {
    //   isOk: false,
    //   error: "is invalid",
    //   invalidValue: "value",
    //   path: [],
    // }

    With a path:

    error("value", "is invalid", ["one", "two"]);
    // => {
    //   isOk: false,
    //   error: "is invalid",
    //   invalidValue: "value",
    //   path: ["one", "two"],
    // }

    Parameters

    • invalidValue: unknown

      The invalid value that led to the error.

    • error: string

      The error associated with the invalid value.

    • Default value path: unknown[] = []

      The keys that lead to the invalid value from the parent object.

    Returns ErrorResult

    An invalid result.

fail

  • fail(error?: undefined | string): Check<unknown, never>
  • fail<I, A>(error: string, path: unknown[], getInvalidValue: (value: I, ...args: A) => unknown): Check<I, never, A>
  • Creates a check function that always fails.

    const check = fail();
    
    check(42);
    // => { isOk: false, ... }

    Parameters

    • Optional error: undefined | string

      The error to give with the invalid value.

    Returns Check<unknown, never>

    A check function.

  • Creates a check function that always fails.

    const check = fail();
    
    check(42);
    // => { isOk: false, ... }

    Type parameters

    • I

    • A: unknown[]

    Parameters

    • error: string

      The error to give with the invalid value.

    • path: unknown[]

      The path to give with the error.

    • getInvalidValue: (value: I, ...args: A) => unknown

      A function to get the invalid value from the passed value.

        • (value: I, ...args: A): unknown
        • Parameters

          • value: I
          • Rest ...args: A

          Returns unknown

    Returns Check<I, never, A>

    A check function.

finite

  • finite(error?: string): Check<unknown, number>
  • Creates a check function that fails when the given value is not a finite number.

    const check = finite();
    
    check(3.14);
    // => { isOk: true, ... }
    check(Infinity);
    // => { isOk: false, ... }
    check(NaN);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not a finite number"

      The error to give when the value is not a finite number.

    Returns Check<unknown, number>

    A check function.

floor

  • Creates a check function that rounds a number down to the previous integer.

    const check = floor();
    
    check(3.14);
    // => {
    //   isOk: true,
    //   value: 3,
    // }
    
    check(-3.14);
    // => {
    //   isOk: true,
    //   value: -4,
    // }

    Returns Check<number>

    A check function.

integer

  • integer(error?: string): Check<unknown, number>
  • Creates a check function that fails when the given value is not an integer.

    const check = integer();
    
    check(42);
    // => { isOk: true, ... }
    check(3.14);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not an integer"

      The error to give when the value is not an integer.

    Returns Check<unknown, number>

    A check function.

is

  • is<V>(value: V, error?: string): Check<unknown, V>
  • Creates a check function that fails when a value is not strictly equal to another.

    const check = is(42);
    
    check(42);
    // => { isOk: true, ... }
    
    check(43);
    // => { isOk: false, ... }

    Type parameters

    • V

    Parameters

    • value: V

      The value to check equality against.

    • Default value error: string = "is invalid"

      The error to give when the check fails.

    Returns Check<unknown, V>

    A check function.

items

  • items<I, O, A>(check: Check<I, O, A>): Check<Iterable<I>, O[], A>
  • Creates a check function that validates the items of an iterable.

    const check = items(chain(string(), trim()));
    
    check([" one  ", "   two  "]);
    // => {
    //   isOk: true,
    //   value: ["one", "two"],
    // }
    
    check(["one", 2]);
    // => { isOk: false, ... }

    Type parameters

    • I

    • O

    • A: unknown[]

    Parameters

    • check: Check<I, O, A>

      The check function to use on the items.

    Returns Check<Iterable<I>, O[], A>

    A check function.

lessThan

  • lessThan(max: number, error?: string): Check<number>
  • Creates a check function that fails if the given value is more than or equal to a maximum.

    const check = lessThan(42);
    
    check(41);
    // => { isOk: true, ... }
    check(43);
    // => { isOk: false, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • max: number

      The value to compare against.

    • Default value error: string = "is too high"

      The error to give if the value is invalid.

    Returns Check<number>

    A check function.

max

  • max(max: number, error?: string): Check<number>
  • Creates a check function that fails if the given value is more than a maximum.

    const check = max(42);
    
    check(41);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: true, ... }
    check(43);
    // => { isOk: false, ... }

    Parameters

    • max: number

      The value to compare against.

    • Default value error: string = "is too high"

      The error to give if the value is invalid.

    Returns Check<number>

    A check function.

maxLength

  • maxLength<T>(max: number, error?: string): Check<T>
  • Creates a check function that fails if the given value is longer than a maximum length.

    const check = maxLength(3);
    
    check([1, 2]);
    // => { isOk: true, ... }
    check([1, 2, 3]);
    // => { isOk: true, ... }
    check([1, 2, 3, 4]);
    // => { isOk: false, ... }

    Type parameters

    • T: ArrayLike<unknown>

    Parameters

    • max: number

      The value to compare the length against.

    • Default value error: string = "is too long"

      The error to give if the value is invalid.

    Returns Check<T>

    A check function.

min

  • min(min: number, error?: string): Check<number>
  • Creates a check function that fails if the given value is less than a minimum.

    const check = min(42);
    
    check(43);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: true, ... }
    check(41);
    // => { isOk: false, ... }

    Parameters

    • min: number

      The value to compare against.

    • Default value error: string = "is too low"

      The error to give if the value is invalid.

    Returns Check<number>

    A check function.

minLength

  • minLength<T>(min: number, error?: string): Check<T>
  • Creates a check function that fails if the given value is shorter than a mininum length.

    const check = minLength(2);
    
    check([1, 2, 3]);
    // => { isOk: true, ... }
    check([1, 2]);
    // => { isOk: true, ... }
    check([1]);
    // => { isOk: false, ... }

    Type parameters

    • T: ArrayLike<unknown>

    Parameters

    • min: number

      The value to compare the length against.

    • Default value error: string = "is too short"

      The error to give if the value is invalid.

    Returns Check<T>

    A check function.

moreThan

  • moreThan(min: number, error?: string): Check<number>
  • Creates a check function that fails if the given value is less than or equal to a minimum.

    const check = moreThan(42);
    
    check(43);
    // => { isOk: true, ... }
    check(41);
    // => { isOk: false, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • min: number

      The value to compare against.

    • Default value error: string = "is too low"

      The error to give if the value is invalid.

    Returns Check<number>

    A check function.

nil

  • nil(error?: string): Check<unknown, null, unknown[]>
  • Creates a check function that fails when the given value is not null.

    const check = null();
    
    check(null);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not null"

      The error to give when the value is not undefined.

    Returns Check<unknown, null, unknown[]>

    A check function.

not

  • not<V, A>(check: Check<V, unknown, A>, error?: undefined | string): Check<V, V, A>
  • not<V, A>(check: Check<V, unknown, A>, error: string, path: unknown[], getInvalidValue: (value: V, ...args: A) => unknown): Check<V, V, A>
  • Creates a check function that negates another check function.

    const check = not(is(42));
    
    check(43);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Type parameters

    • V

    • A: unknown[]

    Parameters

    • check: Check<V, unknown, A>

      The check to negate.

    • Optional error: undefined | string

      The error to give if the value is invalid.

    Returns Check<V, V, A>

    A check function.

  • Creates a check function that negates another check function.

    const check = not(is(42));
    
    check(43);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Type parameters

    • V

    • A: unknown[]

    Parameters

    • check: Check<V, unknown, A>

      The check to negate.

    • error: string

      The error to give if the value is invalid.

    • path: unknown[]

      The path to give with the error.

    • getInvalidValue: (value: V, ...args: A) => unknown

      A function to get the invalid value from the passed value.

        • (value: V, ...args: A): unknown
        • Parameters

          • value: V
          • Rest ...args: A

          Returns unknown

    Returns Check<V, V, A>

    A check function.

nullable

  • nullable<I, O, A>(check: Check<I, O, A>): Check<null | I, null | O, A>
  • Creates a check function that succeeds when the given value is null or the wrapped check function succeeds.

    const check = nullable(number());
    
    check(null);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: true, ... }
    check("jerome");
    // => { isOk: false, ... }

    Type parameters

    • I

    • O

    • A: unknown[]

    Parameters

    • check: Check<I, O, A>

      The check function to run when the value is present.

    Returns Check<null | I, null | O, A>

    A check function.

number

  • number(error?: string): Check<unknown, number>
  • Creates a check function that fails when the given value is not a number.

    const check = number();
    
    check(42);
    // => { isOk: true, ... }
    check("forty-two");
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not a number"

      The error to give when the value is not a number.

    Returns Check<unknown, number>

    A check function.

object

  • object(error?: string): Check<unknown, object>
  • Creates a check function that fails when the given value is not an object.

    const check = object();
    
    check({});
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not an object"

      The error to give when the value is not an object.

    Returns Check<unknown, object>

    A check function.

ok

  • Creates a valid result.

    check.ok("value");
    // => {
    //   isOk: true,
    //   value: "value",
    // }

    Type parameters

    • T

    Parameters

    • value: T

      The valid value to wrap.

    Returns OkResult<T>

    A valid result.

oneOf

  • oneOf<I, O1, A>(...checks: [Check<I, O1, A>]): Check<I, O1, A>
  • oneOf<I, O1, O2, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>]): Check<I, O1 | O2, A>
  • oneOf<I, O1, O2, O3, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>]): Check<I, O1 | O2 | O3, A>
  • oneOf<I, O1, O2, O3, O4, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>]): Check<I, O1 | O2 | O3 | O4, A>
  • oneOf<I, O1, O2, O3, O4, O5, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>]): Check<I, O1 | O2 | O3 | O4 | O5, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, O7, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>, Check<I, O7, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, O7, O8, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>, Check<I, O7, A>, Check<I, O8, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>, Check<I, O7, A>, Check<I, O8, A>, Check<I, O9, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>, Check<I, O7, A>, Check<I, O8, A>, Check<I, O9, A>, Check<I, O10, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9 | O10, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>, Check<I, O7, A>, Check<I, O8, A>, Check<I, O9, A>, Check<I, O10, A>, Check<I, O11, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9 | O10 | O11, A>
  • oneOf<I, O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11, O12, A>(...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>, Check<I, O6, A>, Check<I, O7, A>, Check<I, O8, A>, Check<I, O9, A>, Check<I, O10, A>, Check<I, O11, A>, Check<I, O12, A>]): Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9 | O10 | O11 | O12, A>
  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<I, O1, A>]

      The check functions to try.

    Returns Check<I, O1, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<I, O1, A>, Check<I, O2, A>]

      The check functions to try.

    Returns Check<I, O1 | O2, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>]

      The check functions to try.

    Returns Check<I, O1 | O2 | O3, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>]

      The check functions to try.

    Returns Check<I, O1 | O2 | O3 | O4, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • A: unknown[]

    Parameters

    • Rest ...checks: [Check<I, O1, A>, Check<I, O2, A>, Check<I, O3, A>, Check<I, O4, A>, Check<I, O5, A>]

      The check functions to try.

    Returns Check<I, O1 | O2 | O3 | O4 | O5, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • O7

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • O7

    • O8

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • O7

    • O8

    • O9

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • O7

    • O8

    • O9

    • O10

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9 | O10, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • O7

    • O8

    • O9

    • O10

    • O11

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9 | O10 | O11, A>

    A check function.

  • Creates a check function that tests given check functions until one succeeds.

    If all check functions fail, the last failing result is returned.

    const check = oneOf(
      integer(),
      chain(string(), trim()),
      fail("is not an integer or a string"),
    );
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check(" jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }
    
    check(true);
    // => {
    //   isOk: false,
    //   error: "is not an integer or a string",
    //   ...
    // }

    Type parameters

    • I

    • O1

    • O2

    • O3

    • O4

    • O5

    • O6

    • O7

    • O8

    • O9

    • O10

    • O11

    • O12

    • A: unknown[]

    Parameters

    Returns Check<I, O1 | O2 | O3 | O4 | O5 | O6 | O7 | O8 | O9 | O10 | O11 | O12, A>

    A check function.

optional

  • optional<I, O, A>(check: Check<I, O, A>): Check<undefined | I, undefined | O, A>
  • Creates a check function that succeeds when the given value is undefined or the wrapped check function succeeds.

    const check = optional(number());
    
    check(undefined);
    // => { isOk: true, ... }
    check(42);
    // => { isOk: true, ... }
    check("jerome");
    // => { isOk: false, ... }

    Type parameters

    • I

    • O

    • A: unknown[]

    Parameters

    • check: Check<I, O, A>

      The check function to run when the value is present.

    Returns Check<undefined | I, undefined | O, A>

    A check function.

pass

  • Creates a check function that always succeeds.

    const check = pass();
    
    check(42);
    // => { isOk: true, ... }

    Type parameters

    • V

    Returns Check<V>

    A check function.

pattern

  • pattern(regexp: RegExp, error?: string): Check<string>
  • Creates a check function that fails if a string does not match a regular expression.

    const check = pattern(/[a-z]/i);
    
    check("jerome");
    // => { isOk: true, ... }
    check("42");
    // => { isOk: false, ... }

    Parameters

    • regexp: RegExp

      The regular expression to test against.

    • Default value error: string = "is invalid"

      The error to give if the value is invalid.

    Returns Check<string>

    A check function.

round

  • Creates a check function that rounds a number to the nearest integer.

    const check = round();
    
    check(3.14);
    // => {
    //   isOk: true,
    //   value: 3,
    // }
    
    check(3.86);
    // => {
    //   isOk: true,
    //   value: 4,
    // }

    Returns Check<number>

    A check function.

shape

  • shape<O, A>(checks: {}): Check<object, O, A>
  • shape<I, O, A>(checks: {}): Check<I, O, A>
  • Creates a check function that validates the properties of an object.

    const check = shape({
      name: chain(string(), trim()),
      age: integer(),
    });
    
    check({
      name: "  Jérôme ",
      age: 30,
    });
    // => {
    //   isOk: true,
    //   value: {
    //     name: "Jérôme",
    //     age: 30,
    //   },
    // }
    
    check({
      name: "Jérôme",
      age: "thirty",
    });
    // => { isOk: false, ... }

    Type parameters

    • O

    • A: unknown[]

    Parameters

    • checks: {}

      An object containing check functions.

    Returns Check<object, O, A>

    A check function.

  • Creates a check function that validates the properties of an object.

    const check = shape({
      name: chain(string(), trim()),
      age: integer(),
    });
    
    check({
      name: "  Jérôme ",
      age: 30,
    });
    // => {
    //   isOk: true,
    //   value: {
    //     name: "Jérôme",
    //     age: 30,
    //   },
    // }
    
    check({
      name: "Jérôme",
      age: "thirty",
    });
    // => { isOk: false, ... }

    Type parameters

    • I: {}

    • O

    • A: unknown[]

    Parameters

    • checks: {}

      An object containing check functions.

    Returns Check<I, O, A>

    A check function.

string

  • string(error?: string): Check<unknown, string>
  • Creates a check function that fails when the given value is not a string.

    const check = string();
    
    check("forty-two");
    // => { isOk: true, ... }
    check(42);
    // => { isOk: false, ... }

    Parameters

    • Default value error: string = "is not a string"

      The error to give when the value is not a string.

    Returns Check<unknown, string>

    A check function.

test

  • test<I, O, A>(predicate: (value: I, ...args: A) => value is O, error?: undefined | string): Check<I, O, A>
  • test<I, O, A>(predicate: (value: I, ...args: A) => value is O, error: string, path: unknown[], getInvalidValue: (value: I, ...args: A) => unknown): Check<I, O, A>
  • test<V, A>(predicate: (value: V, ...args: A) => boolean, error?: undefined | string): Check<V, V, A>
  • test<V, A>(predicate: (value: V, ...args: A) => boolean, error: string, path: unknown[], getInvalidValue: (value: V, ...args: A) => unknown): Check<V, V, A>
  • Creates a check function that succeeds or fails based on a predicate function.

    const check = test(value => value === 42);
    
    check(42);
    // => { isOk: true, ... }
    
    check(43);
    // => { isOk: false, ... }

    Type parameters

    • I

    • O: I

    • A: unknown[]

    Parameters

    • predicate: (value: I, ...args: A) => value is O

      The predicate function to test with.

        • (value: I, ...args: A): value is O
        • Parameters

          • value: I
          • Rest ...args: A

          Returns value is O

    • Optional error: undefined | string

      The error to give when the predicate fails.

    Returns Check<I, O, A>

    A check function.

  • Creates a check function that succeeds or fails based on a predicate function.

    const check = test(value => value === 42);
    
    check(42);
    // => { isOk: true, ... }
    
    check(43);
    // => { isOk: false, ... }

    Type parameters

    • I

    • O: I

    • A: unknown[]

    Parameters

    • predicate: (value: I, ...args: A) => value is O

      The predicate function to test with.

        • (value: I, ...args: A): value is O
        • Parameters

          • value: I
          • Rest ...args: A

          Returns value is O

    • error: string

      The error to give when the predicate fails.

    • path: unknown[]

      The path to give with the error.

    • getInvalidValue: (value: I, ...args: A) => unknown

      A function to get the invalid value from the passed value.

        • (value: I, ...args: A): unknown
        • Parameters

          • value: I
          • Rest ...args: A

          Returns unknown

    Returns Check<I, O, A>

    A check function.

  • Creates a check function that succeeds or fails based on a predicate function.

    const check = test(value => value === 42);
    
    check(42);
    // => { isOk: true, ... }
    
    check(43);
    // => { isOk: false, ... }

    Type parameters

    • V

    • A: unknown[]

    Parameters

    • predicate: (value: V, ...args: A) => boolean

      The predicate function to test with.

        • (value: V, ...args: A): boolean
        • Parameters

          • value: V
          • Rest ...args: A

          Returns boolean

    • Optional error: undefined | string

      The error to give when the predicate fails.

    Returns Check<V, V, A>

    A check function.

  • Creates a check function that succeeds or fails based on a predicate function.

    const check = test(value => value === 42);
    
    check(42);
    // => { isOk: true, ... }
    
    check(43);
    // => { isOk: false, ... }

    Type parameters

    • V

    • A: unknown[]

    Parameters

    • predicate: (value: V, ...args: A) => boolean

      The predicate function to test with.

        • (value: V, ...args: A): boolean
        • Parameters

          • value: V
          • Rest ...args: A

          Returns boolean

    • error: string

      The error to give when the predicate fails.

    • path: unknown[]

      The path to give with the error.

    • getInvalidValue: (value: V, ...args: A) => unknown

      A function to get the invalid value from the passed value.

        • (value: V, ...args: A): unknown
        • Parameters

          • value: V
          • Rest ...args: A

          Returns unknown

    Returns Check<V, V, A>

    A check function.

toBoolean

  • toBoolean(): Check<unknown, boolean>
  • Creates a check function that converts the given value into a boolean.

    const check = toBoolean();
    
    check(1);
    // => {
    //   isOk: true,
    //   value: true,
    // }
    
    check(0);
    // => {
    //   isOk: true,
    //   value: false,
    // }

    Returns Check<unknown, boolean>

    A check function.

toDate

  • toDate(): Check<unknown, Date>
  • Creates a check function that converts the given value into a date.

    const check = toDate();
    
    check("2020/05/07");
    // => {
    //   isOk: true,
    //   value: Date(...),
    // }
    
    check(1588802400000);
    // => {
    //   isOk: true,
    //   value: Date(...),
    // }

    Returns Check<unknown, Date>

    A check function.

toLower

  • toLower(): Check<string>
  • Creates a check function that converts a string to lower case.

    const check = toLower();
    
    check("JEROME");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }

    Returns Check<string>

    A check function.

toNumber

  • toNumber(): Check<unknown, number>
  • Creates a check function that converts the given value into a number.

    const check = toNumber();
    
    check("42");
    // => {
    //   isOk: true,
    //   value: 42,
    // }
    
    check("asdf");
    // => {
    //   isOk: true,
    //   value: NaN,
    // }

    Returns Check<unknown, number>

    A check function.

toString

  • toString(): Check<unknown, string>
  • Creates a check function that converts the given value into a string.

    const check = toString();
    
    check(42);
    // => {
    //   isOk: true,
    //   value: "42",
    // }
    
    check(null);
    // => {
    //   isOk: true,
    //   value: "",
    // }

    Returns Check<unknown, string>

    A check function.

toUpper

  • toUpper(): Check<string>
  • Creates a check function that converts a string to upper case.

    const check = toUpper();
    
    check("jerome");
    // => {
    //   isOk: true,
    //   value: "JEROME",
    // }

    Returns Check<string>

    A check function.

transform

  • transform<I, O, A>(trans: (value: I, ...args: A) => O): Check<I, O, A>
  • Creates a check function that transforms a value into another.

    const check = transform(value => value / 2);
    
    check(42);
    // => {
    //   isOk: true,
    //   value: 21,
    // }

    All the arguments passed to resulting check function are passed to the transform function:

    const check = transform((value, other) => value / other);
    
    check(42, 2);
    // => {
    //   isOk: true,
    //   value: 21,
    // }

    Type parameters

    • I

    • O

    • A: unknown[]

    Parameters

    • trans: (value: I, ...args: A) => O

      The function to transform with.

        • (value: I, ...args: A): O
        • Parameters

          • value: I
          • Rest ...args: A

          Returns O

    Returns Check<I, O, A>

    A check function.

trim

  • Creates a check function that trims a string.

    const check = trim();
    
    check("  jerome   ");
    // => {
    //   isOk: true,
    //   value: "jerome",
    // }

    Returns Check<string>

    A check function.

truncate

  • truncate(): Check<number>
  • Creates a check function that transforms a number into its integer part.

    const check = truncate();
    
    check(3.14);
    // => {
    //   isOk: true,
    //   value: 3,
    // }
    
    check(-3.14);
    // => {
    //   isOk: true,
    //   value: -3,
    // }

    Returns Check<number>

    A check function.

tuple

  • tuple<I, O, A>(checks: {}, lengthError?: undefined | string): Check<I, O, A>
  • Creates a check function that validates the items of an array.

    const check = tuple([
      chain(string(), trim()),
      number(),
    ]);
    
    check(["  Jérôme ", 30]);
    // => {
    //   isOk: true,
    //   value: ["Jérôme", 30],
    // }
    
    check(["Jérôme", "thirty"]);
    // => { isOk: false, ... }
    
    check(["Jérôme", 30, "Web Developer"]);
    // => { isOk: false, ... }

    Type parameters

    • I: unknown[]

    • O: unknown[]

    • A: unknown[]

    Parameters

    • checks: {}

      An array of check functions.

    • Optional lengthError: undefined | string

      The error to give when the value does not have the right length

    Returns Check<I, O, A>

    A check function.

Generated using TypeDoc