const schema = Joi.number();
const result = schema.validate('0.00000095');
console.log(result);
{ error:
{ ValidationError: "value" must be a safe number
at Object.exports.process (/Users/aleksanderbarszczewski/Desktop/projects/sm3/node_modules/joi/lib/errors.js:203:19)
at internals.Number._validateWithOptions (/Users/aleksanderbarszczewski/Desktop/projects/sm3/node_modules/joi/lib/types/any/index.js:764:31)
at internals.Number.validate (/Users/aleksanderbarszczewski/Desktop/projects/sm3/node_modules/joi/lib/types/any/index.js:798:21)
at Object.<anonymous> (/Users/aleksanderbarszczewski/Desktop/projects/sm3/src/test.ts:40:23)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Module.m._compile (/Users/aleksanderbarszczewski/Desktop/projects/sm3/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/aleksanderbarszczewski/Desktop/projects/sm3/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
isJoi: true,
name: 'ValidationError',
details: [ [Object] ],
_object: '0.00000095',
annotate: [Function] },
value: 9.5e-7,
then: [Function: then],
catch: [Function: catch] }
It should not throw error. I believe this is because of this line https://github.com/hapijs/joi/blob/master/lib/types/number.js#L48 and value stringified to '9.5e-7' which does not match internals.normalizeDecimal(value).
Hi, I would like to fix this issue, Can I?
@raghavmac sure, but you only have a day or two before I'll close it myself.
Thanks!
Most helpful comment
Thanks!