Rule-based data validation library in Node.js
Rule-based data validation in JS. Extendable, function-oriented, i18n-supported
Discovering a data validation library that seamlessly combines ease of use, the ability to store validation rules for future use, and robust internationalization (i18n) support is a formidable challenge. While numerous data validation libraries exist, finding one that fulfills all these criteria is often elusive. Some libraries that do meet these requirements are unfortunately no longer actively maintained.
Robust Validator was born out of the need for a versatile data validation solution that not only simplifies the validation process but also empowers developers with the flexibility to preserve and reuse validation rules. This library aims to bridge the gap by offering a user-friendly experience, ensuring your validation needs are met comprehensively.
Why choose Robust Validator? Itβs more than just a data validation tool; itβs a commitment to providing a reliable, well-maintained, and feature-rich solution for developers who value simplicity and effectiveness in their projects.
I decided on some fundamental rules while building this library:
The library can be installed into an existing project:
$ npm install --save robust-validator
Using robust-validator is very simple.
You should just call the validate()
function with data and the definition.
import { validate, setLocales, en } from "robust-validator";
setLocales(en);
const data = {
email: "not-a-valid-email",
name: "John",
surname: "Doe",
};
const definition = {
email: "required|email",
name: "required|min:1|max:50",
surname: "required|min:1|max:50",
};
const result = await validate(data, definition);
console.log(result);
Made with contrib.rocks.