Skip to content

Commit

Permalink
Merge pull request #15 from evanshortiss/hapi-joi
Browse files Browse the repository at this point in the history
BREAKING CHANGE: move from joi to @hapi/joi package
  • Loading branch information
evanshortiss authored Jun 17, 2019
2 parents 9806cb8 + 1628fe1 commit 0c048c4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: node_js

node_js:
- "12"
- "11"
- "10"
- "8"
- "7"
- "6"

after_success:
- npm run coveralls
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## CHANGELOG
Date format is DD/MM/YYYY

## 1.0.0 (13/06/2019)
* Migrated from `joi` to `@hapi/joi`.
* Dropped Node.js 6 & 7 support (@hapi/joi forces this)
* Update dev dependencies.

## 0.3.0 (29/09/2018)
* Add response validation
* Update dependencies
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# express-joi-validation

![TravisCI](https://travis-ci.org/evanshortiss/express-joi-validation.svg)
[![npm version](https://badge.fury.io/js/express-joi-validation.svg)](https://badge.fury.io/js/express-joi-validation)
[![Coverage Status](https://coveralls.io/repos/github/evanshortiss/express-joi-validation/badge.svg?branch=master)](https://coveralls.io/github/evanshortiss/express-joi-validation?branch=master)
[![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/)
[![npm version](https://badge.fury.io/js/express-joi-validation.svg)](https://www.npmjs.com/package/express-joi-validation)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](http://www.typescriptlang.org/)
[![npm downloads](https://img.shields.io/npm/dm/express-joi-validation.svg?style=flat)](https://www.npmjs.com/package/express-joi-validation)
[![Known Vulnerabilities](https://snyk.io//test/github/evanshortiss/express-joi-validation/badge.svg?targetFile=package.json)](https://snyk.io//test/github/evanshortiss/express-joi-validation?targetFile=package.json)

A middleware for validating express inputs using Joi schemas. Fills some of the
voids I found that other Joi middleware miss such as:
Expand Down Expand Up @@ -45,7 +47,12 @@ folder of this repository.
```js
const Joi = require('joi')
const app = require('express')()
const validator = require('express-joi-validation')({})
const validator = require('express-joi-validation')({
// You can pass a specific Joi instance using this option. By default the
// module will load the @hapi/joi version you have in your package.json
// so 99% of the time you won't need this option
// joi: require('joi')
})

const querySchema = Joi.object({
type: Joi.string().required().valid('food', 'drinks', 'entertainment')
Expand All @@ -66,7 +73,7 @@ app.get('/orders', validator.query(querySchema, {joi: joiOpts}), (req, res, next

### Joi Versioning
This module uses `peerDependencies` for the Joi version being used. This means
whatever Joi version is in the `dependencies` of your `package.json` will be
whatever `@hapi/joi` version is in the `dependencies` of your `package.json` will be
used by this module.

### Validation Ordering
Expand Down
2 changes: 1 addition & 1 deletion express-joi-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function buildErrorString(err, container) {
module.exports = function generateJoiMiddlewareInstance(cfg) {
cfg = cfg || {} // default to an empty config

const Joi = cfg.joi || require('joi')
const Joi = cfg.joi || require('@hapi/joi')

// We'll return this instance of the middleware
const instance = {
Expand Down
2 changes: 1 addition & 1 deletion index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Joi = require('joi')
const Joi = require('@hapi/joi')
const sinon = require('sinon')
const supertest = require('supertest')
const expect = require('chai').expect
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-joi-validation",
"version": "0.3.0",
"version": "1.0.0",
"description": "validate express application inputs and parameters using joi",
"main": "express-joi-validation.js",
"scripts": {
Expand Down Expand Up @@ -34,6 +34,7 @@
"author": "Evan Shortiss",
"license": "MIT",
"devDependencies": {
"@hapi/joi": "~15.0.3",
"@types/express": "~4.0.39",
"@types/joi": "~13.6.0",
"@types/node": "^6.0.117",
Expand All @@ -44,22 +45,21 @@
"express": "~4.16.3",
"express-formidable": "~1.0.0",
"husky": "~1.0.1",
"joi": "~13.6.0",
"lodash": "~4.17.4",
"mocha": "~5.2.0",
"mocha-lcov-reporter": "~1.3.0",
"nodemon": "~1.11.0",
"nyc": "~13.0.1",
"nyc": "~14.1.1",
"prettier": "~1.14.3",
"proxyquire": "~1.7.11",
"sinon": "~1.17.7",
"supertest": "~3.0.0",
"typescript": "~2.5.3"
},
"peerDependencies": {
"joi": "*"
"@hapi/joi": "*"
},
"engines": {
"node": ">=6.0.0"
"node": ">=8.0.0"
}
}

0 comments on commit 0c048c4

Please sign in to comment.