Package Exports
- composite-validation
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (composite-validation) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
composite-validation
Composite validation API for JS data models. Based on this project idea. This library
Install
npm install composite-validation
Use
For some data model...
const dataModel = {
name: 'Leonardo',
age: 45
};
...describe validation map that folows the structure of the original object.
import { ValidationMap, Conditions, required, equals } from 'composite-validation';
const map = ValidationMap({
name: Conditions(v => required(v)),
age: Conditions([
v => required(v),
v => equals(v, 21)
])
});
Call function.
const result = map(dataModel);
Function applies validation map to data model, check all validity conditions and returns object with validity states for each field.
{
"name": {
"value": "Leonardo",
"isRequired": true
},
"age": {
"error": "Value should be defined",
"isRequired": true
}
}