valideus
v0.0.4
Published
0 dependencies validation library
Downloads
4
Maintainers
Readme
Valideus: Data Validation for JavaScript Projects
Valideus is a lightweight library that simplifies data validation in your JavaScript applications. It provides a user-friendly API for defining validation rules and ensuring your data adheres to those rules.
Installation
Install Valideus using npm:
npm install valideus
Usage
- Import the Package:
import Valideus from 'valideus'; // Assuming ES Modules
- Create a Validator Instance:
const validation = new Valideus()
- Define Validation Rules:
validation.addField(new FieldBuilder().setName("required_field").setRequired(true)) //Required field
validation.addField(new FieldBuilder().setName("minlim").setMinLength(5)) //Minimum length limit
validation.addField(new FieldBuilder().setName("maxlim").setMaxLength(5)) //Maximum length limit
//Or combined
validation.addField(
new FieldBuilder()
.setName("full_power")
.setMaxLength(100))
.setMinimuLength(10)
.setRequired(true)
- Validate Your Data:
validation.validate({
required_field: "Required field',
minlim: '123', // <-- here is an error because min length is 5
//maxlim: empt <-- no error here because its not required AND NOT INCLUDED.
full_power: '' // <-- here is an error as well because its required but its empty
})
- Use the validation output
if(errors) return // Simple as that because if there are no errors it will return null
or you can print them:
errors.forEach(error => console.error(error.name.concat(":", error.error)))