-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathestype.js
More file actions
34 lines (32 loc) · 1.06 KB
/
estype.js
File metadata and controls
34 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(function (root) {
"use strict";
function type(value) {
var r;
if (typeof value === 'object') {
if (value === null) {
return 'null';
}
if (typeof value.constructor === 'function' &&
(r = value.constructor.name) !== 'Object') {
if (r === '' || r === undefined) {
return Function.prototype.toString.call(value.constructor)
.match(/^\n?(?:function|class)\s*([^\s(]*)/)[1] || 'anonymous';
}
return r;
}
return Object.prototype.toString.call(value).match(/\s(.*)\]/)[1];
} else if (typeof value === 'number') {
return isNaN(value) ? 'NaN' : 'number';
}
return typeof value;
}
// Export for node and browser
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
module.exports = type;
}
exports.type = type;
} else {
root.type = type;
}
})(this);