Alinex Validator: Readme

GitHub watchers GitHub stars GitHub forks

npm package latest version Travis status Coveralls status Gemnasium status GitHub issues

This module will help validating complex structures. And should be used on all external information.

  • check value against configuration
  • easy checking of values and complex structures
  • in detail checks for different data types
  • can give a human readable description
  • also supports dependency checks within the structure
  • usable for value formating, too

The validation rules are really simple, but they will get more complex as your data structure gains complexity. But if you know the basic rules it’s all a composition of some simple structures. Like you will see below.

This library can help you make your life secure and easy but you have to run every external data through it using a detailed data description. If you do so you can trust and use the values as they are without further checks. And you’ll get the benefit of automatically optimized values like for handlebars type you get a ready to use handlebar function back.

It is one of the modules of the Alinex Namespace following the code standards defined in the General Docs.

Install

NPM Downloads

The easiest way is to let npm add the module directly to your modules (from within you node modules directory):

Shell Script
npm install alinex-validator --save

And update it to the latest version later:

Shell Script
npm update alinex-validator --save

Always have a look at the latest changes in theVersion changes

Usage

This library is implemented completely asynchronous, to allow io based checks and references within the structure.

To use the validator you have to first include it:

CoffeeScript Code
validator = require 'alinex-validator'

The main method will validate and sanitize the value or value structure:

CoffeeScript Code
validator.check name: 'test' # name to be displayed in errors (optional) value: input # value to check schema: schema # definition of checks context: null # additional data (optional) , (err, result) -> # do something

The checks are completely asynchronous because they may contain some IO checks.

To get a human readable description call:

CoffeeScript Code
message = validator.describe name: 'test' # name to be displayed in errors (optional) schema: schema # definition of checks , (err, text) -> # do something

This will get the description un markdown format.

Within your tests you may check your schema configurations:

CoffeeScript Code
validator.selfcheck name: 'test' # name to be displayed in errors schema: schema # definition to check , (err) -> # do something

Debugging

If you have any problems you may debug the code with the predefined flags. It uses the debug module to let you define what to debug.

Call it with the DEBUG environment variable set to the types you want to debug. The most valueable flags will be:

DEBUG=validator           # general information and checking schema
DEBUG=validator:array     # to check the array type validation
DEBUG=validator:reference # to check the reference resolving

You can also combine them using comma or use only DEBUG=* to show all.

Additional value checking will be done if the debugging for the general validator is enabled.

License

© Copyright 2014-2016 Alexander Schilling

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.