index.js 585 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var numToStr = Number.prototype.toString;
  3. var tryNumberObject = function tryNumberObject(value) {
  4. try {
  5. numToStr.call(value);
  6. return true;
  7. } catch (e) {
  8. return false;
  9. }
  10. };
  11. var toStr = Object.prototype.toString;
  12. var numClass = '[object Number]';
  13. var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag;
  14. module.exports = function isNumberObject(value) {
  15. if (typeof value === 'number') {
  16. return true;
  17. }
  18. if (typeof value !== 'object') {
  19. return false;
  20. }
  21. return hasToStringTag ? tryNumberObject(value) : toStr.call(value) === numClass;
  22. };