-
-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option for strictNumbers. Resolves #1128. #1219
Conversation
577ff49
to
6727a79
Compare
@issacgerges thank you - added some comments. |
6727a79
to
3f25187
Compare
Hey @epoberezkin made the changes you suggested. I ended up leaving |
@epoberezkin any other changes you'd like me to make? |
spec/options/strictNumbers.spec.js
Outdated
var validate = ajv.compile({type: 'integer'}); | ||
validate(1).should.equal(true); | ||
validate(NaN).should.equal(false); | ||
validate(Infinity).should.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed it, sorry - I think integer should also not allow Infinity with strictNumbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anybody would want to have a separate option and integers are also numbers (i.e. they would not fail validation with type: 'number'). The idea of type: 'integer' is to impose stricter constraint than number, but in this case it becomes somewhat overlapping rather than stricter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I would also add non-integer examples to the tests, to make sure nothing was broken with the new option (e.g. 1.1 would pass number but fail integer).
made one small comment about integer with strict numbers - sorry, missed it before. Almost there. |
3f25187
to
edd8c92
Compare
no worries @epoberezkin, I believe I should have met all your requests this time. let me know! |
Thank you! |
What issue does this pull request resolve?
#1128
What changes did you make?
Added an option for
strictNumbers
which is used incheckDataType
to conditionally checkisFinite(date)
. Added documentationIs there anything that requires more attention while reviewing?
The current behavior of
ajv
is thatinteger
will always failNaN
and passInfinity
butnumber
currently doesn't. To respect semver, this will continue to behave the same way, and this new optionstrictNumbers
is off by default.I'm unfamiliar with some of the internals of
ajv
and believe that my changes tocheckDataType
are sufficient. Also was unsure why y'all were usingdata === data
vsisFinite(data)
in integer (one will only failNaN
, the other will failNaN and pos/neg
Infinity`)