GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - axe-api/validator: Rule-based data validation library in Node.js

BranchesTags
Open more actions menu

Latest commit

 

History

282 Commits
282 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
docs
docs
 
 
scripts
scripts
 
 
src
src
 
 
tests
tests
 
 
.eslintrc.cjs
.eslintrc.cjs
 
 
.gitignore
.gitignore
 
 
.npmignore
.npmignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.json
.prettierrc.json
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
SECURITY.md
SECURITY.md
 
 
default.ts
default.ts
 
 
index.ts
index.ts
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
readme.md
readme.md
 
 
rollup.config.mjs
rollup.config.mjs
 
 
tsconfig.json
tsconfig.json
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation



Robust Validator
npm version

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

Documentation

Why?

Most validation libraries are either hard to use, missing key features, or no longer maintained. It’s tough to find one that lets you reuse rules, supports multiple languages, and still feels easy to work with.

Robust Validator was built to solve that. It makes validation simple, reusable, and flexible. You can define your rules once and use them anywhere, and it works great with multiple languages out of the box.

If you want a validation library that just works, is easy to read, and stays up to date, Robust Validator is a solid choice.

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

Nested data validation

This feature allows dynamic traversal of nested data structures, supporting complex validation rules for paths like users.*.addresses.*.city.

It is inspired by Laravel's validation system and works seamlessly with arrays and objects, including deeply nested data.

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

setLocales(en);

const data = {
  secret: "some secret",
  users: [
    { addresses: [{ city: "New York" }, { city: "Istanbul" }] },
    { addresses: [{ city: "New York" }, { street: "Wall Street" }] },
  ],
  permissons: { read: true, write: true },
};

const definition = {
  secret: "required|min:100",
  "users.*.addresses.*.city": "required",
  "permissons.read": "required|boolean",
  "permissons.delete": "required|boolean",
};

const result = await validate(data, definition);
console.log(result);

And this is the content of the result variable:

{
  "isValid": false,
  "isInvalid": true,
  "fields": {
    "secret": false,
    "users.*.addresses.*.city": false,
    "permissons.read": true,
    "permissons.delete": false
  },
  "errors": {
    "secret": [{ "rule": "min", "message": "The field must be at least 100." }],
    "users.1.addresses.1.city": [
      { "rule": "required", "message": "The field is required." }
    ],
    "permissons.delete": [
      { "rule": "required", "message": "The field is required." }
    ]
  }
}

Contributors

Made with contrib.rocks.

License

MIT License

About

Rule-based data validation library in Node.js

validator.axe-api.com

Topics

nodejsvalidate-formvalidate-jsvalidate-using-javascriptvalidatejsvalidatervalidationvalidation-libraryvalidatorvalidatorjs

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

25 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.