1.0.0 • Published 6 years ago
@tombanksme/validator v1.0.0
Validator
Welcome Developer,
This project is a basic data validator written in Typescript. Please be aware that this project is a work in progress and should not be used in any production environment. I highly suggest that you look into alternative data validators.
Installation
npm install @tombanksme/validator
Basic usage
import { Validator } from "@tombanksme/validator"
let v = new Validator ({
email : "thomas@tombanks.me"
} , {
email : [ "required" ]
});
if ( v.fails () ) {
console.log ( v.errors () ); }
Building your own rules
import { Validator , Rule } from "@tombanksme/validator";
class TestRule extends Rule
{
passes ( value : any ) : boolean
{
return value === "TestRule";
}
message ( attr : string ) : string
{
return `${attr} did not pass the rule TestRule`;
}
}
let v = new Validator ({
email : "TestRule",
} , {
email : [ new TestRule () ],
});
if ( v.fails () ) {
console.log ( v.errors () ); }
1.0.0
6 years ago