- The()
- #test()
- #assert()
- #not
- #required()
- #optional()
- #merge()
- #clone()
- The.extend()
- #string()
- #number()
- #boolean()
- #date()
- #regexp()
- #error()
- #function()
- #arguments()
- #object()
- #array()
- #stream()
- #buffer()
- #empty()
- #equal()
- #exist()
- #instanceOf()
- #length()
- #startWith()
- #include()
- #endWith()
- #match()
- #lowerCase()
- #upperCase()
- #min()
- #more()
- #max()
- #less()
- #integer()
- #divisible()
- #precision()
- #scale()
- #unique()
- #json()
- ascii
- alpha
Run all of the attached tests against a provided value.
The().string().test('') // -> true
The().string().test(1) // -> ValidationErrorRun all of the attached tests against a provided value and throws if any fail.
The().string().assert('') // -> true
The().string().assert(1) // -> throw ValidationErrorStores negated versions of all tests.
The().not.string().test(1) // -> true
The().not.string().test('1') // -> ValidationErrorFail tests with nullish values. (This is the default behaviour).
The().required(false).test(null) // -> true
The().required().test(null) // -> ValidationErrorPass tests with nullish values.
The().optional().test(null) // -> true
The().optional(false).test(null) -> // ValidationErrorMerge other tests onto the current instance.
The().string().merge(The().startWith('hi')).test('hi123') // -> true
The().string().merge(The().startWith('hi')).test('123hi') // -> ValidationErrorMake a copy of the current tests.
Adds new custom tests, with their negated (#not) counter parts.
The.extend({ any: funciton (value) { return true; } })
The().any().test(1) // -> trueValue must be a String.
The().string().test("hello") //-> true
The().string().test(1) //-> ValidationErrorValue must be a Number.
The().number().test(1) //-> true
The().number().test("hello") //-> ValidationErrorValue must be a Boolean.
The().boolean().test(true) //-> true
The().boolean().test(1) //-> ValidationErrorValue must be a Date.
The().date().test(new Date) //-> true
The().date().test("2015-08-09T01:09:44.484Z") //-> ValidationErrorValue must be a RegExp.
The().regexp().test(/\d/) //-> true
The().regexp().test("/\d/") //-> ValidationErrorValue must be an Error.
The().error().test(new Error) //-> true
The().error().test(1) //-> ValidationErrorValue must be a Function.
The().function().test(function(){}) //-> true
The().function().test(1) //-> ValidationErrorValue must be a arguments from a function.
The().arguments().test(arguments) //-> true
The().arguments().test([]) //-> ValidationErrorValue must be an Object with the provided structure.
The().object({ a: The().string() }).test({ a: "hi" }) //-> true
The().object({ a: The().string() }).test({ a: 1 }) //-> ValidationErrorValue must be an Array of items that pass the provided tests.
The().array(The().number()).test([1, 2, 3]) //-> true
The().array(The().number()).test([1, 2, "3"]) //-> ValidationErrorValue must be a Stream.
The().stream().test(fs.createReadStream(...)) //-> true
The().stream().test(new Buffer("")) //-> ValidationErrorValue must be a Buffer.
The().stream().test(new Buffer("")) //-> true
The().stream().test(fs.createReadStream(...)) //-> ValidationErrorValue must have no enumerable properties.
The().empty().test([]) //-> true
The().empty().test([1]) //-> ValidationErrorValue must equal one of the arguments.
The().equal(1, 2).test(1) //-> true
The().equal(1, 2).test(3) //-> ValidationErrorValue must not be nullish.
The().exist().test("") //-> true
The().exist().test(null) //-> ValidationErrorValue must be an instanceOf a constructor.
The().instanceOf(Error).test(new Error) //-> true
The().instanceOf(Error).test(1) //-> ValidationErrorValue must have a #length within the provided range.
The().length(1, 3).test("hi") //-> true
The().length(1, 3).test("hello") //-> ValidationErrorValue must start with the provided argument.
The().startWith("hi").test("hi123") //-> true
The().startWith("hi").test("123hi") //-> ValidationErrorValue must contain each argument.
The().include("hi", "1").test("hi123") //-> true
The().include("hi").test("hi23") //-> ValidationErrorValue must end with the provided argument.
The().endWith("hi").test("hi123") //-> ValidationError
The().endWith("hi").test("123hi") //-> trueValue must match a provided regular expression.
The().match(/^[a-z]+$/).test("hi") //-> true
The().match(/^[a-z]+$/).test("hi123") //-> ValidationErrorValue must be all lowercase.
The().lowerCase().test("hi") //-> true
The().lowerCase().test("Hi") //-> ValidationErrorValue must be all uppercase.
The().upperCase().test("HI") //-> true
The().upperCase().test("Hi") //-> ValidationErrorValue must be greater than or equal to a minimum.
The().min(1).test(1) //-> true
The().min(1).test(0) //-> ValidationErrorValue must be greater than a minimum.
The().more(1).test(2) //-> true
The().more(1).test(1) //-> ValidationErrorValue must be less than or equal to a maximum.
The().max(1).test(1) //-> true
The().min(1).test(2) //-> ValidationErrorValue must be less than a minimum.
The().less(1).test(0) //-> true
The().less(1).test(1) //-> ValidationErrorValue must be an integer.
The().integer().test(1) //-> true
The().integer().test(1.1) //-> ValidationErrorValue must divide evenly by a divisor.
The().divisible(5).test(10) //-> true
The().divisible(5).test(11) //-> ValidationErrorValue must have a precision within the provided range.
The().precision(1, 3).test(1.23) //-> true
The().precision(1, 3).test(1.2345) //-> ValidationErrorValue must have a scale within the provided range.
The().scale(1, 3).test(123) //-> true
The().scale(1, 3).test(12345) //-> ValidationErrorValue must consist of unique indexed items.
The().unique().test([1, 2, 3]) //-> true
The().unique().test([1, 1, 3]) //-> ValidationErrorValue must successfully parse into JSON.
The().json().test('{ "a": "b" }') //-> true
The().json().test("hello") //-> ValidationErroreslint-disable
eslint-enable