From da4774f8213058fac2da5c00b995c43f68e49787 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Fri, 16 Aug 2019 00:14:50 +0000 Subject: [PATCH] Replace v16 compatibility interface. Closes #2047 --- .editorconfig | 20 -------------------- .eslintignore | 3 --- examples/conditionalRequire.js | 28 ++++++++++++++-------------- examples/multipleWhen.js | 8 ++++---- examples/timestamps.js | 12 ++++++------ lib/types/any/index.js | 3 +-- lib/types/array/index.js | 3 ++- lib/types/object/index.js | 3 ++- package.json | 13 +++++-------- 9 files changed, 34 insertions(+), 59 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintignore mode change 100644 => 100755 examples/conditionalRequire.js mode change 100644 => 100755 examples/multipleWhen.js mode change 100644 => 100755 examples/timestamps.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 2ae4771bb..000000000 --- a/.editorconfig +++ /dev/null @@ -1,20 +0,0 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - -root = true - -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -indent_style = space -indent_size = 4 - -[**.{js,json,md}] -insert_final_newline = true - -[**.{json,md}] -indent_size = 2 - -[**.html] -insert_final_newline = false diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 3962e2efa..000000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -examples -sandbox.js -/benchmarks/node_modules diff --git a/examples/conditionalRequire.js b/examples/conditionalRequire.js old mode 100644 new mode 100755 index 6f3e86036..27798bcfa --- a/examples/conditionalRequire.js +++ b/examples/conditionalRequire.js @@ -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); diff --git a/examples/multipleWhen.js b/examples/multipleWhen.js old mode 100644 new mode 100755 index 66e372bde..45bca1ef9 --- a/examples/multipleWhen.js +++ b/examples/multipleWhen.js @@ -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') }) }; diff --git a/examples/timestamps.js b/examples/timestamps.js old mode 100644 new mode 100755 index e5905d027..00473da3e --- a/examples/timestamps.js +++ b/examples/timestamps.js @@ -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); diff --git a/lib/types/any/index.js b/lib/types/any/index.js index de6293c5d..a53ef8af1 100755 --- a/lib/types/any/index.js +++ b/lib/types/any/index.js @@ -1,7 +1,6 @@ 'use strict'; const Hoek = require('@hapi/hoek'); -const Marker = require('@hapi/marker'); const Cast = require('../../cast'); const Settings = require('./settings'); @@ -18,7 +17,7 @@ let Schemas = null; const internals = { Set: require('../../set'), - symbol: Marker('joi-any-base') + symbol: Symbol.for('@hapi/joi/schema') }; diff --git a/lib/types/array/index.js b/lib/types/array/index.js index 8438946c0..2664aaa37 100755 --- a/lib/types/array/index.js +++ b/lib/types/array/index.js @@ -1,5 +1,6 @@ 'use strict'; +const Bourne = require('@hapi/bourne'); const Hoek = require('@hapi/hoek'); const Any = require('../any'); @@ -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) { } } diff --git a/lib/types/object/index.js b/lib/types/object/index.js index cdb18a0d8..df2fc051c 100755 --- a/lib/types/object/index.js +++ b/lib/types/object/index.js @@ -1,5 +1,6 @@ 'use strict'; +const Bourne = require('@hapi/bourne'); const Hoek = require('@hapi/hoek'); const Topo = require('@hapi/topo'); @@ -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) { } } diff --git a/package.json b/package.json index a01687b29..af1a4129d 100644 --- a/package.json +++ b/package.json @@ -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" }