Upgrading from 5.x
Following this guide, if you are using
email@example.com and wants to upgrade to the latest version.
The package is re-written from scratch with focus on better UX for Typescript users and performance.
- Indicative now uses a dedicated parser and compiler to parse the schema objects and cache them for performance. This roughly makes Indicative 4x faster from it's predecessor.
- Instead of defining validation rules as a string, one can use the
validationsobject, which works great with Typescript intellisense.
Removing browser support
The newer version of Indicative doesn't have first class support for browsers. Most of my work is targeted towards the Node.js audience, and it is really hard for me to build and maintain Isomorphic packages.
I am not a fulltime frontend engineer and things like finding right babel plugins, keeping bundle size in control, integrating tests with tools browserstack adds a lot to the development time.
However, I am open for the community to standup and work towards making Indicative compatible with browsers.
Changes to import paths
We have scoped the
sanitizer API to subpaths and that introduces minor changes to the imports API.
We have removed the
rule method in favor of
sanitizations objects. The newer API works great with Typescript intellisense, and you won't have to remember the rules name anymore.
The validator API stays intact for the most part, except the options argument signature has been changed as described below.
Changes to options argument
fourth argument used to receive an optional
formatter. Now it receives an object with following properties.
options argument and all of it's internal keys are optional.
All of the validator rules behaves the same, except some of the rules now have inbuilt data casting. The inbuilt data casting solves lot of edge cases. For example:
- You want a certain value to be a valid
- Since the data transfered over HTTP is always string, you make use of
- The date was invalid and hence the sanitization rule converted it to
- Now, the validator will see the
nullvalue and returns the required validation error message vs invalid date error message to the user.
Following rules will perform implicit data casting.
Since the data casting is now inbuilt within the validator, we have removed type conversion sanitization rules.
sanitizer.toDatein favor of validator.date
sanitizer.toIntin favor of validator.integer
sanitizer.toBooleanin favor of validator.date
We have introduced a dedicated
extend method for
sanitizer both. It will add your new rules to the runtime engine as well as to the list of
Along with that, the API for the custom validation and sanitization rules have been changed.
extendmethod expect you to define whether the
validatemethod is async or not, this helps in optimizing the runtime. Learn more
validatemethod doesn't receive the
messageanymore, since returning correct message is not the responsibility of the rule.
validatedoesn't receive the
getmethod anymore and instead you are required to import
- The return value from the
validatemethod has to be a boolean. Earlier you were supposed to throw an exception, which has severe impact on runtime performance.
- Finally, the validator config is passed to all the rules, so that they can use the config to tweak the behavior.