rulingjs
v1.1.0
Published
Just a simple set of useful functions to check validation rules
Downloads
190
Readme
RulingJs
Just a simple set of useful functions to check validation rules
Install
npm i -S rulingjs
To Do List
- ~~Translate in multiple languages~~
- Automate NPM publication with CI/CD pipeline
- ~~Add tests~~
Usage
Instanciating a rule
// Basic rule
const requiredRule = ruling.required()
// Rule with custom error message
const requiredRule = ruling.required('This is a mandatory field, dude !')
Change language
import ruling from 'ruling'
import fr from 'ruling/locale/fr.js'
const rulingFr = ruling.create({
lang: fr
})
const requiredRule = rulingFr.required()
Use a rule with Vuetify
<template>
<v-text-field label="Your email"
:rules="[ruling.required(), ruling.email()]"
/>
</template>
Rules
email
ruling.email(customErrorMessage?: string)
isCapital
ruling.isCapital(customErrorMessage?: string)
isNumber
ruling.isNumber(customErrorMessage?: string)
isInteger
ruling.isInteger(customErrorMessage?: string)
isCapitalOrNumber
ruling.isCapitalOrNumber(customErrorMessage?: string)
isDefined
ruling.isDefined(customErrorMessage?: string)
maxLength
ruling.maxLength(len: number, customErrorMessage?: string)
minLength
ruling.minLength(len: number, customErrorMessage?: string)
NotContain
ruling.NotContain(forbiddenCharacters: string[], customErrorMessage?: string)
notEmpty
ruling.notEmpty(customErrorMessage?: string)
required
ruling.required(customErrorMessage?: string)
strictLength
ruling.strictLength(len: number, customErrorMessage?: string)
pattern
ruling.pattern(pattern: RegExp, customErrorMessage?: string)
Thanks
Thanks to @Vincere1st for contributions