-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(semantic-release): Use semantic release
BREAKING CHANGE: The code has been refactord to take advantage of es6 features only available in node6 or higher.
- Loading branch information
Showing
7 changed files
with
162 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "script" | ||
}, | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"brace-style": ["error", "stroustrup"], | ||
"max-len": ["warn", { | ||
"code": 100, | ||
"comments": 80, | ||
"ignoreUrls": true, | ||
"ignorePattern": "(logger\\.|new Error\\)|new TypeError\\()", | ||
"ignoreTrailingComments": true, | ||
"tabWidth": 2 | ||
}], | ||
"no-warning-comments": "warn", | ||
"quotes": ["error", "single", {"avoidEscape": true, "allowTemplateLiterals": true}], | ||
"require-jsdoc": ["error", { | ||
"require": { | ||
"FunctionDeclaration": true, | ||
"MethodDefinition": true, | ||
"ClassDeclaration": true | ||
} | ||
}], | ||
"valid-jsdoc": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
sudo: false | ||
language: node_js | ||
cache: | ||
directories: | ||
- node_modules | ||
notifications: | ||
email: false | ||
node_js: | ||
- "0.12" | ||
- "4" | ||
- "node" | ||
- '6' | ||
- 'node' | ||
before_install: | ||
- npm i -g npm@^2.0.0 | ||
before_script: | ||
- npm prune | ||
script: npm run lint && npm t | ||
after_success: npm run coveralls | ||
after_success: | ||
- npm run coveralls | ||
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all' | ||
- python travis_after_all.py | ||
- export $(cat .to_export_back) &> /dev/null | ||
- npm run semantic-release | ||
branches: | ||
except: | ||
- /^v\d+\.\d+\.\d+$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,69 @@ | ||
var Ajv = require('ajv'); | ||
var ajv = new Ajv({allErrors: true, verbose: true}) | ||
'use strict'; | ||
|
||
/** | ||
* Validator class with an optional JSON API schema. | ||
* | ||
* @param {*} schema | ||
* (optional) An object, or path relative to __dirname for a valid JSON API | ||
* schema. If one is not provided ./schema.json will be used. | ||
*/ | ||
var Validator = function (schema) { | ||
if (typeof schema === 'undefined') { | ||
schema = require('./schema.json'); | ||
} | ||
const defaultSchema = require('./schema.json'); | ||
const Ajv = require('ajv'); | ||
|
||
this._validate = ajv.compile(schema); | ||
}; | ||
const ajv = new Ajv({ allErrors: true, verbose: true }); | ||
|
||
/** | ||
* Validation method. | ||
* | ||
* @param {object} doc | ||
* A JavaScript object to validate against JSON API. | ||
* | ||
* @throws {Error} | ||
* Thrown if the document is not valid json. An additional element, errors, | ||
* is added to the error object that lists the problems encountered. | ||
* Validator class with an optional JSON API schema. | ||
* @class | ||
*/ | ||
Validator.prototype.validate = function (doc) { | ||
var valid = this._validate(doc); | ||
if (!valid) { | ||
var e = new Error('Invalid JSON API.'); | ||
e.errors = this._validate.errors; | ||
throw e; | ||
class Validator { | ||
/** | ||
* @constructor | ||
* | ||
* @param {*} schema | ||
* (optional) An object, or path relative to __dirname for a valid JSON API | ||
* schema. If one is not provided ./schema.json will be used. | ||
*/ | ||
constructor(schema = defaultSchema) { | ||
this.validator = ajv.compile(schema); | ||
} | ||
}; | ||
|
||
/** | ||
* Boolean validation method. | ||
* | ||
* @param {object} doc | ||
* A JavaScript object to validate against JSON API. | ||
* | ||
* @return {boolean} | ||
* true if the document is valid, else false. | ||
*/ | ||
Validator.prototype.isValid = function (doc) { | ||
try { | ||
this.validate(doc); | ||
} catch (e) { | ||
return false; | ||
/** | ||
* Validation method. | ||
* | ||
* @param {object} doc | ||
* A JavaScript object to validate against JSON API. | ||
* | ||
* @return {undefined} | ||
* | ||
* @throws {Error} | ||
* Thrown if the document is not valid json. An additional element, errors, | ||
* is added to the error object that lists the problems encountered. | ||
*/ | ||
validate(doc) { | ||
const valid = this.validator(doc); | ||
if (!valid) { | ||
const e = new Error('Invalid JSON API.'); | ||
e.errors = this.validator.errors; | ||
throw e; | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
/** | ||
* Boolean validation method. | ||
* | ||
* @param {object} doc | ||
* A JavaScript object to validate against JSON API. | ||
* | ||
* @return {boolean} | ||
* true if the document is valid, else false. | ||
*/ | ||
isValid(doc) { | ||
try { | ||
this.validate(doc); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
module.exports = { | ||
Validator: Validator | ||
Validator, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.