npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kommissar

v1.0.15

Published

Kommissar =========

Downloads

8

Readme

Kommissar

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.

Example

I uploaded a working example. Have a look.

validations

validations are the methods used for validations. Kommissar provides basic methods like isInt, isEmail, len, min, max, ...

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

rules

Example rule

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 kommissar.validation:

enable middleware validation (server)

app.post '/route',
    kommissar.middleware() userRule,
    updateModelWithNewDataMiddleware

This will only process updateModelWithNewDataMiddleware if the validation of userRule with the body was successful.

The signature of kommissar.middleware is

kommissar.middleware = (validations, failureMiddleware, successMiddleware)

validations are the available validations. The default option is to use the validations from kommissar.validations. If you want to extend the available validations with custom one, you can use this option.

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 updateModelWithNewDataMiddleware

enable middleware in the client

It is required that this module with all requirements is available for the client. In the example browserify is used.

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 kommissar.bootstrapDefault, this callback is optimized to print the error messages next to the form in an vanilla bootstrap page.

Concept

Asynchron Validation

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

Isolation

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.

Basic Rules

Default Validators (like isInt, len) should be available by default. It should also be easy to drop in custom rules (like isUsernameTaken).