blob: de303abe1aae6c5822d5cbb7d74b36e9842b522a [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var numToStr = Number.prototype.toString;
4var tryNumberObject = function tryNumberObject(value) {
5 try {
6 numToStr.call(value);
7 return true;
8 } catch (e) {
9 return false;
10 }
11};
12var toStr = Object.prototype.toString;
13var numClass = '[object Number]';
14var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
15
16module.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};