Skip to content

Commit

Permalink
Replace v16 compatibility interface. Closes #2047
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Aug 16, 2019
1 parent e14321f commit da4774f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 59 deletions.
20 changes: 0 additions & 20 deletions .editorconfig

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

28 changes: 14 additions & 14 deletions examples/conditionalRequire.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ const schema = Joi.object().keys({
.when('q2', { is: true, then: Joi.valid('1-5', '6-10', '11-50', '50+').required() }),
// Rate 20% of most friendly Parisians, from how many people you know answered in q3, individually on 1-5 rating
q4: Joi.array()
.when('q3', {is: '1-5', then: Joi.array().min(0).max(1).items(intRating).required() })
.when('q3', {is: '6-10', then: Joi.array().min(1).max(2).items(intRating).required() })
.when('q3', {is: '11-50', then: Joi.array().min(2).max(10).items(intRating).required() })
.when('q3', {is: '50+', then: Joi.array().min(10).items(intRating).required() }),
.when('q3', { is: '1-5', then: Joi.array().min(0).max(1).items(intRating).required() })
.when('q3', { is: '6-10', then: Joi.array().min(1).max(2).items(intRating).required() })
.when('q3', { is: '11-50', then: Joi.array().min(2).max(10).items(intRating).required() })
.when('q3', { is: '50+', then: Joi.array().min(10).items(intRating).required() }),
// Rate remaining 80% of Parisians, from how many people you know answered in q3, individually on 1-5 rating
q5: Joi.array()
.when('q3', {is: '1-5', then: Joi.array().min(1).max(4).items(intRating).required() })
.when('q3', {is: '6-10', then: Joi.array().min(4).max(8).items(intRating).required() })
.when('q3', {is: '11-50', then: Joi.array().min(8).max(40).items(intRating).required() })
.when('q3', {is: '50+', then: Joi.array().min(40).items(intRating).required().required() }),
.when('q3', { is: '1-5', then: Joi.array().min(1).max(4).items(intRating).required() })
.when('q3', { is: '6-10', then: Joi.array().min(4).max(8).items(intRating).required() })
.when('q3', { is: '11-50', then: Joi.array().min(8).max(40).items(intRating).required() })
.when('q3', { is: '50+', then: Joi.array().min(40).items(intRating).required().required() }),
// Rate the reputation of Parisians in general, 1-5 rating
q6: intRating.required()
});

const response = {
q1: true,
q2: true,
q3: '1-5',
q4: [5],
q5: [1],
q6: 2
q1: true,
q2: true,
q3: '1-5',
q4: [5],
q5: [1],
q6: 2
};

Joi.assert(response, schema);
8 changes: 4 additions & 4 deletions examples/multipleWhen.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const internals = {};
const schema = {
type: Joi.string().required(),
subtype: Joi.alternatives()
.when('type', {is: 'video', then: Joi.valid('mp4', 'wav')})
.when('type', {is: 'audio', then: Joi.valid('mp3')})
.when('type', {is: 'image', then: Joi.valid('jpg', 'png')})
.when('type', {is: 'pdf' , then: Joi.valid('document')})
.when('type', { is: 'video', then: Joi.valid('mp4', 'wav') })
.when('type', { is: 'audio', then: Joi.valid('mp3') })
.when('type', { is: 'image', then: Joi.valid('jpg', 'png') })
.when('type', { is: 'pdf', then: Joi.valid('document') })
};


Expand Down
12 changes: 6 additions & 6 deletions examples/timestamps.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const javascriptTimestamp = now.getTime();
const unixTimestamp = now.getTime() / 1000;

const schema = Joi.object().options({ abortEarly: false }).keys({
javascript1: Joi.date().timestamp(),
javascript2: Joi.date().timestamp('javascript'),
unix: Joi.date().timestamp('unix')
javascript1: Joi.date().timestamp(),
javascript2: Joi.date().timestamp('javascript'),
unix: Joi.date().timestamp('unix')
});

const data = {
javascript1: javascriptTimestamp,
javascript2: javascriptTimestamp,
unix: unixTimestamp
javascript1: javascriptTimestamp,
javascript2: javascriptTimestamp,
unix: unixTimestamp
};

Joi.assert(data, schema);
3 changes: 1 addition & 2 deletions lib/types/any/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const Hoek = require('@hapi/hoek');
const Marker = require('@hapi/marker');

const Cast = require('../../cast');
const Settings = require('./settings');
Expand All @@ -18,7 +17,7 @@ let Schemas = null;

const internals = {
Set: require('../../set'),
symbol: Marker('joi-any-base')
symbol: Symbol.for('@hapi/joi/schema')
};


Expand Down
3 changes: 2 additions & 1 deletion lib/types/array/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const Bourne = require('@hapi/bourne');
const Hoek = require('@hapi/hoek');

const Any = require('../any');
Expand Down Expand Up @@ -49,7 +50,7 @@ internals.Array = class extends Any {
(value[0] === '[' || /^\s*\[/.test(value))) {

try {
result.value = JSON.parse(value);
result.value = Bourne.parse(value);
}
catch (e) { }
}
Expand Down
3 changes: 2 additions & 1 deletion lib/types/object/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const Bourne = require('@hapi/bourne');
const Hoek = require('@hapi/hoek');
const Topo = require('@hapi/topo');

Expand Down Expand Up @@ -48,7 +49,7 @@ internals.Object = class extends Any {
(value[0] === '{' || /^\s*\{/.test(value))) {

try {
value = JSON.parse(value);
value = Bourne.parse(value);
}
catch (e) { }
}
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@
],
"dependencies": {
"@hapi/address": "2.x.x",
"@hapi/hoek": "6.x.x",
"@hapi/marker": "1.x.x",
"@hapi/bourne": "1.x.x",
"@hapi/hoek": "8.x.x",
"@hapi/topo": "3.x.x"
},
"devDependencies": {
"@hapi/code": "5.x.x",
"@hapi/lab": "18.x.x",
"hapitoc": "1.x.x"
"@hapi/code": "6.x.x",
"@hapi/lab": "20.x.x"
},
"scripts": {
"test": "lab -t 100 -a @hapi/code -L",
"test-cov-html": "lab -r html -o coverage.html -a @hapi/code",
"toc": "hapitoc && node docs/check-errors-list.js",
"version": "npm run toc && git add API.md README.md"
"test-cov-html": "lab -r html -o coverage.html -a @hapi/code"
},
"license": "BSD-3-Clause"
}

0 comments on commit da4774f

Please sign in to comment.