@ivujs/i-utils 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +17 -19
  2. package/dist/cjs/id/index.cjs +26 -43
  3. package/dist/cjs/index.cjs +8 -398
  4. package/dist/es/id/index.d.ts +16 -0
  5. package/dist/es/id/index.mjs +28 -42
  6. package/dist/es/index.d.ts +2 -0
  7. package/dist/es/index.mjs +8 -58
  8. package/dist/index.d.ts +21 -0
  9. package/dist/lib/index.full.cjs.js +38 -0
  10. package/dist/lib/index.full.cjs.min.js +2 -0
  11. package/dist/lib/index.full.cjs.min.js.map +1 -0
  12. package/dist/lib/index.full.esm.js +35 -15822
  13. package/dist/lib/index.full.esm.min.js +2 -58
  14. package/dist/lib/index.full.esm.min.js.map +1 -0
  15. package/dist/lib/index.full.umd.js +39 -16176
  16. package/dist/lib/index.full.umd.min.js +2 -0
  17. package/dist/lib/index.full.umd.min.js.map +1 -0
  18. package/package.json +77 -54
  19. package/dist/cjs/ID-card/index.cjs +0 -122
  20. package/dist/cjs/array/index.cjs +0 -465
  21. package/dist/cjs/clipboard/index.cjs +0 -135
  22. package/dist/cjs/color/index.cjs +0 -210
  23. package/dist/cjs/constants/date.cjs +0 -186
  24. package/dist/cjs/constants/lang.cjs +0 -13
  25. package/dist/cjs/constants/math.cjs +0 -13
  26. package/dist/cjs/constants/regexp.cjs +0 -57
  27. package/dist/cjs/constants/sort.cjs +0 -15
  28. package/dist/cjs/cookie/index.cjs +0 -71
  29. package/dist/cjs/crypto/aes/aes.cjs +0 -533
  30. package/dist/cjs/crypto/aes/index.cjs +0 -28
  31. package/dist/cjs/crypto/base32/base32.cjs +0 -385
  32. package/dist/cjs/crypto/base32/index.cjs +0 -44
  33. package/dist/cjs/crypto/base64/base64.cjs +0 -433
  34. package/dist/cjs/crypto/base64/index.cjs +0 -64
  35. package/dist/cjs/crypto/des/des.cjs +0 -1054
  36. package/dist/cjs/crypto/des/index.cjs +0 -30
  37. package/dist/cjs/crypto/md5/index.cjs +0 -25
  38. package/dist/cjs/crypto/md5/md5.cjs +0 -944
  39. package/dist/cjs/crypto/sha/sha1/index.cjs +0 -25
  40. package/dist/cjs/crypto/sha/sha1/sha1.cjs +0 -602
  41. package/dist/cjs/crypto/sha/sha256/index.cjs +0 -46
  42. package/dist/cjs/crypto/sha/sha256/sha256.cjs +0 -654
  43. package/dist/cjs/crypto/sha/sha3/index.cjs +0 -44
  44. package/dist/cjs/crypto/sha/sha3/sha3.cjs +0 -747
  45. package/dist/cjs/crypto/sha/sha512/index.cjs +0 -88
  46. package/dist/cjs/crypto/sha/sha512/sha512.cjs +0 -1186
  47. package/dist/cjs/crypto/sm/lib/asn1.cjs +0 -167
  48. package/dist/cjs/crypto/sm/lib/ec.cjs +0 -352
  49. package/dist/cjs/crypto/sm/lib/jsbn.cjs +0 -1633
  50. package/dist/cjs/crypto/sm/lib/sm3.cjs +0 -173
  51. package/dist/cjs/crypto/sm/lib/utils.cjs +0 -198
  52. package/dist/cjs/crypto/sm/sm2/index.cjs +0 -122
  53. package/dist/cjs/crypto/sm/sm2/sm2.cjs +0 -269
  54. package/dist/cjs/crypto/sm/sm3/index.cjs +0 -15
  55. package/dist/cjs/crypto/sm/sm3/sm3.cjs +0 -103
  56. package/dist/cjs/crypto/sm/sm4/index.cjs +0 -28
  57. package/dist/cjs/crypto/sm/sm4/sm4.cjs +0 -362
  58. package/dist/cjs/crypto/tea/index.cjs +0 -26
  59. package/dist/cjs/crypto/tea/tea.cjs +0 -215
  60. package/dist/cjs/date/index.cjs +0 -1349
  61. package/dist/cjs/desensitized/index.cjs +0 -74
  62. package/dist/cjs/device/index.cjs +0 -159
  63. package/dist/cjs/dom/index.cjs +0 -176
  64. package/dist/cjs/file/index.cjs +0 -339
  65. package/dist/cjs/function/index.cjs +0 -67
  66. package/dist/cjs/keycode/index.cjs +0 -142
  67. package/dist/cjs/math/index.cjs +0 -284
  68. package/dist/cjs/number/index.cjs +0 -14
  69. package/dist/cjs/object/index.cjs +0 -216
  70. package/dist/cjs/pagination/index.cjs +0 -140
  71. package/dist/cjs/random/index.cjs +0 -25
  72. package/dist/cjs/regexp/index.cjs +0 -109
  73. package/dist/cjs/storage/index.cjs +0 -11
  74. package/dist/cjs/storage/localStorage.cjs +0 -40
  75. package/dist/cjs/storage/sessionStorage.cjs +0 -40
  76. package/dist/cjs/string/index.cjs +0 -338
  77. package/dist/cjs/url/index.cjs +0 -279
  78. package/dist/cjs/validate/index.cjs +0 -487
  79. package/dist/cjs/weapp/index.cjs +0 -151
  80. package/dist/es/ID-card/index.mjs +0 -116
  81. package/dist/es/array/index.mjs +0 -437
  82. package/dist/es/clipboard/index.mjs +0 -129
  83. package/dist/es/color/index.mjs +0 -200
  84. package/dist/es/constants/date.mjs +0 -184
  85. package/dist/es/constants/lang.mjs +0 -11
  86. package/dist/es/constants/math.mjs +0 -11
  87. package/dist/es/constants/regexp.mjs +0 -55
  88. package/dist/es/constants/sort.mjs +0 -13
  89. package/dist/es/cookie/index.mjs +0 -65
  90. package/dist/es/crypto/aes/aes.mjs +0 -529
  91. package/dist/es/crypto/aes/index.mjs +0 -25
  92. package/dist/es/crypto/base32/base32.mjs +0 -381
  93. package/dist/es/crypto/base32/index.mjs +0 -39
  94. package/dist/es/crypto/base64/base64.mjs +0 -427
  95. package/dist/es/crypto/base64/index.mjs +0 -57
  96. package/dist/es/crypto/des/des.mjs +0 -1050
  97. package/dist/es/crypto/des/index.mjs +0 -27
  98. package/dist/es/crypto/md5/index.mjs +0 -22
  99. package/dist/es/crypto/md5/md5.mjs +0 -941
  100. package/dist/es/crypto/sha/sha1/index.mjs +0 -22
  101. package/dist/es/crypto/sha/sha1/sha1.mjs +0 -599
  102. package/dist/es/crypto/sha/sha256/index.mjs +0 -41
  103. package/dist/es/crypto/sha/sha256/sha256.mjs +0 -649
  104. package/dist/es/crypto/sha/sha3/index.mjs +0 -39
  105. package/dist/es/crypto/sha/sha3/sha3.mjs +0 -742
  106. package/dist/es/crypto/sha/sha512/index.mjs +0 -79
  107. package/dist/es/crypto/sha/sha512/sha512.mjs +0 -1177
  108. package/dist/es/crypto/sm/lib/asn1.mjs +0 -164
  109. package/dist/es/crypto/sm/lib/ec.mjs +0 -349
  110. package/dist/es/crypto/sm/lib/jsbn.mjs +0 -1630
  111. package/dist/es/crypto/sm/lib/sm3.mjs +0 -170
  112. package/dist/es/crypto/sm/lib/utils.mjs +0 -186
  113. package/dist/es/crypto/sm/sm2/index.mjs +0 -111
  114. package/dist/es/crypto/sm/sm2/sm2.mjs +0 -258
  115. package/dist/es/crypto/sm/sm3/index.mjs +0 -13
  116. package/dist/es/crypto/sm/sm3/sm3.mjs +0 -99
  117. package/dist/es/crypto/sm/sm4/index.mjs +0 -25
  118. package/dist/es/crypto/sm/sm4/sm4.mjs +0 -359
  119. package/dist/es/crypto/tea/index.mjs +0 -23
  120. package/dist/es/crypto/tea/tea.mjs +0 -211
  121. package/dist/es/date/index.mjs +0 -1262
  122. package/dist/es/desensitized/index.mjs +0 -69
  123. package/dist/es/device/index.mjs +0 -145
  124. package/dist/es/dom/index.mjs +0 -164
  125. package/dist/es/file/index.mjs +0 -323
  126. package/dist/es/function/index.mjs +0 -63
  127. package/dist/es/keycode/index.mjs +0 -139
  128. package/dist/es/math/index.mjs +0 -274
  129. package/dist/es/number/index.mjs +0 -12
  130. package/dist/es/object/index.mjs +0 -203
  131. package/dist/es/pagination/index.mjs +0 -134
  132. package/dist/es/random/index.mjs +0 -22
  133. package/dist/es/regexp/index.mjs +0 -98
  134. package/dist/es/storage/index.mjs +0 -9
  135. package/dist/es/storage/localStorage.mjs +0 -35
  136. package/dist/es/storage/sessionStorage.mjs +0 -35
  137. package/dist/es/string/index.mjs +0 -321
  138. package/dist/es/url/index.mjs +0 -261
  139. package/dist/es/validate/index.mjs +0 -451
  140. package/dist/es/weapp/index.mjs +0 -140
@@ -1,261 +0,0 @@
1
- import { REGEXP } from '../constants/regexp.mjs';
2
- import { isArray } from '../validate/index.mjs';
3
- import { arrayInsertBefore, arrayInsertAfter } from '../array/index.mjs';
4
-
5
- /**
6
- * 获得协议名
7
- * @param {String} url url地址,默认当前url地址
8
- * @returns {String} 返回协议名
9
- */
10
- function getProtocol(url = window.location.href) {
11
- let match = url.match(REGEXP.URL);
12
- if (match) {
13
- return match[1] || "";
14
- }
15
- }
16
-
17
- /**
18
- * 获得主机地址
19
- * @param {String} url url地址,默认当前url地址
20
- * @returns {String} 返回主机地址
21
- */
22
- function getHost(url = window.location.href) {
23
- let match = url.match(REGEXP.URL);
24
- if (match) {
25
- return (match[2] || "") + (match[3] ? ":" + match[3] : "");
26
- }
27
- }
28
-
29
- /**
30
- * 获得主机名称
31
- * @param {String} url url地址,默认当前url地址
32
- * @returns {String} 返回主机名称
33
- */
34
- function getHostName(url = window.location.href) {
35
- let match = url.match(REGEXP.URL);
36
- if (match) {
37
- return match[2] || "";
38
- }
39
- }
40
-
41
- /**
42
- * 获得端口号
43
- * @param {String} url url地址,默认当前url地址
44
- * @returns {String} 返回端口号
45
- */
46
- function getPort(url = window.location.href) {
47
- let match = url.match(REGEXP.URL);
48
- if (match) {
49
- return match[3] || "";
50
- }
51
- }
52
-
53
- /**
54
- * 获得地址路径
55
- * @param {String} url url地址,默认当前url地址
56
- * @returns {String} 返回地址路径
57
- */
58
- function getUrlPath(url = window.location.href) {
59
- let match = url.match(REGEXP.URL);
60
- if (match) {
61
- return match[4] || "";
62
- }
63
- }
64
-
65
- /**
66
- * 获得hash字符串
67
- * @param {String} url url地址,默认当前url地址
68
- * @returns {String} 返回hash字符串
69
- */
70
- function getUrlHash(url = window.location.href) {
71
- let match = url.match(REGEXP.URL);
72
- if (match) {
73
- return match[6] || "";
74
- }
75
- }
76
-
77
- /**
78
- * 获得查询参数字符串
79
- * @param {String} url url地址,默认当前url地址
80
- * @returns {String} 返回查询参数字符串
81
- */
82
- function getSearchString(url = window.location.href) {
83
- let match = url.match(REGEXP.URL);
84
- console.log(match);
85
- if (match) {
86
- return match[5] || "";
87
- }
88
- }
89
-
90
- /**
91
- * 查询参数字符串中获得某个参数的值
92
- * @param {String} name 参数名
93
- * @param {String} url url地址,默认当前url地址
94
- * @returns {String} 返回查询到的值
95
- */
96
- function getSearchParam(name, url = window.location.href) {
97
- name = name.replace(/[[\]]/g, "\\$&");
98
- url = getSearchString(url);
99
- let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
100
- let match = url.substring(0).match(reg);
101
- if (match) {
102
- return decodeURIComponent(match[2]);
103
- }
104
- }
105
-
106
- /**
107
- * 查询参数字符串中设置某个参数的值
108
- * @param {String} name 参数名
109
- * @param {String,Number,Array} value 参数值,如果是数组,则解析为:&ids[0]=1&ids[2]=2
110
- * @param {String} url url地址,默认当前url地址
111
- * @returns {String} 返回查询参数字符串
112
- */
113
- function setSearchParam(name, value, url = window.location.href) {
114
- let params = toSearchParam(url);
115
- params[name] = value;
116
-
117
- // 返回替换后的url
118
- return url.replace(/(\?.+?)(?=#|$)/, "?" + toSearchString(params));
119
- }
120
-
121
- /**
122
- * 查询参数字符串中是否包含某个参数
123
- * @param {String} name 参数名
124
- * @param {String} url url地址,默认当前url地址
125
- * @returns {Boolean} 返回结果
126
- */
127
- function hasSearchParam(name, url = window.location.href) {
128
- let params = toSearchParam(url);
129
- return params[name] !== undefined;
130
- }
131
-
132
- /**
133
- * 查询参数字符串中在最前面追加新参数和值
134
- * @param {String} name 参数名
135
- * @param {String,Number,Array} value 参数值,如果是数组,则解析为:&ids[0]=1&ids[2]=2
136
- * @param {String} url url地址,默认当前url地址
137
- * @returns {String} 返回查询参数字符串
138
- */
139
- function prependSearchParam(name, value, url = window.location.href) {
140
- let searchArr = getSearchString(url).split("&");
141
- if (isArray(value)) {
142
- let arr = [];
143
- for (let i = 0; i < value.length; i++) {
144
- arr.push(`${encodeURIComponent(name)}[${i}]=${encodeURIComponent(value[i])}`);
145
- }
146
- searchArr.unshift(...arr);
147
- } else {
148
- searchArr.unshift(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
149
- }
150
-
151
- return url.replace(/(\?.+?)(?=#|$)/, "?" + searchArr.join("&"));
152
- }
153
-
154
- /**
155
- * 查询参数字符串中在某个参数的前面追加新参数和值
156
- * @param {String} name 参数名
157
- * @param {String,Number,Array} value 参数值,如果是数组,则解析为:&ids[0]=1&ids[2]=2
158
- * @param {String} beforeParam 在前面追加参数的名称
159
- * @param {String} url url地址,默认当前url地址
160
- * @returns {String} 返回查询参数字符串
161
- */
162
- function prependToSearchParam(name, value, beforeParam, url = window.location.href) {
163
- let searchArr = getSearchString(url).split("&");
164
- let beforeIndex = searchArr.findIndex((v) => v.includes(beforeParam));
165
- let beforeArr = arrayInsertBefore(searchArr, beforeIndex, `${name}=${value}`);
166
-
167
- return url.replace(/(\?.+?)(?=#|$)/, "?" + beforeArr.join("&"));
168
- }
169
-
170
- /**
171
- * 查询参数字符串中在最后面追加新参数和值
172
- * @param {String} name 参数名
173
- * @param {String,Number,Array} value 参数值,如果是数组,则解析为:&ids[0]=1&ids[2]=2
174
- * @param {String} url url地址,默认当前url地址
175
- * @returns {String} 返回查询参数字符串
176
- */
177
- function appendSearchParam(name, value, url = window.location.href) {
178
- let searchArr = getSearchString(url).split("&");
179
- searchArr.push(`${name}=${value}`);
180
-
181
- return url.replace(/(\?.+?)(?=#|$)/, "?" + searchArr.join("&"));
182
- }
183
-
184
- /**
185
- * 查询参数字符串中在某个参数的后面追加新参数和值
186
- * @param {String} name 参数名
187
- * @param {String,Number,Array} value 参数值,如果是数组,则解析为:&ids[0]=1&ids[2]=2
188
- * @param {String} afterName 在后面追加参数的名称
189
- * @param {String} url url地址,默认当前url地址
190
- * @returns {String} 返回查询参数字符串
191
- */
192
- function appendToSearchParam(name, value, afterName, url = window.location.href) {
193
- let searchArr = getSearchString(url).split("&");
194
- let beforeIndex = searchArr.findIndex((v) => v.includes(afterName));
195
- let afterArr = arrayInsertAfter(searchArr, beforeIndex, `${name}=${value}`);
196
-
197
- return url.replace(/(\?.+?)(?=#|$)/, "?" + afterArr.join("&"));
198
- }
199
-
200
- /**
201
- * 查询参数字符串中移除某个参数和值
202
- * @param {String} name 参数名
203
- * @param {String} url url地址,默认当前url地址
204
- * @returns {String} 返回查询参数字符串
205
- */
206
- function removeSearchParam(name, url = window.location.href) {
207
- let searchArr = getSearchString(url).split("&");
208
- let delIndex = searchArr.findIndex((v) => v.includes(name));
209
- if (delIndex > -1) {
210
- searchArr.splice(delIndex, 1);
211
- }
212
-
213
- return url.replace(/(\?.+?)(?=#|$)/, "?" + searchArr.join("&"));
214
- }
215
-
216
- /**
217
- * 查询参数字符串转为对象
218
- * @param {String} url url地址,默认当前url地址
219
- * @returns {Object} 返回参数对象
220
- */
221
- function parseSearchParam(url = window.location.href) {
222
- let searchString = getSearchString(url);
223
- let searchArr = searchString.split("&");
224
- let param = {};
225
- for (let i = 0; i < searchArr.length; i++) {
226
- let arr = searchArr[i].split("=");
227
- param[decodeURIComponent(arr[0])] = decodeURIComponent(arr[1] || "");
228
- }
229
- return param;
230
- }
231
-
232
- /**
233
- * 对象转为查询参数字符串
234
- * @param {Object} params 参数对象
235
- * @param {String} url url地址,如果不为空,则会拼接好查询参数字符串的url地址
236
- * @returns {String} 返回查询参数字符串
237
- */
238
- function formatSearchString(params, url = undefined) {
239
- if (typeof params !== "object") return params;
240
-
241
- let arr = [];
242
- for (let key in params) {
243
- let value = params[key];
244
- if (isArray(value)) {
245
- for (let i = 0; i < value.length; ++i) {
246
- arr.push(encodeURIComponent(key + "[" + i + "]") + "=" + encodeURIComponent(value[i]));
247
- }
248
- } else {
249
- arr.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
250
- }
251
- }
252
-
253
- // 如果url不为空,则会返回拼接好url字符串
254
- if (url) {
255
- return url.replace(/(\?.+?)(?=#|$)/, "?" + arr.join("&"));
256
- } else {
257
- return arr.join("&");
258
- }
259
- }
260
-
261
- export { appendSearchParam, appendToSearchParam, formatSearchString, getHost, getHostName, getPort, getProtocol, getSearchParam, getSearchString, getUrlHash, getUrlPath, hasSearchParam, parseSearchParam, prependSearchParam, prependToSearchParam, removeSearchParam, setSearchParam };
@@ -1,451 +0,0 @@
1
- /**
2
- * 判断是整数
3
- * @param {*} value 参数
4
- * @returns {Boolean} result 返回结果
5
- */
6
- function isInteger(value) {
7
- return Number.isInteger(value);
8
- }
9
-
10
- /**
11
- * 判断是小数
12
- * @param {*} value 参数
13
- * @returns {Boolean} result 返回结果
14
- */
15
- function isDecimal(value) {
16
- return /^\d+\.\d+$/.test(value);
17
- }
18
-
19
- /**
20
- * 判断类型是数字 Number
21
- * @param {Number} value 参数
22
- * @returns {Boolean} 返回结果
23
- */
24
- function isNumber(value) {
25
- return Object.prototype.toString.call(value).slice(8, -1) === "Number";
26
- }
27
-
28
- /**
29
- * 判断类型是字符串 String
30
- * @param {*} value 参数
31
- * @returns {Boolean} 返回结果
32
- */
33
- function isString(value) {
34
- return Object.prototype.toString.call(value).slice(8, -1) === "String";
35
- }
36
-
37
- /**
38
- * 判断类型是数组 Array
39
- * @param {*} value 参数
40
- * @returns {Boolean} 返回结果
41
- */
42
- function isArray(value) {
43
- return Object.prototype.toString.call(value).slice(8, -1) === "Array";
44
- }
45
-
46
- /**
47
- * 判断类型是对象 Object
48
- * @param {*} value 参数
49
- * @returns {Boolean} 返回结果
50
- */
51
- function isObject(value) {
52
- return Object.prototype.toString.call(value).slice(8, -1) === "Object";
53
- }
54
-
55
- /**
56
- * 判断类型是布尔 Boolean
57
- * @param {*} value 参数
58
- * @returns {Boolean} 返回结果
59
- */
60
- function isBoolean(value) {
61
- return Object.prototype.toString.call(value).slice(8, -1) === "Boolean";
62
- }
63
-
64
- /**
65
- * 判断类型是日期 Date
66
- * @param {*} value 参数
67
- * @returns {Boolean} 返回结果
68
- */
69
- function isDate(value) {
70
- return Object.prototype.toString.call(value).slice(8, -1) === "Date";
71
- }
72
-
73
- /**
74
- * 判断类型是函数 Function
75
- * @param {*} value 参数
76
- * @returns {Boolean} 返回结果
77
- */
78
- function isFunction(value) {
79
- return Object.prototype.toString === "Function";
80
- }
81
-
82
- /**
83
- * 判断类型是异步函数 AsyncFunction
84
- * @param {*} value 参数
85
- * @returns {Boolean} 返回结果
86
- */
87
- function isAsyncFunction(value) {
88
- return Object.prototype.toString.call(value).slice(8, -1) === "AsyncFunction";
89
- }
90
-
91
- /**
92
- * 判断类型是 Symbol
93
- * @param {*} value 参数
94
- * @returns {Boolean} 返回结果
95
- */
96
- function isSymbol(value) {
97
- return Object.prototype.toString.call(value).slice(8, -1) === "Symbol";
98
- }
99
-
100
- /**
101
- * 判断类型是正则 RegExp
102
- * @param {*} value 参数
103
- * @returns {Boolean} 返回结果
104
- */
105
- function isRegExp(value) {
106
- return Object.prototype.toString.call(value).slice(8, -1) === "RegExp";
107
- }
108
-
109
- /**
110
- * 判断类型是错误 Error
111
- * @param {*} value 参数
112
- * @returns {Boolean} 返回结果
113
- */
114
- function isError(value) {
115
- return Object.prototype.toString.call(value).slice(8, -1) === "Error";
116
- }
117
-
118
- /**
119
- * 判断类型是 Promise
120
- * @param {*} value 参数
121
- * @returns {Boolean} 返回结果
122
- */
123
- function isPromise(value) {
124
- return Object.prototype.toString.call(value).slice(8, -1) === "Promise";
125
- }
126
-
127
- /**
128
- *判断类型是 Map
129
- * @param {*} value 参数
130
- * @returns {Boolean} 返回结果
131
- */
132
- function isMap(value) {
133
- return Object.prototype.toString.call(value).slice(8, -1) === "Map";
134
- }
135
-
136
- /**
137
- * 判断类型是 WeakMap
138
- * @param {*} value 参数
139
- * @returns {Boolean} 返回结果
140
- */
141
- function isWeakMap(value) {
142
- return Object.prototype.toString.call(value).slice(8, -1) === "WeakMap";
143
- }
144
-
145
- /**
146
- * 判断类型是 Set
147
- * @param {*} value 参数
148
- * @returns {Boolean} 返回结果
149
- */
150
- function isSet(value) {
151
- return Object.prototype.toString.call(value).slice(8, -1) === "Set";
152
- }
153
-
154
- /**
155
- * 判断类型是 WeakSet
156
- * @param {*} value 参数
157
- * @returns {Boolean} 返回结果
158
- */
159
- function isWeakSet(value) {
160
- return Object.prototype.toString.call(value).slice(8, -1) === "WeakSet";
161
- }
162
-
163
- /**
164
- * 判断类型是 BigInt
165
- * @param {*} value 参数
166
- * @returns {Boolean} 返回结果
167
- */
168
- function isBigInt(value) {
169
- return Object.prototype.toString.call(value).slice(8, -1) === "BigInt";
170
- }
171
-
172
- /**
173
- * 判断类型是 Json
174
- * @param {*} value 参数
175
- * @returns {Boolean} 返回结果
176
- */
177
- function isJson(value) {
178
- try {
179
- JSON.parse(value);
180
- return true;
181
- } catch (error) {
182
- return false;
183
- }
184
- }
185
-
186
- /* 数据值校验 */
187
- /**
188
- * 判断值为真
189
- * @param {*} value 校验的参数
190
- * @returns {Boolean} 返回结果
191
- */
192
- function isTrue(value) {
193
- return !isFalse(value);
194
- }
195
-
196
- /**
197
- * 判断值为假
198
- * @param {*} value 校验的参数
199
- * @returns {Boolean} 返回结果
200
- */
201
- function isFalse(value) {
202
- return (
203
- value === undefined ||
204
- value === null ||
205
- value === "undefined" ||
206
- value === "null" ||
207
- value === 0 ||
208
- value === false ||
209
- value === NaN
210
- );
211
- }
212
-
213
- /**
214
- * 判断非数字
215
- * @param {*} value 参数
216
- * @returns {Boolean} 返回结果
217
- */
218
- function isNaN(value) {
219
- // window的isNaN函数是有缺陷的,空数组/数组有一个元素,null,空字符串 都会被认为是数字
220
- return window.isNaN(value) || isArray(value) || value == null || value === "";
221
- }
222
-
223
- /**
224
- * 判断是数字
225
- * @description 等同于isNumber()
226
- * @param {*} value 参数
227
- * @returns {Boolean} 返回结果
228
- */
229
- function isNotNaN(value) {
230
- return !isNaN(value);
231
- }
232
-
233
- /**
234
- * 判断对象为空
235
- * @description 判断值是否为空,如果对象初始化了值则不为空
236
- * @param {*} value 校验的参数
237
- * @returns {Boolean} 返回结果
238
- */
239
- function isNull(value) {
240
- return value === undefined || value === null || value === "";
241
- }
242
-
243
- /**
244
- * 判断对象不为空
245
- * @description 判断值是否为空,如果对象初始化了值则不为空
246
- * @param {*} value 校验的参数
247
- * @returns {Boolean} 返回结果
248
- */
249
- function isNotNull(value) {
250
- return !isNull(value);
251
- }
252
-
253
- /**
254
- * 判断值为空
255
- * @description 判断是否是有意义不为空的值,如果值是{},[]空的数据则为空
256
- * @param {*} value 校验的参数
257
- * @returns {Boolean} 返回结果
258
- */
259
- function isEmpty(value) {
260
- return isNull(value) || !(Object.keys(value) || value).length;
261
- }
262
-
263
- /**
264
- * 判断值不为空
265
- * @description 判断是否是有意义不为空的值,如果值是{},[]空的数据则为空
266
- * @param {*} value 校验的参数
267
- * @returns {Boolean} 返回结果
268
- */
269
- function isNotEmpty(value) {
270
- return !isEmpty(value);
271
- }
272
-
273
- /**
274
- * 判断值是空白的
275
- * @description 同时会校验空值,空对象,以及空白符号
276
- * @param {*} value 校验的参数
277
- * @returns {Boolean} 返回结果
278
- */
279
- function isBlank(value) {
280
- return isEmpty(value) || /^\s*$/.test(value);
281
- }
282
-
283
- /**
284
- * 判断值不是空白的
285
- * @description 同时会校验空值,空对象,以及空白符号
286
- * @param {*} value 校验的参数
287
- * @returns {Boolean} 返回结果
288
- */
289
- function isNotBlank(value) {
290
- return !isBlank(value);
291
- }
292
-
293
- /**
294
- * 判断值是undefined
295
- * @param {*} value 校验的参数
296
- * @returns {Boolean} 返回结果
297
- */
298
- function isUndefined(value) {
299
- return value === undefined;
300
- }
301
-
302
- /**
303
- * 判断值不是undefined
304
- * @param {*} value 校验的参数
305
- * @returns {Boolean} 返回结果
306
- */
307
- function isNotUndefined(value) {
308
- return !isUndefined(value);
309
- }
310
-
311
- /* 数据比较 */
312
- /**
313
- * 判断两个值是否相等
314
- * @param {String|Number} value1 参数1
315
- * @param {String|Number} value2 参数2
316
- * @returns {Boolean} 返回结果
317
- */
318
- function equals(value1, value2) {
319
- return Object.is(value1, value2);
320
- }
321
-
322
- /**
323
- * 判断两个值是否相等(忽略大小写)
324
- * @param {String|Number} value1 参数1
325
- * @param {String|Number} value2 参数2
326
- * @returns {Boolean} 返回结果
327
- */
328
- function equalsIgnoreCase(value1, value2) {
329
- return Object.is(value1.toLowerCase(), value2.toLowerCase());
330
- }
331
-
332
- /**
333
- * 深度对比数据
334
- * @description 可以对比任意数据,对象,数组,日期等也可深度对比,对象不区分先后顺序
335
- * @param {*} x 数据1
336
- * @param {*} y 数据2
337
- * @returns {Boolean} 返回结果
338
- */
339
- function deepCompare(x, y) {
340
- let i, l, leftChain, rightChain;
341
-
342
- function compare2Objects(x, y) {
343
- let p;
344
-
345
- // remember that NaN === NaN returns false
346
- // and isNaN(undefined) returns true
347
- if (isNaN(x) && isNaN(y) && typeof x === "number" && typeof y === "number") {
348
- return true;
349
- }
350
-
351
- // Compare primitives and functions.
352
- // Check if both arguments link to the same object.
353
- // Especially useful on the step where we compare prototypes
354
- if (x === y) {
355
- return true;
356
- }
357
-
358
- // Works in case when functions are created in constructor.
359
- // Comparing dates is a common scenario. Another built-ins?
360
- // We can even handle functions passed across iframes
361
- if (
362
- (typeof x === "function" && typeof y === "function") ||
363
- (x instanceof Date && y instanceof Date) ||
364
- (x instanceof RegExp && y instanceof RegExp) ||
365
- (x instanceof String && y instanceof String) ||
366
- (x instanceof Number && y instanceof Number)
367
- ) {
368
- return x.toString() === y.toString();
369
- }
370
-
371
- // At last checking prototypes as good as we can
372
- if (!(x instanceof Object && y instanceof Object)) {
373
- return false;
374
- }
375
-
376
- if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
377
- return false;
378
- }
379
-
380
- if (x.constructor !== y.constructor) {
381
- return false;
382
- }
383
-
384
- if (x.prototype !== y.prototype) {
385
- return false;
386
- }
387
-
388
- // Check for infinitive linking loops
389
- if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
390
- return false;
391
- }
392
-
393
- // Quick checking of one object being a subset of another.
394
- for (p in y) {
395
- if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
396
- return false;
397
- } else if (typeof y[p] !== typeof x[p]) {
398
- return false;
399
- }
400
- }
401
-
402
- for (p in x) {
403
- if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
404
- return false;
405
- } else if (typeof y[p] !== typeof x[p]) {
406
- return false;
407
- }
408
-
409
- switch (typeof x[p]) {
410
- case "object":
411
- case "function":
412
- leftChain.push(x);
413
- rightChain.push(y);
414
-
415
- if (!compare2Objects(x[p], y[p])) {
416
- return false;
417
- }
418
-
419
- leftChain.pop();
420
- rightChain.pop();
421
- break;
422
-
423
- default:
424
- if (x[p] !== y[p]) {
425
- return false;
426
- }
427
- break;
428
- }
429
- }
430
-
431
- return true;
432
- }
433
-
434
- if (arguments.length < 1) {
435
- return true; // Die silently? Don't know how to handle such case, please help...
436
- // throw "Need two or more arguments to compare";
437
- }
438
-
439
- for (i = 1, l = arguments.length; i < l; i++) {
440
- leftChain = [];
441
- rightChain = [];
442
-
443
- if (!compare2Objects(arguments[0], arguments[i])) {
444
- return false;
445
- }
446
- }
447
-
448
- return true;
449
- }
450
-
451
- export { deepCompare, equals, equalsIgnoreCase, isArray, isAsyncFunction, isBigInt, isBlank, isBoolean, isDate, isDecimal, isEmpty, isError, isFalse, isFunction, isInteger, isJson, isMap, isNaN, isNotBlank, isNotEmpty, isNotNaN, isNotNull, isNotUndefined, isNull, isNumber, isObject, isPromise, isRegExp, isSet, isString, isSymbol, isTrue, isUndefined, isWeakMap, isWeakSet };