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

node-form

v1.0.18

Published

form validation engine

Downloads

57

Readme

Form validation module

logo

Validation module is a lightweight JavaScript library for easy business rules definition of the product, the contract, the form etc.

[Tutorial] (https://github.com/rsamec/form/wiki)

Key features

The main benefit is that validation engine is not tight to HTML DOM or any other UI framework. This validation engine is UI agnostic and that is why it can be used as an independent representation of business rules of a product, contract, etc. It can be easily reused by different types of applications, libraries.

  • It enables to decorate custom objects and its properties with validation rules.
  • It supports composition of validation rules, that enables to validate custom object with nested structures.
  • It is ease to create your own custom validators.
  • It supports asynchronous validation rules (uses promises).
  • It supports shared validation rules.
  • It supports assigning validation rules to collection-based structures - arrays and lists.
  • It supports localization of error messages with TranslateArgs.
  • It deploys as AMD, CommonJS or plain script module pattern.
  • It offers basic build-in constrains validators. Other custom validators can be find in extensible repository of custom validators (work in progress).

Installation

This module is installed:

  • Node.js
  • npm install node-form
  • use require('node-form');
  • Bower
  • bower install form
  • Require.js - require(["form/amd/Validation"], ...
  • Script tag -> add reference to dist/module/Validation.js file.

Example Usage

To define business rules for some object, you have to create abstract validator.

          //create new validator for object with structure<IPerson>
          var personValidator = new Validation.AbstractValidator();

          //basic validators
          var required =new Validators.RequiredValidator();
          var maxLength = new Validators.MaxLengthValidator(15);

          //assigned validators to property
          personValidator.RuleFor("FirstName", required);
          personValidator.RuleFor("FirstName",maxLength);

          //assigned validators to property
          personValidator.RuleFor("LastName", required);
          personValidator.RuleFor("LastName",maxLength);

To use business rules and execute them on particular data

          //create test data
          var data = {
                Person1:
                {
                    FirstName:'John',
                    LastName: 'Smith'
                },
                Person2:{}

          }

          //create concrete rule
          var person1Validator = personValidator.CreateRule("Person 1");

          //execute validation
          var result = person1Validator.Validate(this.Data.Person1);

          //verify results
          if (result.HasErrors){
              console.log(result.ErrorMessage);
          }
          //---------
          //--outputs
          //---------

          //create concrete rule
          var person2Validator = personValidator.CreateRule("Person 2");

          //execute validation
          var result = person2Validator.Validate(this.Data.Person1);

           //verify results
          if (result.HasErrors){
              console.log(result.ErrorMessage);
          }

          //---------
          //--outputs
          //---------
          // FirstName: Field is required.
          // LastName: Field is required.

Source code

All code is written in typescript.

npm install -g typescript

To compile to javascript.

tsc src/validation/Validation.ts --target ES5 --module:commonjs

Tests

npm install -g mocha
npm install -g expect.js

To run tests

mocha test

Grunt automatization

To build all sources to dist folder (generates AMD, CommonJS and module pattern)

$ grunt dist

To run code analyze - complexity + jshint.

$ grunt ci

To generate api documentation.

$ grunt document

To generate typings -> typescript definition files.

$ grunt typings

To run tests

$ grunt test

Roadmap

  • Add validation groups to shared validation rules
  • Separate ValidationResult from execution of validation rules
  • Add depedency injection for managing dependencies among components