Package detail

robust-validator

axe-api2kMIT3.0.0

Rule-based data validation library

robust-validator, validatorjs, validator.js, data validation

readme

#



Robust Validator
npm version

Rule-based data validation in JS. Extendable, function-oriented, i18n-supported

Documentation

💡 Why?

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.

🤞 Principles

I decided on some fundamental rules while building this library:

  • ✅︎ Every validation rule should be an independent function.
  • ✅︎ Every validation rule should be able to be used separately
  • ✅︎ All validation definition should be able to be stored anywhere (database, memory, configuration files, 3rd party API, etc) to be used later.
  • ✅︎ All validation rules should be able to be used in different languages.
  • ✅︎ Contribution to the rule set should be easy.
  • ✅︎ Should be well-documented.

🏃 Installation

The library can be installed into an existing project:

$ npm install --save robust-validator

💪 Usage

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);

🤝 Contributors

Made with contrib.rocks.

⚖️ License

MIT License

changelog

Release Notes

3.0.0 (2025-07-13)

Breaking changes

Rename rule names:

inincludes

isInisIncludes

String rules: in:admin,moderatorincludes:admin,moderator

Fixes

  • Fixed: Declarative usage ofin:A,B does not validate B (#73)

Improvements

  • Documentation

2.2.1 (2025-02-03)

🎉 Big thanks to our contributors for this release! Special shoutout to: @christoph-kluge 🚀👏

Your help makes this project better—cheers! 🎩✨

  • Fixed: Argument parsing issue on different functions #70
  • Fixed: Internal server error: DEFINED_RULES.includes is not a function #68

2.2.0 (2025-01-13)

  • Array and object validation #54

2.1.1 (2024-10-27)

  • TypeError: list.map is not a function #62

2.1.0 (2024-10-19)

  • Added isRegistered() function. #60

2.0.1 (2024-09-28)

  • Fixed validation messages in English

2.0.0 (2024-09-27)

  • Fixed bundling issues
  • The dayjs library with date-fns. You MUST replace the date formats:
    • YYYY-MM-DD => yyyy-MM-dd

1.1.1 (2024-09-19)

  • Security fix

1.1.0 (2024-02-17)

  • Fixed bundling issues
  • Reduced library size.
  • Fixed custom rule registration issue #43

Breaking changes

Before:

import { validate, setLocales } from "robust-validator";
import en from "robust-validator/dist/i18n/en.json";

After:

import { validate, setLocales, en } from "robust-validator";

1.0.1 (2024-02-16)

Fixed

  • Fixed module target

1.0.0 (2024-02-11)

  • Initial version