alinex-validator
Data validator with additional sanitize of simple and complex values used as schema validation for any imported data structure.
Last updated 3 years ago by alinex .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install alinex-validator 
SYNC missed versions from official npm registry.

Alinex Validator

GitHub watchers GitHub stars GitHub forks

npm package latest version Travis status Codacy Badge Coverage status GitHub issues

The ultimate validation library for javascript!

This module will help validating complex structures. And should be used on all external information. Like configuration or user input. It's strength are very complex structures but as easily it works with simple things. It's the best validator ever, see the comparison with others later.

  • class based schema definitions
  • multiple predefined types
  • multiple options per type
  • check and transform values
  • specialized in deep and complex data structures
  • supports dependency checks with references
  • can give a human readable description
  • command line interface (cli)
  • including data loading
  • precompile JSON config for any system

The core builds a schema which is build as combination of different type instances from the schema classes. This schema builder mechanism allows to setup complex structures with optimizations and logical validation. It can be build step by step, cloned and redefined...

With such a schema you can directly validate your data structure or use it to load and validate data structure or to transform them into optimized JSON data files using the command line interface. A schema can also describe itself human readable for users to describe what is needed. If some value failed an error message is given with reference to the original value and the description what failed and what is needed.

This library can help you make your life secure and easy but you should have to define your data structure deeply, before. 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 and easy to use configuration files back.

You may also split up complex configuration files for any system into multiple files which are combined together by the validator after each change.

Read the complete documentation under https://alinex.gitbooks.io/validator

Usage

Install to use as module:

npm install alinex-validator

or install it globally:

npm install -g alinex-validator

Create Schema

Now you can define your schema specification like:

// config.schema.js

// @flow
import * as val from 'alinex-validator/dist/builder'

const schema = new val.Object()
  .key('title', new val.String().allow(['Dr.', 'Prof.']))
  .key('name', new val.String().min(3).required())
  .key('street', new val.String().min(3).required())
  .key('plz', new val.Number().required()
    .positive().max(99999)
    .format('00000'))
  .key('city', new val.String().required().min(3))

module.exports = schema

Validating using API

import validator from 'alinex-validator'

import schema from './config.schema.js'

validator.searchApp('myApp') // search in /etc/myApp or ~/.myApp
const data = validator.load('config/**/*.yml')

schema.validate(data)
  .then((data) => {
    console.log(data)
  })
  .catch((err) => {
    console.error(err.text())
  })

Use the CLI

Transform into an optimized JSON structure:

validator -i *.yml -s schema.js -o config.json

This will load all *.yml files in the current directory, validate it through the given schema and store the resulting data structure to a JSON file.

This can be used to validate and optimize a configuration before using them. If you want to use this in JavaScript you can use:

import config from './config.json'

Read more in the complete manual...

Changelog

V3.0.1 Bug fixes: file.exists, CLI calls

V3.0.0 Complete rewrite with class structure

License

(C) Copyright 2014-2017 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.

Current Tags

  • 3.0.1                                ...           latest (3 years ago)

72 Versions

  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.1.4                                ...           3 years ago
  • 2.1.3                                ...           3 years ago
  • 2.1.2                                ...           3 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.7                                ...           4 years ago
  • 2.0.6                                ...           4 years ago
  • 2.0.5                                ...           4 years ago
  • 2.0.4                                ...           4 years ago
  • 2.0.3                                ...           4 years ago
  • 2.0.2                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.6.6                                ...           4 years ago
  • 1.6.5                                ...           4 years ago
  • 1.6.4                                ...           4 years ago
  • 1.6.3                                ...           4 years ago
  • 1.6.2                                ...           4 years ago
  • 1.6.1                                ...           4 years ago
  • 1.6.0                                ...           4 years ago
  • 1.5.0                                ...           4 years ago
  • 1.4.6                                ...           4 years ago
  • 1.4.5                                ...           4 years ago
  • 1.4.4                                ...           4 years ago
  • 1.4.3                                ...           4 years ago
  • 1.4.2                                ...           4 years ago
  • 1.4.1                                ...           4 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.2                                ...           4 years ago
  • 1.3.1                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.4                                ...           4 years ago
  • 1.2.3                                ...           4 years ago
  • 1.2.2                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.3.15                                ...           5 years ago
  • 0.3.13                                ...           5 years ago
  • 0.3.12                                ...           5 years ago
  • 0.3.11                                ...           5 years ago
  • 0.3.10                                ...           5 years ago
  • 0.3.9                                ...           5 years ago
  • 0.3.8                                ...           5 years ago
  • 0.3.7                                ...           5 years ago
  • 0.3.6                                ...           5 years ago
  • 0.3.5                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.3                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.3                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (18)

Copyright 2014 - 2016 © taobao.org |