0.0.4 • Published 1 year ago

vibrant-veil-validator v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

vibrant-veil-validator

A versatile input validator with support for required fields, type checking, and custom validation rules.

Installation

To install vibrant-veil-validator, run:

npm install vibrant-veil-validator

Usage

First, import vibrant-veil-validator and define your validation rules:

const Validator = require('vibrant-veil-validator');

const rules = {
name: { required: true, type: 'string' },
age: { required: true, type: 'number', custom: (value) => value >= 18 },
email: { required: true, type: 'string', custom: (value) => /\S+@\S+\.\S+/.test(value) }
};

const validator = new Validator(rules);

Then, use it to validate input:

const input = {
name: 'John Doe',
age: 25,
email: 'john@example.com'
};

const result = validator.validate(input);

if (result.valid) {
console.log('Validation passed.');
} else {
console.log('Validation failed:', result.errors);
}
0.0.4

1 year ago

0.0.3

1 year ago

0.0.1-alpha

1 year ago