Skip to content
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 support for isSafeInteger #2529

Closed
wants to merge 1 commit into from
Closed

Add support for isSafeInteger #2529

wants to merge 1 commit into from

Conversation

devanp92
Copy link

@devanp92 devanp92 commented May 5, 2016

Include isSafeInteger as referenced in issue 2455 by @jdalton.

The conditions are:

  1. If Type(number) is not Number, return false.
  2. If number is NaN, +∞, or −∞, return false.
  3. Let integer be ToInteger(number).
  4. If integer is not equal to number, return false.
  5. Otherwise, return true.

Include [isSafeInteger](http://www.ecma-international.org/ecma-262/6.0/#sec-number.issafeinteger)
as referenced in [issue 2455](#2455) proposed by @jdalton.
@coveralls
Copy link

coveralls commented May 5, 2016

Coverage Status

Coverage increased (+0.008%) to 96.875% when pulling de69ee5 on devanp92:is-safe-integer into 53086b0 on jashkenas:master.

@@ -1344,6 +1344,10 @@
return obj != null && hasOwnProperty.call(obj, key);
};

_.isSafeInteger = function(obj) {
return _.isNumber(obj) && _.isFinite(obj) && toString.call(parseInt(obj, 10)) === '[object Number]' && Math.floor(obj) === obj;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the third condition really necessary here? It seems kind of redundant with the first. Also, maybe the first is a bit too lenient. The standard seems to suggest that object-wrapped numbers are not allowed, so it should probably be typeof obj === 'number'.

@jgonggrijp
Copy link
Collaborator

Postponing decision on this. As I wrote in #2455, I think this rather belongs in an extension library.

@devanp92 devanp92 closed this May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants