Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
docs: usage with Ajv
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Dec 26, 2016
1 parent d4b0643 commit 96ccdf0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# ajv-async
Managing and detecting async validation mode in Ajv - JSON-Schema validator
Configure async validation mode in [Ajv](https://github.com/epoberezkin/ajv) - JSON-Schema validator

[![npm version](https://badge.fury.io/js/ajv-async.svg)](https://www.npmjs.com/package/ajv-async)
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)

## Install

```shell
npm install ajv-async
```


## Usage

The code below configures async mode in Ajv instance to use the best async mode (async functions or generators) available in the current environment with/without transpilation. If transpilation is required, you should install [nodent](https://github.com/MatAtBread/nodent) or [regenerator](https://github.com/facebook/regenerator), ajv-async doesn't install them.

```javascript
var Ajv = require('ajv');
var setupAsync = require('ajv-async');

var ajv = setupAsync(new Ajv);
```

`async` and/or `transpile` options can be passed to Ajv to enable a specific async/transpilation mode. See [Ajv docs](https://github.com/epoberezkin/ajv#asynchronous-validation) for more information.


## Using in browser

At the moment Ajv already includes nodent and regenerators bundles. You still need to use this package, unless you manually set `async` option and explicitely pass `processCode` option. `transpile` option support requires using this package.

If you build this package with your code with Webpack, it will log warnings because this package uses optional dependencies. To suppress these warnings use [IgnorePlugin](https://webpack.github.io/docs/list-of-plugins.html#ignoreplugin):

```javascript
new IgnorePlugin(/regenerator|nodent/, /ajv-async/)
```


## License

[MIT](https://github.com/epoberezkin/ajv-async/blob/master/LICENSE)
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ajv-async",
"version": "0.0.1",
"description": "Managing and detecting async validation mode in Ajv - JSON-Schema validator",
"version": "0.1.0",
"description": "Configure async validation mode in Ajv - JSON-Schema validator",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -20,7 +20,11 @@
"json-schema-validator",
"json-schema-validation",
"async",
"asynchronous",
"asynchronous validation",
"ajv",
"generators",
"async-function",
"co",
"nodent",
"regenerator"
Expand Down

0 comments on commit 96ccdf0

Please sign in to comment.