The type of input values.
The type of valid output values.
The type of additional arguments to the function.
A validation result.
The type of valid values.
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, ... }
The error to given when the value is not NaN.
A check function.
Creates a check function that fails when the given value is not an array.
const check = array();
check([]);
// => { isOk: true, ... }
check(42);
// => { isOk: true, ... }
The error to give when the value is not an array.
A check function.
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, ... }
The error to give when the value is not a boolean.
A check function.
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,
// }
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, ... }
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, ... }
The check functions to chain together.
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, ... }
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
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, ... }
The check functions to chain together.
A check function.
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, ... }
The error to give when the value is not a date.
A check function.
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, ... }
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"],
// }
The invalid value that led to the error.
The error associated with the invalid value.
The keys that lead to the invalid value from the parent object.
An invalid result.
Creates a check function that always fails.
const check = fail();
check(42);
// => { isOk: false, ... }
The error to give with the invalid value.
A check function.
Creates a check function that always fails.
const check = fail();
check(42);
// => { isOk: false, ... }
The error to give with the invalid value.
The path to give with the error.
A function to get the invalid value from the passed value.
A check function.
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, ... }
The error to give when the value is not a finite number.
A check function.
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,
// }
A check function.
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, ... }
The error to give when the value is not an integer.
A check function.
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, ... }
The value to check equality against.
The error to give when the check fails.
A check function.
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, ... }
The check function to use on the items.
A check function.
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, ... }
The value to compare against.
The error to give if the value is invalid.
A check function.
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, ... }
The value to compare against.
The error to give if the value is invalid.
A check function.
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, ... }
The value to compare the length against.
The error to give if the value is invalid.
A check function.
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, ... }
The value to compare against.
The error to give if the value is invalid.
A check function.
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, ... }
The value to compare the length against.
The error to give if the value is invalid.
A check function.
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, ... }
The value to compare against.
The error to give if the value is invalid.
A check function.
Creates a check function that fails when the given value is not null.
const check = null();
check(null);
// => { isOk: true, ... }
check(42);
// => { isOk: false, ... }
The error to give when the value is not undefined.
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, ... }
The check to negate.
The error to give if the value is invalid.
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, ... }
The check to negate.
The error to give if the value is invalid.
The path to give with the error.
A function to get the invalid value from the passed value.
A check function.
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, ... }
The check function to run when the value is present.
A check function.
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, ... }
The error to give when the value is not a number.
A check function.
Creates a check function that fails when the given value is not an object.
const check = object();
check({});
// => { isOk: true, ... }
check(42);
// => { isOk: false, ... }
The error to give when the value is not an object.
A check function.
Creates a valid result.
check.ok("value");
// => {
// isOk: true,
// value: "value",
// }
The valid value to wrap.
A valid result.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
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",
// ...
// }
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
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",
// ...
// }
The check functions to try.
A check function.
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, ... }
The check function to run when the value is present.
A check function.
Creates a check function that always succeeds.
const check = pass();
check(42);
// => { isOk: true, ... }
A check function.
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, ... }
The regular expression to test against.
The error to give if the value is invalid.
A check function.
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,
// }
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, ... }
An object containing check functions.
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, ... }
An object containing check functions.
A check function.
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, ... }
The error to give when the value is not a string.
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, ... }
The predicate function to test with.
The error to give when the predicate fails.
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, ... }
The predicate function to test with.
The error to give when the predicate fails.
The path to give with the error.
A function to get the invalid value from the passed value.
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, ... }
The predicate function to test with.
The error to give when the predicate fails.
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, ... }
The predicate function to test with.
The error to give when the predicate fails.
The path to give with the error.
A function to get the invalid value from the passed value.
A check function.
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,
// }
A check function.
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(...),
// }
A check function.
Creates a check function that converts a string to lower case.
const check = toLower();
check("JEROME");
// => {
// isOk: true,
// value: "jerome",
// }
A check function.
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,
// }
A check function.
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: "",
// }
A check function.
Creates a check function that converts a string to upper case.
const check = toUpper();
check("jerome");
// => {
// isOk: true,
// value: "JEROME",
// }
A check function.
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,
// }
The function to transform with.
A check function.
Creates a check function that trims a string.
const check = trim();
check(" jerome ");
// => {
// isOk: true,
// value: "jerome",
// }
A check function.
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,
// }
A check function.
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, ... }
An array of check functions.
The error to give when the value does not have the right length
A check function.
Generated using TypeDoc
A check function.