validate
validate
is a function that returns a validator function
. validator function
is used to validate data and to provide the correct type of the data.
validate
#
Parsing behaviour of @typeofweb/schema
comes with a default set of sane coercion rules, meaning some of the most common scenarioes are covered out of the box!
#
Example#
Numeric strings are converted to numbersSometimes, numbers are passed as strings i.e. in query strings. We found out this kind of scenario is very common and thus we automatically convert numeric strings to numbers.
#
Dates get stringifiedDate
instances#
Date strings are converted to JSON format doesn't support Date instances and usually strings in ISO 8601 format are used instead. We thought it makes sense to automatically convert them to proper Date
instances.