A tool to validate your inputs in a visualy pleasing and flexible way.

Usage no npm install needed!

<script type="module">
  import validationChainer from '';


Validation Chainer

A tool to validate your inputs in a visualy pleasing and flexible way.



With npm:

npm install validation-chainer

With yarn:

yarn add validation-chainer


Basic Usage:

import { startChain } from "validation-chainer";

const data = {
    foo: "yes",
    bar: "PLEASE",

// starts the chain with the data
// await is used here because pack returns a promise
const errors = await startChain(data)
    // starts check on foo
    // does some validation with the property foo (foo's value is used as an argument)
    .validate((foo) => foo typeof "string", "Foo is not a string")
    .validate((foo) => foo.length >= 8, "Foo must be at least 8 characters")

    // makes bar lower case (modifies the object getting passed in) so bar is now please
    .sanitize((bar) => bar.toLowerCase())
    .validate((bar) => bar == "please")

    // make sure to call this!

// check to see if there are any errors
if (errors.length > 0)
    // there should only be one error

Logs in console:

        property: "foo",
        message: "Foo must be at least 8 characters",

Login verify example:

import { startChain } from "validation-chainer";
import argon2 from "argon2";

const data = {
    username: "bob",
    password: "very strong password",

const user = await database.findOne({ username: data.username });

const errors = await startChain(data)
    .validate(() => user != null, "Username doesn't exist")

    // makes sure username is valid first
    .ensure("username", "Username is invalid")
    // checks password using asynchronous hashing algorithm
        async (storedPass) => await argon2.verify(storedPass, user.password),
        "Password is incorrect"


Using the validator library:

import { startChain } from "validation-chainer";
import validator from "validator";

const data = {
    name: "                 💩      ",

const errors = await startChain(data)
    // removes whitespace at the beggining and end of name so it's now just "💩"
    // property fails here because of the 💩
    .validate(validator.isAlphaNumeric, "Name must contain valid alpha-numeric characters")


Using TypeScript:

import { startChain } from "validation-chainer";

const data = {
    status: "sad",

// starts chain that's specialized with data
const errors = await startChain(data)
    // intilisense info on object
    // optional type generics on function (default is any)
    .validate<string>((status) => status === "happy", "Why are you not happy")
    .sanitize<string>((status) => status.toUpperCase())



The documentation is in the source code written in jsdoc (with typescript). IDE's like vscode will be able to show it while developing. There might be plans to convert it into markdown or html in the future.


Install packages first:

npm install

Change Code.

Do tests:

npm run test

Do linting:

npm run lint


npm run build