VisorJS
A Validation Framework.
Visorjs doesn't attempt to tell you what rules you have to make and what rules you have to follow. It comes with only with two rules required and notRequired
This allows you to use a different library like validator. This is a highly popular and tested library.
Usage
; // Extends this class v.validate //throws error
Best Practice
You only want to use a Validation instance once. So you will be creating a new one each time. Use extend to create Base Classes that has common validations that you want to run.
You can pass parameters to the function easily by adding params.
required notRequired
These two functions are very important. They allow you to do something very nice with validation.
Imaging this possibility.
This allows you to have a parameter that is missing. Like address, however if the address is present it forces certain elements to be required.
//Valid against the rule above //not valid missing number //valid
Config
The config allows a certain amount of flexibility. For example you can use these different combination in your rules.
//single string value that must be a method that accepts key and value "rulename" //multiple rules "rulename|other_rulename" //Array rule //function //mixture of string and arrays //passing parameters "rulename:arg1,arg2" //this will call the method with args as such
All other functions that are required will need to be created on your own.
Future
I plan on adding a different class that will have some basic validation.
Concepts
Rules are validated in the order that they are written. It fails on the first one.
Dependencies
This is simple. None.
Typescript
Hell yea!!!