toniw-validator
v1.0.1
Published
validation library for validating data, input, and forms
Maintainers
Readme
toniw-validator
The minimalist data validation library you didn’t know you needed — until now. Say goodbye to endless if-checks and hello to clean, sweet validation magic.
Installation npm install validator
Quick Start import {validate, required, minLength, maxLength, number} from "toniw-validator" const rules = { name: [required(), minLength(3), maxLength(10)], age: [required(), number()], }; const data = { name: "John", age: 30 };
const result = validate(rules, data); console.log(result);
API Breakdown validate(rules, data) rules: object with fields as keys and arrays of validator functions as values
data: object with the actual stuff to check
Returns:
{ isValid: boolean, // true if all clear, false if drama errors: { // detailed receipts on what went wrong [field]: string[] } }
Why bother? Stop writing the same boring checks over and over
Get nice, readable error messages
Lightweight and zero dependencies — no extra fat here
Future Features (coming soon™) Async validators (because promises are the future)
TypeScript typings, so your editor stops crying
More built-in rules, because variety is life
