@darkwolf/validator.cjs
v1.0.4
Published
Validator
Downloads
12
Maintainers
Readme
Validator
Install
ECMAScript (Node.js v12.x LTS or higher)
npm i --save @darkwolf/validator.mjs
CommonJS (Node.js v10.x LTS or higher)
npm i --save @darkwolf/validator.cjs
Using
// ECMAScript
import Validator, { ValidationError } from '@darkwolf/validator.mjs'
// CommonJS
const Validator = require('@darkwolf/validator.cjs')
const { ValidationError } = Validator
const validation = new Validator('Ave, Darkwolf!')
.isString()
.validate((value, valid) => {
if (!valid) {
throw new ValidationError(value, 'Value must be a string.')
}
})
.startsWith('Ave')
validation.valid // => true
if (!+validation) {
throw new ValidationError(validation.value, `Value must start with 'Ave'.`)
}