controls-spec
v0.0.1
Published
JSON specification and validation for control interfaces.
Downloads
11
Maintainers
Readme
Controls Specification
JSON specification and validator for control interfaces.
Installation
$ npm install controls-spec
Usage
var validate = require( 'controls-spec' );
validate( config )
Validates if a configuration object conforms to the specification for .
var config = {
"name": "Width",
"id": 0,
"type":"slider",
"min": 400,
"max": 800,
"step":10,
}
var isValid = validate( config );
// returns true
validate.errors
An array
of errors from the most recent validation. If no errors occurred during validation, the list is null
.
var errs = validate.errors;
Examples
var validate = require( 'controls-spec' ),
goodConfig,
badConfig,
isValid;
// Load in our contol interface configurations...
goodConfig = require( './good.json' );
/*
{
"id": 0,
"type":"slider",
"max": 10,
"min": 0,
"step":1
}
*/
badConfig = require( './bad.json' );
/*
{
"id": 0,
"type":"slider",
"min":"wrong",
"max":1
}
*/
// Validate:
isValid = validate( goodConfig );
// returns true
isValid = validate( badConfig );
// returns false
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. The Compute.io Authors.