| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var numToStr = Number.prototype.toString; |
| 4 | var tryNumberObject = function tryNumberObject(value) { |
| 5 | try { |
| 6 | numToStr.call(value); |
| 7 | return true; |
| 8 | } catch (e) { |
| 9 | return false; |
| 10 | } |
| 11 | }; |
| 12 | var toStr = Object.prototype.toString; |
| 13 | var numClass = '[object Number]'; |
| 14 | var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; |
| 15 | |
| 16 | module.exports = function isNumberObject(value) { |
| 17 | if (typeof value === 'number') { |
| 18 | return true; |
| 19 | } |
| 20 | if (typeof value !== 'object') { |
| 21 | return false; |
| 22 | } |
| 23 | return hasToStringTag ? tryNumberObject(value) : toStr.call(value) === numClass; |
| 24 | }; |