1.0.4 • Published 3 years ago
@aster-js/validation v1.0.4
@aster-js/validation
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);
}
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago
1.0.0-beta.4
3 years ago
1.0.0-beta.3
3 years ago
1.0.0-beta.2
3 years ago
1.0.0-beta.1
3 years ago