isNumber.js 886 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var baseGetTag = require('./_baseGetTag'),
  2. isObjectLike = require('./isObjectLike');
  3. /** `Object#toString` result references. */
  4. var numberTag = '[object Number]';
  5. /**
  6. * Checks if `value` is classified as a `Number` primitive or object.
  7. *
  8. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  9. * classified as numbers, use the `_.isFinite` method.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 0.1.0
  14. * @category Lang
  15. * @param {*} value The value to check.
  16. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  17. * @example
  18. *
  19. * _.isNumber(3);
  20. * // => true
  21. *
  22. * _.isNumber(Number.MIN_VALUE);
  23. * // => true
  24. *
  25. * _.isNumber(Infinity);
  26. * // => true
  27. *
  28. * _.isNumber('3');
  29. * // => false
  30. */
  31. function isNumber(value) {
  32. return typeof value == 'number' ||
  33. (isObjectLike(value) && baseGetTag(value) == numberTag);
  34. }
  35. module.exports = isNumber;