Skip to content

sebdoucet/aster-js-validation

 
 

Repository files navigation

@aster-js/validation Node.js Package

Fluent validation library inspired by the fluent validation library from .NET.

Usage

We will take the following model as a sample:

type MyModel = {
    readonly id: number,
    readonly name: string,
    readonly value: any;
};

Validator declaration

import { Validator, Validate } from "@aster-js/validation";

const myModelValidator = Validator.create<MyModel>(expect => {

    expect("id").toBeNumber({ min: 0 }).orFail("id must be a number greater than 0");

    expect("name").toBeString({ minLength: 5, maxLength: 20 }).orFail("name must have more than 5 chars and less than 20");

    expect("value").toBeDefined().orFail("value must be defined");

});

Validator usage

const model = { id: 0, name: "Joe", value: null };
const validationResult = myModelValidator.validate(model);

if(validationResult.type === "failed") {
    console.debug(validationResult.errors);
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 94.9%
  • JavaScript 5.1%