har-validator
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"name": "har-validator", | ||
@@ -4,0 +4,0 @@ "description": "Extremely fast HTTP Archive (HAR) validator using JSON Schema", |
298
README.md
@@ -45,26 +45,27 @@ # HAR Validator [![version][npm-version]][npm-url] [![License][npm-license]][license-url] | ||
### Validate(data [, callback]) | ||
**Note**: as of [`v2.0.0`](https://github.com/ahmadnassri/har-validator/releases/tag/v2.0.0) this module defaults to Promise based API. *For backward comptability with `v1.x` an [async/callback API](#callback-api) is provided* | ||
Returns `true` or `false`. | ||
### Validate(data) | ||
> Returns a promise that resolves to the valid object. | ||
- **data**: `Object` *(Required)* | ||
a full [HAR](http://www.softwareishard.com/blog/har-12-spec/) object | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var HAR = require('./har.json'); | ||
var validate = require('har-validator'); | ||
var HAR = require('./har.json') | ||
var validate = require('har-validator') | ||
validate(HAR, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
if (valid) console.log('horray!'); | ||
}); | ||
validate(HAR) | ||
.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.log(data [, callback]) | ||
### Validate.log(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -74,16 +75,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.log(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.log(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.cache(data [, callback]) | ||
### Validate.cache(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -93,16 +94,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.cache(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.cache(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.cacheEntry(data [, callback]) | ||
### Validate.cacheEntry(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -112,16 +113,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.cacheEntry(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.cacheEntry(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.content(data [, callback]) | ||
### Validate.content(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -131,16 +132,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.content(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.content(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.cookie(data [, callback]) | ||
### Validate.cookie(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -150,16 +151,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.cookie(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.cookie(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.creator(data [, callback]) | ||
### Validate.creator(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -169,16 +170,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.creator(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.creator(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.entry(data [, callback]) | ||
### Validate.entry(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -188,20 +189,20 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.entry(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.entry(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.log(data [, callback]) | ||
### Validate.log(data) | ||
alias of [`Validate(data [, callback])`](#validate-data-callback-) | ||
alias of [`Validate(data)`](#validate-data-callback-) | ||
### Validate.page(data [, callback]) | ||
### Validate.page(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -211,16 +212,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.page(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.page(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.pageTimings(data [, callback]) | ||
### Validate.pageTimings(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -230,16 +231,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.pageTimings(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.pageTimings(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.postData(data [, callback]) | ||
### Validate.postData(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -249,16 +250,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.postData(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.postData(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.record(data [, callback]) | ||
### Validate.record(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -268,16 +269,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.record(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.record(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.request(data [, callback]) | ||
### Validate.request(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -287,16 +288,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.request(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.request(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.response(data [, callback]) | ||
### Validate.response(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -306,16 +307,16 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator'); | ||
var validate = require('har-validator') | ||
validate.cacheEntry(data, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
}); | ||
validate.cacheEntry(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
### Validate.timings(data [, callback]) | ||
### Validate.timings(data) | ||
Returns `true` or `false`. | ||
> Returns a promise that resolves to the valid object. | ||
@@ -325,13 +326,36 @@ - **data**: `Object` *(Required)* | ||
- **callback**: `Function` | ||
gets two arguments (err, valid) | ||
```js | ||
var validate = require('har-validator') | ||
validate.timings(data.then(function (HAR) { | ||
console.log('horray!') | ||
}) | ||
.catch(function (error) { | ||
console.error(error) | ||
}) | ||
``` | ||
---- | ||
## Callback API | ||
### Validate(data [, callback]) | ||
Returns `true` or `false`. | ||
```js | ||
var validate = require('har-validator'); | ||
var HAR = require('./har.json'); | ||
var validate = require('har-validator/lib/async'); | ||
validate.timings(data, function (e, valid) { | ||
validate(HAR, function (e, valid) { | ||
if (e) console.log(e.errors) | ||
if (valid) console.log('horray!'); | ||
}); | ||
``` | ||
The async API provides exactly the same methods as the [Promise API](#promise-api) | ||
---- | ||
## Support | ||
@@ -338,0 +362,0 @@ |
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
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
23835
387