<commit_before># koa-joi-schema

[![Build Status](https://travis-ci.org/simplyianm/koa-joi-schema.svg)](https://travis-ci.org/simplyianm/koa-joi-schema)

Koa middleware to validate input/output using [Joi][joi].

## Usage

See [test.js](test.js) for more examples.

```javascript
const validate = require('koa-joi-schema')

const validator = validate('body')(Joi.object().keys({
  username: Joi.string().email().required(),
  password: Joi.string()..regex(/^[a-zA-Z0-9]{3,30}$/).required()
}))

const errorHandler = (ctx, next) => {
  if (ctx.joiError) { // Joi error object
    ctx.status = 400 // invalid input
    ctx.body = {
      error: 'Invalid input',
      reason: ctx.joiError
    }
    return
  }
  yield next()
}

router.post('/users', bodyParser, validator, errorHandler, usersCtrl.create)
```

## License

ISC

[joi]: https://github.com/hapijs/joi<commit_msg>docs: add joi to docs<commit_after># koa-joi-schema

[![Build Status](https://travis-ci.org/simplyianm/koa-joi-schema.svg)](https://travis-ci.org/simplyianm/koa-joi-schema)

Koa middleware to validate input/output using [Joi][joi].

## Usage

See [test.js](test.js) for more examples.

```javascript
const validate = require('koa-joi-schema')
const Joi = validate.Joi // prevent version mismatch

const validator = validate('body')(Joi.object().keys({
  username: Joi.string().email().required(),
  password: Joi.string()..regex(/^[a-zA-Z0-9]{3,30}$/).required()
}))

const errorHandler = (ctx, next) => {
  if (ctx.joiError) { // Joi error object
    ctx.status = 400 // invalid input
    ctx.body = {
      error: 'Invalid input',
      reason: ctx.joiError
    }
    return
  }
  yield next()
}

router.post('/users', bodyParser, validator, errorHandler, usersCtrl.create)
```

## License

ISC

[joi]: https://github.com/hapijs/joi
{'fraction_non_alphanumeric': 0.18428334255672385, 'fraction_numerical': 0.008854454897620365, 'mean_word_length': 3.7830687830687832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2029511', 'n_tokens_mistral': 680, 'n_tokens_neox': 659, 'n_words': 127}