Comparing version 17.11.0 to 17.11.1
@@ -215,3 +215,7 @@ 'use strict'; | ||
const obj = this.$_parent('label', name); | ||
const each = (item, source) => (source.path[0] !== 'is' ? item.label(name) : undefined); | ||
const each = (item, source) => { | ||
return source.path[0] !== 'is' && typeof item._flags.label !== 'string' ? item.label(name) : undefined; | ||
}; | ||
return obj.$_modify({ each, ref: false }); | ||
@@ -218,0 +222,0 @@ } |
@@ -15,3 +15,13 @@ 'use strict'; | ||
dotRegex: /\./, | ||
trailingZerosRegex: /0+$/ | ||
trailingZerosRegex: /0+$/, | ||
decimalPlaces(value) { | ||
const str = value.toString(); | ||
const dindex = str.indexOf('.'); | ||
const eindex = str.indexOf('e'); | ||
return ( | ||
(dindex < 0 ? 0 : (eindex < 0 ? str.length : eindex) - dindex - 1) + | ||
(eindex < 0 ? 0 : Math.max(0, -parseInt(str.slice(eindex + 1)))) | ||
); | ||
} | ||
}; | ||
@@ -172,11 +182,26 @@ | ||
return this.$_addRule({ name: 'multiple', args: { base } }); | ||
const baseDecimalPlace = typeof base === 'number' ? internals.decimalPlaces(base) : null; | ||
const pfactor = Math.pow(10, baseDecimalPlace); | ||
return this.$_addRule({ | ||
name: 'multiple', | ||
args: { | ||
base, | ||
baseDecimalPlace, | ||
pfactor | ||
} | ||
}); | ||
}, | ||
validate(value, helpers, { base }, options) { | ||
validate(value, helpers, { base, baseDecimalPlace, pfactor }, options) { | ||
if (value * (1 / base) % 1 === 0) { | ||
return value; | ||
const valueDecimalPlace = internals.decimalPlaces(value); | ||
if (valueDecimalPlace > baseDecimalPlace) { | ||
// Value with higher precision than base can never be a multiple | ||
return helpers.error('number.multiple', { multiple: options.args.base, value }); | ||
} | ||
return helpers.error('number.multiple', { multiple: options.args.base, value }); | ||
return Math.round(pfactor * value) % Math.round(pfactor * base) === 0 ? | ||
value : | ||
helpers.error('number.multiple', { multiple: options.args.base, value }); | ||
}, | ||
@@ -189,3 +214,5 @@ args: [ | ||
message: 'must be a positive number' | ||
} | ||
}, | ||
'baseDecimalPlace', | ||
'pfactor' | ||
], | ||
@@ -192,0 +219,0 @@ multi: true |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "17.11.0", | ||
"version": "17.11.1", | ||
"repository": "git://github.com/hapijs/joi", | ||
@@ -18,5 +18,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@hapi/hoek": "^9.0.0", | ||
"@hapi/topo": "^5.0.0", | ||
"@sideway/address": "^4.1.3", | ||
"@hapi/hoek": "^9.3.0", | ||
"@hapi/topo": "^5.1.0", | ||
"@sideway/address": "^4.1.4", | ||
"@sideway/formula": "^3.0.1", | ||
@@ -29,4 +29,4 @@ "@sideway/pinpoint": "^2.0.0" | ||
"@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x", | ||
"@hapi/lab": "^25.0.1", | ||
"@types/node": "^14.18.24", | ||
"@hapi/lab": "^25.1.3", | ||
"@types/node": "^14.18.63", | ||
"typescript": "4.3.x" | ||
@@ -33,0 +33,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9877
529049
Updated@hapi/hoek@^9.3.0
Updated@hapi/topo@^5.1.0
Updated@sideway/address@^4.1.4