-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.js
155 lines (139 loc) · 3.68 KB
/
util.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
/**
* @description
*/
const isUndefined = exports.isUndefined = function isUndefined(param) {
if( Object.prototype.toString.call(param) == '[object Undefined]') return true;
return false
}
/**
* @description
*/
const isNull = exports.isNull = function isNull(param) {
if( Object.prototype.toString.call(param) == '[object Null]') return true;
return false
}
/**
* @description
*/
const isEmpty = exports.isEmpty = function isEmpty(param) {
if(isUndefined(param)) return true;
if(isNull(param)) return true;
return false;
}
/**
* @description
*/
const isObject = exports.isObject = function isObject(param) {
if( Object.prototype.toString.call(param) == '[object Object]') return true;
return false
}
/**
* @description
*/
const isArray = exports.isArray = function isArray(param) {
if( Object.prototype.toString.call(param) == '[object Array]') return true;
return false
}
/**
* @description
*/
const isComparableNumber = exports.isComparableNumber = function isComparableNumber(param) {
if( Object.prototype.toString.call(param) == '[object Number]'){
if(isNaN(param)){
return false;
}else{
if((typeof param) == 'object'){
return false;
}else{
return true;
}
}
}
return false;
}
/**
* @description 获取对应的类型
*/
const getType = exports.getType = function getType(param) {
let type = Object.prototype.toString.call(param);
switch (type) {
case "[object String]":
if((typeof param) == 'object'){
type = "String(object)";
}else{
type = "String";
}
break;
case "[object Number]":
if(isNaN(param)){
type = "Number(isNaN)";
}else{
if((typeof param) == 'object'){
type = "Number(object)";
}else{
type = "Number";
}
}
break;
case "[object Array]":
type = "Array";
break;
case "[object Object]":
type = "Object";
break;
case "[object Boolean]":
if((typeof param) == 'object'){
type = "Boolean(object)";
}else{
type = "Boolean";
}
break;
case "[object Date]":
type = "Date";
break;
case "[object Function]":
type = "Function";
break;
case "[object Symbol]":
type = "Symbol";
break;
case "[object RegExp]":
type = "RegExp";
break;
case "[object Uint8Array]":
type = "Buffer";
break;
case "[object BigInt]":
type = "BigInt";
break;
case "[object Error]":
type = "Error";
break;
case "[object Null]":
type = "Null";
break;
case "[object Undefined]":
type = "Undefined";
break;
case "[object WeakMap]":
type = "WeakMap";
break;
case "[object Map]":
type = "Map";
break;
case "[object WeakSet]":
type = "WeakSet";
break;
case "[object Set]":
type = "Set";
break;
}
return type;
}
/**
* @description 获取提示信息
*/
const getMsgTip = exports.getMsgTip = function getMsgTip(param) {
return `But the type of the argument passed in is [${getType(param)}], Please check the value in the "_original" field.`;
}