This library is intended to facilitate the isolation of validation rules, and to ensure high validation code reuse rate.
Targets
Create Rules
Reuse Rules
Ensure uniform code
Framework Agnostic (functional api)
Install
$ npm install -save light-validate
$ npm install -save reflect-metadata
Development and Implementation - Creating Validation Rules (light-rules) ...
Define a mapping to the object that will be processed, requiring the class to follow the data model agreement (interface).
The rule must implement the 'LightRule' class/interface.
Beginning with version 1.0.2, the LightRule interface is given an optional last parameter, which has its value equivalent to the target object to be validated if you need to create a Rule that depends on a second value of the target object.
Development and Implementation - Creating Mapping (Classes / Types) ...
Important !!!
All properties will be decorated with decorator validate, must be initialized with 'undefined' in the class definition, otherwise validation will not work.
username:string=undefined;// all properties decorated with @LightValidate must be initialized with undefined on mapping class, otherwise, validation will not work with the property
name:string=undefined;// all properties decorated with @LightValidate must be initialized with undefined on mapping class, otherwise, validation will not work with the property
document:string=undefined;// all properties decorated with @LightValidate must be initialized with 'undefined' on mapping class, otherwise, validation will not work with the property
}
Development and Implementation - Validation Call ...