har-validator
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"name": "har-validator", | ||
"description": "Extremely fast HTTP Archive (HAR) validator using JSON Schema", | ||
"author": "Ahmad Nassri <ahmad@ahmadnassri.com> (https://www.ahmadnassri.com/)", | ||
"homepage": "https://github.com/ahmadnassri/har-validator", | ||
"license": "MIT", | ||
"main": "./src/index.js", | ||
"bin": "./bin/har-validator", | ||
"keywords": [ | ||
"har", | ||
"http", | ||
"archive", | ||
"validate", | ||
"validator" | ||
], | ||
"engines": { | ||
"node": "0.10.x", | ||
"npm": "1.4.x" | ||
"node": ">=0.10" | ||
}, | ||
"files": [ | ||
"bin", | ||
"src" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ahmadnassri/har-validator.git" | ||
"url": "https://github.com/ahmadnassri/har-validator" | ||
}, | ||
@@ -20,19 +31,23 @@ "bugs": { | ||
}, | ||
"keywords": [ | ||
"HAR", | ||
"HTTP", | ||
"Archive" | ||
], | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "standard && mocha --reporter spec", | ||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha", | ||
"codeclimate": "codeclimate < coverage/lcov.info" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.1.0", | ||
"should": "^5.0.1" | ||
"codeclimate-test-reporter": "0.0.4", | ||
"istanbul": "^0.3.8", | ||
"mocha": "^2.2.1", | ||
"should": "^5.2.0", | ||
"standard": "^3.2.0" | ||
}, | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"bluebird": "^2.9.14", | ||
"chalk": "^1.0.0", | ||
"commander": "^2.6.0", | ||
"is-my-json-valid": "^2.9.4" | ||
"commander": "^2.7.1", | ||
"debug": "^2.1.3", | ||
"is-my-json-valid": "^2.10.0", | ||
"require-directory": "^2.1.0" | ||
} | ||
} |
307
README.md
@@ -7,10 +7,14 @@ # HAR Validator [![version][npm-version]][npm-url] [![License][npm-license]][license-url] | ||
[![Downloads][npm-downloads]][npm-url] | ||
[![Code Climate][codeclimate-quality]][codeclimate-url] | ||
[![Coverage Status][codeclimate-coverage]][codeclimate-url] | ||
[![Dependencies][david-image]][david-url] | ||
## Installation | ||
## Install | ||
install from source or through [npm](https://www.npmjs.com/): | ||
```shell | ||
# to use in cli | ||
npm install --global har-validator | ||
# to use as a module | ||
npm install --save har-validator | ||
``` | ||
@@ -20,12 +24,12 @@ | ||
### CLI | ||
``` | ||
Usage: har-validator <file ...> | ||
Usage: har-validator [options] <files ...> | ||
Options: | ||
-h, --help output usage information | ||
-V, --version output the version number | ||
-s, --schema [request | response] validate sub schema | ||
-h, --help output usage information | ||
-V, --version output the version number | ||
-s, --schema [name] validate schema name (log, request, response, etc ...) | ||
``` | ||
@@ -35,61 +39,272 @@ | ||
```shell | ||
har-validator ./path/to/har.json | ||
har-validator har.json | ||
har-validator --schema ./path/to/request.json | ||
har-validator --schema request request.json | ||
``` | ||
### Code | ||
## API | ||
Include the module in your code and use directly or with any of the utility methods to validate sub-schemas: | ||
### Validate(data [, callback]) | ||
| method | description | | ||
| ------------- | --------------------------------------------------------------------------------------------------------- | | ||
| `cache` | validates a [cache](http://www.softwareishard.com/blog/har-12-spec/#cache) object | | ||
| `cacheEntry` | validates a ["beforeRequest" or "afterRequest"](http://www.softwareishard.com/blog/har-12-spec/#cache) objects | | ||
| `content` | validates a [content](http://www.softwareishard.com/blog/har-12-spec/#content) object | | ||
| `cookie` | validates a [cookie](http://www.softwareishard.com/blog/har-12-spec/#cookies) object | | ||
| `creator` | validates a [creator](http://www.softwareishard.com/blog/har-12-spec/#creator) object | | ||
| `entry` | validates a [entry](http://www.softwareishard.com/blog/har-12-spec/#entries) object | | ||
| `log` | validates a [log](http://www.softwareishard.com/blog/har-12-spec/#log) object | | ||
| `page` | validates a [page](http://www.softwareishard.com/blog/har-12-spec/#pages) object | | ||
| `pageTimings` | validates a [pageTimings](http://www.softwareishard.com/blog/har-12-spec/#pageTimings) object | | ||
| `postData` | validates a [postData](http://www.softwareishard.com/blog/har-12-spec/#postData) object | | ||
| `record` | validates a [record](http://www.softwareishard.com/blog/har-12-spec/#headers) object | | ||
| `request` | validates a [request](http://www.softwareishard.com/blog/har-12-spec/#request) object | | ||
| `response` | validates a [response](http://www.softwareishard.com/blog/har-12-spec/#response) object | | ||
| `timings` | validates a [timings](http://www.softwareishard.com/blog/har-12-spec/#timings) object | | ||
Returns `true` or `false`. | ||
###### Example | ||
- **data**: `Object` *(Required)* | ||
a [log](http://www.softwareishard.com/blog/har-12-spec/#log) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var HAR = require('har.json'); | ||
var HAR = require('./har.json'); | ||
var validate = require('har-validator'); | ||
validate(HAR, function (err, valid) { | ||
if (err) console.log(err) | ||
validate(HAR, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
if (valid) { | ||
console.log('horray!'); | ||
} | ||
if (valid) console.log('horray!'); | ||
}); | ||
``` | ||
### Validate.cache(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [cache](http://www.softwareishard.com/blog/har-12-spec/#cache) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var request = require('request.json'); | ||
var validate = require('har-validator'); | ||
validate(request, function (err, valid) { | ||
if (err) console.log(err) | ||
validate.cache(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
if (valid) { | ||
console.log('horray!'); | ||
} | ||
### Validate.cacheEntry(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a ["beforeRequest" or "afterRequest"](http://www.softwareishard.com/blog/har-12-spec/#cache) objects | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.cacheEntry(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.content(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [content](http://www.softwareishard.com/blog/har-12-spec/#content) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.content(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.cookie(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [cookie](http://www.softwareishard.com/blog/har-12-spec/#cookies) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.cookie(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.creator(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [creator](http://www.softwareishard.com/blog/har-12-spec/#creator) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.creator(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.entry(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [entry](http://www.softwareishard.com/blog/har-12-spec/#entries) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.entry(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.log(data [, callback]) | ||
alias of [`Validate(data [, callback])`](#validate-data-callback-) | ||
### Validate.page(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [page](http://www.softwareishard.com/blog/har-12-spec/#pages) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.page(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.pageTimings(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [pageTimings](http://www.softwareishard.com/blog/har-12-spec/#pageTimings) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.pageTimings(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.postData(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [postData](http://www.softwareishard.com/blog/har-12-spec/#postData) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.postData(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.record(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [record](http://www.softwareishard.com/blog/har-12-spec/#headers) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.record(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.request(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [request](http://www.softwareishard.com/blog/har-12-spec/#request) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.request(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.response(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [response](http://www.softwareishard.com/blog/har-12-spec/#response) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.cacheEntry(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
### Validate.timings(data [, callback]) | ||
Returns `true` or `false`. | ||
- **data**: `Object` *(Required)* | ||
a [timings](http://www.softwareishard.com/blog/har-12-spec/#timings) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
validate.timings(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
``` | ||
## License | ||
Licensed under [The MIT License](LICENSE). | ||
[MIT](LICENSE) © [Ahmad Nassri](https://www.ahmadnassri.com) | ||
@@ -106,3 +321,7 @@ [license-url]: https://github.com/ahmadnassri/har-validator/blob/master/LICENSE | ||
[codeclimate-url]: https://codeclimate.com/github/ahmadnassri/har-validator | ||
[codeclimate-quality]: https://img.shields.io/codeclimate/github/ahmadnassri/har-validator.svg?style=flat-square | ||
[codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/ahmadnassri/har-validator.svg?style=flat-square | ||
[david-url]: https://david-dm.org/ahmadnassri/har-validator | ||
[david-image]: https://img.shields.io/david/ahmadnassri/har-validator.svg?style=flat-square |
@@ -1,34 +0,45 @@ | ||
'use strict'; | ||
'use strict' | ||
var validator = require('is-my-json-valid'); | ||
var schemas = require('./schemas.json'); | ||
var validator = require('is-my-json-valid') | ||
var schemas = require('./schemas.json') | ||
function ValidationError (errors) { | ||
this.name = 'ValidationError' | ||
this.errors = errors | ||
} | ||
ValidationError.prototype = Error.prototype | ||
var runner = function (schema, data, cb) { | ||
var validate = validator(schema, { | ||
schemas: schemas | ||
}); | ||
}) | ||
var valid = false; | ||
var valid = false | ||
if (data !== undefined) { | ||
// execute is-my-json-valid | ||
valid = validate(data); | ||
valid = validate(data) | ||
} | ||
// callback? | ||
if (cb) { | ||
return cb(validate.errors, valid); | ||
if (!cb) { | ||
if (validate.errors) { | ||
throw new ValidationError(validate.errors) | ||
} | ||
} else { | ||
return cb(validate.errors ? new ValidationError(validate.errors) : null, valid) | ||
} | ||
return valid; | ||
}; | ||
return valid | ||
} | ||
module.exports = function (data, cb) { | ||
return runner(schemas.log, data, cb); | ||
}; | ||
return runner(schemas.log, data, cb) | ||
} | ||
Object.keys(schemas).map(function (name) { | ||
module.exports[name] = function (data, cb) { | ||
return runner(schemas[name], data, cb); | ||
}; | ||
}); | ||
return runner(schemas[name], data, cb) | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
324
18398
7
5
6
244
1
+ Addedasync@^0.9.0
+ Addedbluebird@^2.9.14
+ Addeddebug@^2.1.3
+ Addedrequire-directory@^2.1.0
+ Addedasync@0.9.2(transitive)
+ Addedbluebird@2.11.0(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
Updatedcommander@^2.7.1
Updatedis-my-json-valid@^2.10.0