Skip to content

Commit

Permalink
feat(validator): change validator to the superior AJV
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nassri committed Dec 3, 2016
1 parent 95f9fea commit 89b6486
Show file tree
Hide file tree
Showing 34 changed files with 108 additions and 623 deletions.
8 changes: 4 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

"browsers": {
"presets": [ ["env", { "targets": { "browsers": ["last 2 versions"] } }] ],
"plugins": ["babel-plugin-add-module-exports"]
"plugins": ["add-module-exports"]
},

"v4": {
"presets": [ ["env", { "targets": { "node": 4.0 } }] ],
"plugins": ["babel-plugin-add-module-exports"]
"plugins": ["add-module-exports"]
},

"v6": {
"presets": [ ["env", { "targets": { "node": 6.0 } }] ],
"plugins": ["babel-plugin-add-module-exports"]
"plugins": ["add-module-exports"]
},

"v7": {
"presets": [ ["env", { "targets": { "node": 7.0 } }] ],
"plugins": ["babel-plugin-add-module-exports"]
"plugins": ["add-module-exports"]
}
}
}
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ cache:

before_script:
- npm prune
- BABEL_ENV=v4 npm run compile -- -d lib/node4
- BABEL_ENV=v6 npm run compile -- -d lib/node6
- BABEL_ENV=v7 npm run compile -- -d lib/node7
- BABEL_ENV=browser npm run compile -- -d lib/browser

after_success:
- npm run coverage
- npm run codeclimate
- BABEL_ENV=v4 npm run compile -- -d lib/node4
- BABEL_ENV=v6 npm run compile -- -d lib/node6
- BABEL_ENV=v7 npm run compile -- -d lib/node7
- BABEL_ENV=browsers npm run compile -- -d lib/browsers
- npm run semantic-release

branches:
Expand Down
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,17 @@ I recommend using an optimized build matching your Node.js environment version,
/*
* Node 7
*/
const validator = require('har-validator/lib/node7')
const validate = require('har-validator/lib/node7')

/*
* Node 6
*/
const validator = require('har-validator/lib/node6')
const validate = require('har-validator/lib/node6')

/*
* Node 4 (Default)
* Note: additional ES2015 polyfills may be required
*/
var validator = require('har-validator')
```


```bash
# to use in cli
npm install --global har-validator

# to use as a module
npm install --save har-validator
var validate = require('har-validator')
```

## CLI Usage
Expand All @@ -63,9 +53,9 @@ npm install --save har-validator
###### Example

```shell
har-validator har.json
$ har-validator har.json

har-validator --schema request request.json
$ har-validator --schema=request request.json
```

## API
Expand Down
6 changes: 3 additions & 3 deletions docs/async.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## async API

```js
import validate from 'har-validator/lib/{node-version}/async'
import * as validate from 'har-validator/lib/{node-version}/async'
import { request, response } from 'har-validator/lib/{node-version}/async'
```

### validate.default(data)
### validate.har(data)

> Returns `true` or `false`.
- **data**: `Object` *(Required)*
a full [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) object

```js
let isValid = validate(data)
let isValid = validate.har(data)
```

### validate.log(data)
Expand Down
6 changes: 3 additions & 3 deletions docs/callback.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## Callback API

```js
import validate from 'har-validator/lib/{node-version}/async'
import * as validate from 'har-validator/lib/{node-version}/async'
import { request, response } from 'har-validator/lib/{node-version}/async'
```

### validate.default(data [, callback])
### validate.har(data [, callback])

- **data**: `Object` *(Required)*
a full [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) object
- **callback**: `Function`
callback function with signature of `(err, valid)`

```js
validate.default(data, (err, valid) => {
validate.har(data, (err, valid) => {
if (err) console.error(err.errors)

if (valid) console.log('✔️')
Expand Down
8 changes: 4 additions & 4 deletions docs/promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@


```js
import validate from 'har-validator'
import validate from 'har-validator/lib/{node-version}/promise'
import * as validate from 'har-validator'
import * as validate from 'har-validator/lib/{node-version}/promise'
import { request, response } from 'har-validator/lib/{node-version}/promise'
```

### validate.default(data)
### validate.har(data)

> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a full [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) object

```js
validate(data)
validate.har(data)
.then((data) => console.log('✔️'))
.catch(console.error)
```
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"keywords": [
"har",
"cli",
"ajv",
"http",
"archive",
"validate",
Expand All @@ -34,9 +35,11 @@
},
"scripts": {
"compile": "babel -q src",
"test": "BABEL_ENV=test tap test/*.js --reporter spec --node-arg=--require --node-arg=babel-register",
"test": "BABEL_ENV=test tap test --reporter spec --node-arg=--require --node-arg=babel-register",
"test-one": "BABEL_ENV=test tap --reporter spec --node-arg=--require --node-arg=babel-register",
"test-cli": "BABEL_ENV=test babel-node src/bin.js",
"pretest": "snazzy && echint",
"coverage": "BABEL_ENV=test tap test/*.js --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register",
"coverage": "BABEL_ENV=test tap test --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register",
"codeclimate": "BABEL_ENV=test tap --coverage-report=text-lcov | codeclimate-test-reporter",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
Expand Down Expand Up @@ -68,8 +71,9 @@
"tap": "^8.0.1"
},
"dependencies": {
"ajv": "^4.9.0",
"chalk": "^1.1.3",
"commander": "^2.9.0",
"is-my-json-valid": "^2.15.0"
"har-schema": "^0.1.0"
}
}
13 changes: 0 additions & 13 deletions schemas/cache.json

This file was deleted.

31 changes: 0 additions & 31 deletions schemas/cacheEntry.json

This file was deleted.

27 changes: 0 additions & 27 deletions schemas/content.json

This file was deleted.

34 changes: 0 additions & 34 deletions schemas/cookie.json

This file was deleted.

18 changes: 0 additions & 18 deletions schemas/creator.json

This file was deleted.

51 changes: 0 additions & 51 deletions schemas/entry.json

This file was deleted.

11 changes: 0 additions & 11 deletions schemas/har.json

This file was deleted.

Loading

0 comments on commit 89b6486

Please sign in to comment.