vtypes-objectof
"objectOf" validation for validate.js
About
The objectOf
validator attempts to make sure that the value of all keys
in an object conforms to the predefined format.
Installation
Using npm:
$ npm i --save vtypes-objectof
const validate = ;const objectOf = ; // you can then proceed to register the required validators.validatevalidatorsobjectOf = objectOf;
Usage
;// => undefined ;// => undefined
const value = attr: a: '' b: 't2' ; const constraints = attr: objectof: contains: presence: true length: is: 3 ; ;// {// attr: {// _message: '^One or more object values for value is not valid',// a: [// 'A can\'t be blank',// 'A is the wrong length (should be 3 characters)'// ],// b: [// 'B is the wrong length (should be 3 characters)'// ]// }// };
For more examples, check out the test files in this package's source folder.
Available Options
name | type | default | description |
---|---|---|---|
formatter | function | (v) => v |
Allows processing of errors before it returns |
message | string | ^One or more object values for %{key} is not valid |
Error message |
messageKey | string | _message |
key in return object for the summary message |
notObject | string | %{key} is not of type object |
Error when value is not an object |
License
vtypes-objectof
is MIT licensed