isInteger.js 669 B

12345678910111213141516171819202122232425262728293031323334
  1. var toInteger = require('./toInteger');
  2. /**
  3. * Checks if `value` is an integer.
  4. *
  5. * **Note:** This method is based on
  6. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Lang
  12. * @param {*} value The value to check.
  13. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  14. * @example
  15. *
  16. * _.isInteger(3);
  17. * // => true
  18. *
  19. * _.isInteger(Number.MIN_VALUE);
  20. * // => false
  21. *
  22. * _.isInteger(Infinity);
  23. * // => false
  24. *
  25. * _.isInteger('3');
  26. * // => false
  27. */
  28. function isInteger(value) {
  29. return typeof value == 'number' && value == toInteger(value);
  30. }
  31. module.exports = isInteger;