controls-spec v0.0.1
Controls Specification
JSON specification and validator for control interfaces.
Installation
$ npm install controls-specUsage
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 truevalidate.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 falseTo run the example code from the top-level application directory,
$ node ./examples/index.jsTests
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 testAll 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-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covLicense
Copyright
Copyright © 2015. The Compute.io Authors.