This repository was archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Ernest edited this page Apr 6, 2020
·
52 revisions
The most customizable verification framework for JavaScript.
Intuitive APIs. 🎯
Asynchronous Rules Support.
Type Annotation Support. 💡
Full-custom Message Support.
Written in TypeScript. 💪
Self Sufficient.
// custom rules
const minlength = length => ({ value }) => {
if (value.length < length) {
return `Must be at least ${length} characters long.`
}
}
const form = {
password: '123'
}
const schema = VerifyJs.createSchema({
password: {
$rule: minlength(6)
}
})
schema.$verifySync(form)
schema.$hasMessage // true
schema.$messages // ['Must be at least 6 characters long.']There is no best way to implement the rules for every projects.
For example, should we verify form.interests in the following situation?
const minLengthA = length => ({ value }) => {
if (value.length < length) {
return `This field should contains at least ${length} thing(s).`
}
}
const minLengthB = length => ({ value }) => {
if (value.length !== 0 && value.length < length) {
return `This field should contains at least ${length} thing(s).`
}
}
const form = {
name: 'Herbert',
interests: [], // given empty array
}
const schema = VerifyJs.createSchema({
interests: {
$rule: {
minLength(3), // [] or [`This field should contains at least 3 thing(s).`]
}
}
})