Want to see pretty graphs? Log in now!
npm install kommissar
|32||downloads in the last week|
|59||downloads in the last month|
|Last Published By|
|Version||1.0.15 last updated 5 months ago|
|Dependencies||underscore, async, hashish|
Kommissar is hybrid Validation Framework for the client and the node.js server. The validation rules can be reused.
This guarantees a consistency in client side validation and security validation of the untrusted user data.
validations are the methods used for validations. Kommissar provides
basic methods like
You can find the complete list of available methods at node-validator.
If you want to add custom rules the signature of the functions is the following
customRule = (objectToValidate, parameter0, ..., parameterN)
which should return a boolean value
userRule = (check) # simple rule check('email').isEmail() # optional error messages are supported check('password', 'Your Password is too short.').len 8 # rule are chainable check('string').len(8,64).isAlpha() # check if a field is valid in dependency on another field # this rule makes sense if the user wants to edit its # profile and the rule has to check if *no other* user # has this email check.('email').isUnique().with('id')
Rules should be stored in a single file that is made available to the server and the client.
All available validation methods are imported from node-validator. You can have a look at the available validations.
If you want to use custom validations, just extend
enable middleware validation (server)
app.post '/route', kommissar.middleware() userRule, updateModelWithNewDataMiddleware
This will only process
updateModelWithNewDataMiddleware if the validation
userRule with the body was successful.
The signature of
kommissar.middleware = (validations, failureMiddleware, successMiddleware)
validations are the available validations.
The default option is to use the validations from
If you want to extend the available validations with custom one, you can use
failureMiddleware is the middleware that gets executed if the verification
failed. On default this returns a
Bad Request Status Code.
successCallback is executed if the verification was successful. On default
this continues with the next middleware. In the example this would be the
enable middleware in the client
form = $ '#form' kommissar.clientValidate form, validations, rule, callback
Enables the form
#form for the validation.
The validation is executed if the user presses the submit button.
After the validation is finished the callback is called with the results.
The callback has to decide what to do.
An example callback can be found in
callback is optimized to print the error messages next to the form in an
vanilla bootstrap page.
The rules need to allow asynchronous validation. For example checking the avalability of an username on the client is asynchronous. Thus a validation framework has to deal with asynchron validation
A Validation framework should be decoupled to allow unit testing. It should be easy to unit test the rules. This framework should not force the user to implement the validation process in a specific way.
Easy to use
Writting rules should be fast and easy.
Default Validators (like
len) should be available by default.
It should also be easy to drop in custom rules (like