Use case: I have an http request represented by an object and I want to check the fields of the object before I make an http call with the request(i.e. makeHttpCall(request)). For example, given the object below:
{ "classic": false, "billing-account": "1234567890", "device": "123456" } I want to validate the following fields from the object:
- "classic" is a bool true/false
- "billing-account" is a string with length 9
- "device" value is a string with length 6
I want to be able to write a config that can be used to validate the fields, similar PropTypes or Formik. For example:
{ "classic": boolean "billing-account": string.length===9 "device": string.length===9 } UPDATE: yup is what I was looking for https://github.com/jquense/yup
classic: x => typeof x === "boolean". Next you can iterate over the keys and pass the values to the validator functions.