Only allows numbers in a range between min and max
import yxc from "@dotvirus/yxc"
yxc.number().between(0, 5).validate(-1) // -> Fails
yxc.number().between(0, 5).validate(5.5) // -> Fails
yxc.number().between(0, 5).validate(0) // -> OK
yxc.number().between(0, 5).validate(3.2) // -> OK
yxc.number().between(0, 5).validate(5) // -> OK
Alias for custom
Add a custom function to test the value with
import yxc from "@dotvirus/yxc"
yxc.string().test()
Only allows a selection of values
import yxc from "@dotvirus/yxc"
const allowedValues = ["test", "test2", "test3"]
yxc.string().enum(allowedValues).validate("test") // -> OK
yxc.string().enum(allowedValues).validate("asdasd") // -> Fails
Alias for equals
Alias for equals
Only allows a certain value Value is checked using strict equality (===)
import yxc from "@dotvirus/yxc"
yxc.string().equals("test").validate("test") // -> OK
yxc.string().equals("test").validate("test2") // -> Fails
Alias for integer
Only allows integers (whole numbers)
import yxc from "@dotvirus/yxc"
yxc.number().validate(4.5) // -> OK
yxc.number().integer().validate(4.5) // -> Fails
yxc.number().integer().validate(4) // -> OK
Only allows numbers equal to or smaller than min
import yxc from "@dotvirus/yxc"
yxc.number().max(0).validate(1) // -> Fails
yxc.number().max(0).validate(0) // -> OK
yxc.number().max(0).validate(-1) // -> OK
Only allows numbers equal to or greater than min
import yxc from "@dotvirus/yxc"
yxc.number().min(0).validate(-1) // -> Fails
yxc.number().min(0).validate(0) // -> OK
yxc.number().min(0).validate(1) // -> OK
Only allow natural numbers
Only allows numbers smaller than 0
import yxc from "@dotvirus/yxc"
yxc.number().validate(0) // -> Fails
yxc.number().integer().validate(4) // -> Fails
yxc.number().integer().validate(-4) // -> OK
Allows null value
Allows undefined value
Only allows numbers greater than 0
import yxc from "@dotvirus/yxc"
yxc.number().validate(0) // -> Fails
yxc.number().integer().validate(-4) // -> Fails
yxc.number().integer().validate(4) // -> OK
Alias for custom
Alias for custom
Alias for custom
Validate a value Returns a IValidationResult array
import yxc from "@dotvirus/yxc"
yxc.string().validate(myValue)
Generated using TypeDoc
Number handler