joi-nochange
Advanced tools
Comparing version 2.0.0 to 3.0.0
27
index.js
'use strict'; | ||
const Joi = require('joi'); | ||
const Hoek = require('hoek'); | ||
function noChangeExtend(Joi) { | ||
// extend Joi | ||
// due to extending any() not extending other types, number(), string(), etc. we need to extend all of these manually | ||
// see https://github.com/hapijs/joi/issues/577 | ||
return Joi | ||
.extend(createRule('any')) | ||
.extend(createRule('object')) | ||
.extend(createRule('number')) | ||
.extend(createRule('string')) | ||
.extend(createRule('date')) | ||
.extend(createRule('boolean')); | ||
} | ||
// creates a rule for the provided base type | ||
@@ -19,3 +31,3 @@ function createRule(joiType) { | ||
params: { | ||
q: Joi.any() | ||
q: joi.any() | ||
}, | ||
@@ -42,11 +54,2 @@ validate(params, value, state, options) { | ||
// extend Joi and export | ||
// due to extending any() not extending other types, number(), string(), etc. we need to extend all of these manually | ||
// see https://github.com/hapijs/joi/issues/577 | ||
module.exports = Joi | ||
.extend(createRule('any')) | ||
.extend(createRule('object')) | ||
.extend(createRule('number')) | ||
.extend(createRule('string')) | ||
.extend(createRule('date')) | ||
.extend(createRule('boolean')); | ||
module.exports = noChangeExtend; |
{ | ||
"name": "joi-nochange", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Adds noChange() to Joi", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=6.0.0" | ||
}, | ||
@@ -31,13 +31,13 @@ "keywords": [ | ||
"dependencies": { | ||
"hoek": "^3.0.4" | ||
"hoek": "^5.0.3" | ||
}, | ||
"peerDependencies": { | ||
"joi": ">=10.3.0" | ||
"joi": ">=11.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "3.4.1", | ||
"eslint": "1.10.3", | ||
"chai": "^4.1.2", | ||
"eslint": "^5.0.1", | ||
"joi": "12.0.0", | ||
"mocha": "2.3.4" | ||
"mocha": "^5.2.0" | ||
} | ||
} |
@@ -12,8 +12,20 @@ # Joi noChange Plugin | ||
## v3 Breaking Changes | ||
Instead of having `joi-nochange` extend Joi when required, v3 allows an instance of Joi to be passed in. This fixes an issue where other uses of `Joi.extend` would become innefective if used before requiring `joi-nochange`. | ||
To migrate, change | ||
```js | ||
const Joi = require('joi-nochange'); | ||
``` | ||
to | ||
```js | ||
const Joi = require('joi-nochange')(require('joi')); | ||
``` | ||
## Usage | ||
```js | ||
var Joi = require('joi-nochange'); // require this plugin as Joi | ||
const Joi = require('joi-nochange')(require('joi')); | ||
var origObj = { | ||
const origObj = { | ||
id: 'k1773y', | ||
@@ -28,3 +40,3 @@ name: 'Cuddles', | ||
var kitty = JSON.parse(JSON.stringify(origObj)); // clone | ||
const kitty = JSON.parse(JSON.stringify(origObj)); // clone | ||
@@ -35,3 +47,3 @@ kitty.meta.weight += 10; // Cuddles has been eating a lot | ||
var schema = Joi.object().keys({ | ||
const schema = Joi.object().keys({ | ||
id: Joi.string().noChange(origObj).required().label('id'), | ||
@@ -46,3 +58,3 @@ name: Joi.string().required().label('name'), | ||
var result = schema.validate(kitty); | ||
const result = schema.validate(kitty); | ||
// check and throw if there is an error (there is) | ||
@@ -61,6 +73,7 @@ if (result.error) { | ||
| < 9.0.0 | < 1.0.0 (`joi-pre-v9` branch) | | ||
| 9.0.0 - 10.2.2 | 1.0.0 (`joi-v9` branch) | | ||
| 10.3.0+ | 2.0.0 (`master` branch) | | ||
| 9.0.0 - 10.2.2 | 1.x.x (`joi-v9` branch) | | ||
| 10.x.x | 2.x.x (`joi-v10` branch) | | ||
| 11.0.0 + | > 3.0.0 (`master` branch) | | ||
### Finding Compatible Versions | ||
There is a [`find-compatible.js`](find-compatible.js) script that tests the currently checked out branch of `joi-nochange` against all versions of `joi>6`. |
6089
45
75
+ Addedhoek@5.0.4(transitive)
- Removedhoek@3.0.4(transitive)
Updatedhoek@^5.0.3