-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (52 loc) · 1.51 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module.exports = function(checkedVariable){
return {
is: function(typeString){
if(undefined === typeString){
return getTypeOf(checkedVariable);
}
else{
return (typeString === getTypeOf(checkedVariable));
}
}
}
}
//delete require.cache[require.resolve('/path/to/module.js')]
function getTypeOf(value) {
var ObjectHinting = {
LitteralObjectMatcher : /^\s*function\s*(Object)\s*\(\s*\)\s*\{\s*\[native\s*code]\s*}\s*$/,
ArrayMatcher : /^\s*function\s*(Array)\s*\(\s*\)\s*\{\s*\[native\s*code]\s*}\s*$/,
DateMatcher : /^\s*function\s*(Date)\s*\(\s*\)\s*\{\s*\[native\s*code]\s*}\s*$/,
EngineNativeTypeMatcher : /^\s*function\s*(\w+)\s*\(\s*\)\s*\{\s*\[native\s*code]\s*}\s*$/,
ConstructedTypeMatcher : /^(?:\s|\n)*function(?:\s|\n)*(\w+)(?:\s|\n)*\(/m
}
var HintResult = [];
var HintString = "";
if ("object" === typeof value) {
if (null === value) {
HintString = "Null";
}
else{
for (var m in ObjectHinting) {
HintResult = value.constructor.toString().match(ObjectHinting[m]);
if(null !== HintResult){
HintString = HintResult[1];
break;
}
}
}
}
else{
if(undefined === value){
HintString = "Undefined";
}
else{
if (("number" === typeof value) && ("NaN" === value.toString())) {
HintString = "NaN";
}
else{
HintString = (typeof value).substr(0,1).toUpperCase() + (typeof value).substr(1);
}
}
}
return HintString;
}