Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.
Ernest edited this page Apr 6, 2020 · 52 revisions

The most customizable verification framework for JavaScript.

Feature

Intuitive APIs. 🎯

Asynchronous Rules Support.

Type Annotation Support. 💡

Full-custom Message Support.

Written in TypeScript. 💪

Self Sufficient.

Getting Started

// 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.']

No Built-in Rules

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).`]
    }
  }
})

Clone this wiki locally