tools-min-ns 1.5.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 (162) hide show
  1. package/README.md +85 -0
  2. package/esm/array/ArrayUtil.d.ts +109 -0
  3. package/esm/array/ArrayUtil.js +242 -0
  4. package/esm/array/TreeUtil.d.ts +151 -0
  5. package/esm/array/TreeUtil.js +412 -0
  6. package/esm/base/BaseUtil.d.ts +91 -0
  7. package/esm/base/BaseUtil.js +148 -0
  8. package/esm/browser/BrowserUtil.d.ts +57 -0
  9. package/esm/browser/BrowserUtil.js +337 -0
  10. package/esm/browser/fingerprint.d.ts +120 -0
  11. package/esm/browser/fingerprint.js +1469 -0
  12. package/esm/check/CheckUtil.d.ts +110 -0
  13. package/esm/check/CheckUtil.js +465 -0
  14. package/esm/common.d.ts +43 -0
  15. package/esm/common.js +44 -0
  16. package/esm/config.d.ts +7 -0
  17. package/esm/config.js +7 -0
  18. package/esm/cookie/CookieUtil.d.ts +56 -0
  19. package/esm/cookie/CookieUtil.js +12 -0
  20. package/esm/cookie/cookie.d.ts +2 -0
  21. package/esm/cookie/cookie.js +104 -0
  22. package/esm/date/DateUtil.d.ts +261 -0
  23. package/esm/date/DateUtil.js +763 -0
  24. package/esm/env/EnvUtil.d.ts +27 -0
  25. package/esm/env/EnvUtil.js +29 -0
  26. package/esm/env/env.d.ts +41 -0
  27. package/esm/env/env.js +106 -0
  28. package/esm/func/FunctionUtil.d.ts +77 -0
  29. package/esm/func/FunctionUtil.js +215 -0
  30. package/esm/index.d.ts +19 -0
  31. package/esm/index.js +19 -0
  32. package/esm/number/NumberUtil.d.ts +96 -0
  33. package/esm/number/NumberUtil.js +256 -0
  34. package/esm/object/ObjectUtil.d.ts +41 -0
  35. package/esm/object/ObjectUtil.js +158 -0
  36. package/esm/pwd/PasswordUtil.d.ts +33 -0
  37. package/esm/pwd/PasswordUtil.js +68 -0
  38. package/esm/pwd/crypto.d.ts +6 -0
  39. package/esm/pwd/crypto.js +1824 -0
  40. package/esm/request/RequestUtil.d.ts +52 -0
  41. package/esm/request/RequestUtil.js +53 -0
  42. package/esm/request/jsonp.d.ts +18 -0
  43. package/esm/request/jsonp.js +73 -0
  44. package/esm/request/mgop/env.d.ts +7 -0
  45. package/esm/request/mgop/env.js +15 -0
  46. package/esm/request/mgop/index.d.ts +3 -0
  47. package/esm/request/mgop/index.js +276 -0
  48. package/esm/request/mgop/responseCode.d.ts +20 -0
  49. package/esm/request/mgop/responseCode.js +37 -0
  50. package/esm/request/mgop/type.d.ts +34 -0
  51. package/esm/request/mgop/type.js +1 -0
  52. package/esm/request/uniRquest/index.d.ts +2 -0
  53. package/esm/request/uniRquest/index.js +66 -0
  54. package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
  55. package/esm/request/uniRquest/miniapp/index.js +29 -0
  56. package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  57. package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
  58. package/esm/request/uniRquest/types.d.ts +65 -0
  59. package/esm/request/uniRquest/types.js +36 -0
  60. package/esm/request/uniRquest/utils.d.ts +9 -0
  61. package/esm/request/uniRquest/utils.js +69 -0
  62. package/esm/request/uniRquest/web/index.d.ts +2 -0
  63. package/esm/request/uniRquest/web/index.js +85 -0
  64. package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  65. package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
  66. package/esm/request/uniRquest/weex/index.d.ts +14 -0
  67. package/esm/request/uniRquest/weex/index.js +59 -0
  68. package/esm/storage/StorageUtil.d.ts +19 -0
  69. package/esm/storage/StorageUtil.js +75 -0
  70. package/esm/string/StringUtil.d.ts +392 -0
  71. package/esm/string/StringUtil.js +556 -0
  72. package/esm/system/SystemUtil.d.ts +46 -0
  73. package/esm/system/SystemUtil.js +122 -0
  74. package/esm/transfer/MapTransferUtil.d.ts +54 -0
  75. package/esm/transfer/MapTransferUtil.js +160 -0
  76. package/esm/transfer/TransferUtil.d.ts +98 -0
  77. package/esm/transfer/TransferUtil.js +323 -0
  78. package/esm/types.d.ts +25 -0
  79. package/esm/types.js +1 -0
  80. package/esm/url/UrlUtil.d.ts +30 -0
  81. package/esm/url/UrlUtil.js +85 -0
  82. package/lib/array/ArrayUtil.d.ts +109 -0
  83. package/lib/array/ArrayUtil.js +252 -0
  84. package/lib/array/TreeUtil.d.ts +151 -0
  85. package/lib/array/TreeUtil.js +422 -0
  86. package/lib/base/BaseUtil.d.ts +91 -0
  87. package/lib/base/BaseUtil.js +153 -0
  88. package/lib/browser/BrowserUtil.d.ts +57 -0
  89. package/lib/browser/BrowserUtil.js +347 -0
  90. package/lib/browser/fingerprint.d.ts +120 -0
  91. package/lib/browser/fingerprint.js +1500 -0
  92. package/lib/check/CheckUtil.d.ts +110 -0
  93. package/lib/check/CheckUtil.js +475 -0
  94. package/lib/common.d.ts +43 -0
  95. package/lib/common.js +50 -0
  96. package/lib/config.d.ts +7 -0
  97. package/lib/config.js +12 -0
  98. package/lib/cookie/CookieUtil.d.ts +56 -0
  99. package/lib/cookie/CookieUtil.js +22 -0
  100. package/lib/cookie/cookie.d.ts +2 -0
  101. package/lib/cookie/cookie.js +109 -0
  102. package/lib/date/DateUtil.d.ts +261 -0
  103. package/lib/date/DateUtil.js +773 -0
  104. package/lib/env/EnvUtil.d.ts +27 -0
  105. package/lib/env/EnvUtil.js +39 -0
  106. package/lib/env/env.d.ts +41 -0
  107. package/lib/env/env.js +112 -0
  108. package/lib/func/FunctionUtil.d.ts +77 -0
  109. package/lib/func/FunctionUtil.js +225 -0
  110. package/lib/index.d.ts +19 -0
  111. package/lib/index.js +144 -0
  112. package/lib/number/NumberUtil.d.ts +96 -0
  113. package/lib/number/NumberUtil.js +266 -0
  114. package/lib/object/ObjectUtil.d.ts +41 -0
  115. package/lib/object/ObjectUtil.js +168 -0
  116. package/lib/pwd/PasswordUtil.d.ts +33 -0
  117. package/lib/pwd/PasswordUtil.js +78 -0
  118. package/lib/pwd/crypto.d.ts +6 -0
  119. package/lib/pwd/crypto.js +1829 -0
  120. package/lib/request/RequestUtil.d.ts +52 -0
  121. package/lib/request/RequestUtil.js +94 -0
  122. package/lib/request/jsonp.d.ts +18 -0
  123. package/lib/request/jsonp.js +80 -0
  124. package/lib/request/mgop/env.d.ts +7 -0
  125. package/lib/request/mgop/env.js +21 -0
  126. package/lib/request/mgop/index.d.ts +3 -0
  127. package/lib/request/mgop/index.js +289 -0
  128. package/lib/request/mgop/responseCode.d.ts +20 -0
  129. package/lib/request/mgop/responseCode.js +42 -0
  130. package/lib/request/mgop/type.d.ts +34 -0
  131. package/lib/request/mgop/type.js +5 -0
  132. package/lib/request/uniRquest/index.d.ts +2 -0
  133. package/lib/request/uniRquest/index.js +77 -0
  134. package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
  135. package/lib/request/uniRquest/miniapp/index.js +35 -0
  136. package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
  137. package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
  138. package/lib/request/uniRquest/types.d.ts +65 -0
  139. package/lib/request/uniRquest/types.js +42 -0
  140. package/lib/request/uniRquest/utils.d.ts +9 -0
  141. package/lib/request/uniRquest/utils.js +83 -0
  142. package/lib/request/uniRquest/web/index.d.ts +2 -0
  143. package/lib/request/uniRquest/web/index.js +91 -0
  144. package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
  145. package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
  146. package/lib/request/uniRquest/weex/index.d.ts +14 -0
  147. package/lib/request/uniRquest/weex/index.js +65 -0
  148. package/lib/storage/StorageUtil.d.ts +19 -0
  149. package/lib/storage/StorageUtil.js +85 -0
  150. package/lib/string/StringUtil.d.ts +392 -0
  151. package/lib/string/StringUtil.js +566 -0
  152. package/lib/system/SystemUtil.d.ts +46 -0
  153. package/lib/system/SystemUtil.js +132 -0
  154. package/lib/transfer/MapTransferUtil.d.ts +54 -0
  155. package/lib/transfer/MapTransferUtil.js +165 -0
  156. package/lib/transfer/TransferUtil.d.ts +98 -0
  157. package/lib/transfer/TransferUtil.js +333 -0
  158. package/lib/types.d.ts +25 -0
  159. package/lib/types.js +5 -0
  160. package/lib/url/UrlUtil.d.ts +30 -0
  161. package/lib/url/UrlUtil.js +95 -0
  162. package/package.json +56 -0
@@ -0,0 +1,556 @@
1
+ /**
2
+ * 字符串工具
3
+ * @description
4
+ * @author nanshen
5
+ * @creat 2021-09-15 14:24:25
6
+ */
7
+ import BaseUtil from '../base/BaseUtil';
8
+ var isEmpty = BaseUtil.isEmpty;
9
+ var StringUtil;
10
+ (function (StringUtil) {
11
+ /**
12
+ * 判断字符串是否不为空
13
+ * @param {String} input 输入字符串,如'我是测试的字符串'
14
+ * @example
15
+ * isNotEmpty('我是测试的字符串'); => true
16
+ * isNotEmpty(''); => false
17
+ */
18
+ StringUtil.isNotEmpty = function (input) {
19
+ return !isEmpty(input);
20
+ };
21
+ /**
22
+ * 将字符串去除空格
23
+ * @param {string} input 输入字符串,如'我是测 试的字符串'
24
+ * @returns {string} 去除空格后的字符串
25
+ * @example
26
+ * trim(' 测试字符串 '); => 测试字符串
27
+ * trim('我是测 试的字符串'); => 我是测试的字符串
28
+ */
29
+ StringUtil.trim = function (input) {
30
+ return input.replace(/\s+/g, '');
31
+ };
32
+ /**
33
+ * 判断字符串是否以某个字符串开头
34
+ * @param {string} input 输入字符串,如' abcdefg'
35
+ * @param {string} prefix 输入字符串,如'ab'
36
+ * @example
37
+ * startsWith('abcdefg','ab'); => true
38
+ * startsWith('abcdefg','bc'); => false
39
+ * startsWith('abcdefg','a'); => true
40
+ */
41
+ StringUtil.startsWith = function (input, prefix) {
42
+ return input.indexOf(prefix) === 0;
43
+ };
44
+ /**
45
+ * 判断字符串是否以某个字符串结束
46
+ * @param {String} input 输入字符串,如' abcdefg '
47
+ * @param {string} suffix 输入字符串,如'fg'
48
+ * @examplec
49
+ * endsWith('abcdefg', 'fg'); => true
50
+ * endsWith('abcdefg', 'ef'); => false
51
+ * endsWith('abcdefg', 'g'); => true
52
+ */
53
+ StringUtil.endsWith = function (input, suffix) {
54
+ return input.endsWith(suffix);
55
+ };
56
+ /**
57
+ * 判断字符串是否包含某个字符串
58
+ * @param {String} input 输入字符串,如'abcdefg'
59
+ * @param {string} searchSeq 输入字符串,如'abc'
60
+ * @example
61
+ * contains('abcdefg', 'abc'); => true
62
+ * contains('abcdefg', 'gh'); => false
63
+ * contains('abcdefg', 'a'); => true
64
+ */
65
+ StringUtil.contains = function (input, searchSeq) {
66
+ return input.indexOf(searchSeq) >= 0;
67
+ };
68
+ /**
69
+ * 忽略大小写判断两个字符串是否相等
70
+ * @param {String} input1 输入字符串,如'equalsIgnoreCasE',
71
+ * @param {String} input2 输入字符串,如'equalsIgnoreCase'
72
+ * @example
73
+ * equalsIgnoreCase('equalsIgnoreCasE', 'equalsIgnoreCase'); => true
74
+ * equalsIgnoreCase('equals ', 'equalsIgnoreCase'); => false
75
+ */
76
+ StringUtil.equalsIgnoreCase = function (input1, input2) {
77
+ return input2.toLocaleLowerCase() === input1.toLocaleLowerCase();
78
+ };
79
+ /**
80
+ * 判断字符串是否含有空格
81
+ * @param {String} input 输入字符串,如'我是 测试 的 字符串'
82
+ * @example
83
+ * containsWhitespace('我是 测试 的 字符串 '); => true
84
+ * containsWhitespace('我是测试的字符串'); => false
85
+ * containsWhitespace(' 我是测试的字符串 '); => true
86
+ */
87
+ StringUtil.containsWhitespace = function (input) {
88
+ return /\s/.test(input);
89
+ };
90
+ /**
91
+ * 按指定数量生成给定字符串字符
92
+ * @param {string|number} ch 输入字符串,如'我是测试的字符串', 或 输入数字如 220022
93
+ * @param {number} repeatTimes 输入数字,如 '6'
94
+ * @returns {string} 指定数量的给定字符串
95
+ * @example
96
+ * repeat('AB ',6); => 'AB AB AB AB AB AB '
97
+ * repeat('C D',3); => 'C DC DC D'
98
+ * repeat('20', 3); => '202020'
99
+ */
100
+ StringUtil.repeat = function (ch, repeatTimes) {
101
+ var result = '';
102
+ for (var i = 0; i < repeatTimes; i++) {
103
+ result += ch;
104
+ }
105
+ return result;
106
+ };
107
+ /**
108
+ * 去除字符串中的空格
109
+ * @param {string} input 输入字符串,如'我是 测试 的 字符串 '
110
+ * @returns {string} 去除空格后的字符串
111
+ * @example
112
+ * deleteWhitespace('我是 测试 的 字符串 '); => '我是测试的字符串'
113
+ * deleteWhitespace(''); => ''
114
+ */
115
+ StringUtil.deleteWhitespace = function (input) {
116
+ return input.replace(/\s+/g, '');
117
+ };
118
+ /**
119
+ * 将给定字符串进行右侧填充
120
+ * @param {string|number} input 输入字符串
121
+ * @param {number} size 输入数量
122
+ * @param {string|number } padStr 输入填充字符
123
+ * @example
124
+ * rightPad(2222, 1, 33); => '222233'
125
+ * rightPad('我是测试的字符串', 2, '--'); => '我是测试的字符串----'
126
+ */
127
+ StringUtil.rightPad = function (input, size, padStr) {
128
+ return input + StringUtil.repeat(padStr, size);
129
+ };
130
+ /**
131
+ * 将给定字符进行左侧填充
132
+ * @param {string|number} input 输入字符串
133
+ * @param {number} size 输入数量
134
+ * @param {string|number} padStr 输入填充字符
135
+ * @returns {string} 左侧填充后的字符串
136
+ * @example
137
+ * leftPad('我是测试的字符串', 2, '--'); => '----我是测试的字符串'
138
+ * leftPad(2222, 2, 3); => '332222'
139
+ */
140
+ StringUtil.leftPad = function (input, size, padStr) {
141
+ return StringUtil.repeat(padStr, size) + input;
142
+ };
143
+ /**
144
+ * 将字符串首字母转大写
145
+ * @param {string} input 输入字符串
146
+ * @example
147
+ * capitalize('admin'); => 'Admin'
148
+ * capitalize('capitalize'); => 'Capitalize'
149
+ */
150
+ StringUtil.capitalize = function (input) {
151
+ return input.replace(input[0], input[0].toUpperCase());
152
+ };
153
+ /**
154
+ * 将字符串首字母转小写
155
+ * @param {string} input 输入字符串
156
+ * @example
157
+ * unCapitalize('Capitalize'); => 'capitalize'
158
+ * unCapitalize('SetTimeout'); => 'setTimeout'
159
+ */
160
+ StringUtil.unCapitalize = function (input) {
161
+ return input.replace(input[0], input[0].toLowerCase());
162
+ };
163
+ /**
164
+ * 将字符串中的字母大写转小写,小写转大写
165
+ * @param {string} input 输入字符串
166
+ * @example
167
+ * swapCase('aBcde'); => 'AbCDE'
168
+ * swapCase('ABCDe'); => 'abcdE'
169
+ */
170
+ StringUtil.swapCase = function (input) {
171
+ return input.replace(/[a-z]/gi, function (matchStr) {
172
+ if (matchStr >= 'A' && matchStr <= 'Z') {
173
+ return matchStr.toLocaleLowerCase();
174
+ } else if (matchStr >= 'a' && matchStr <= 'z') {
175
+ return matchStr.toLocaleUpperCase();
176
+ }
177
+ return matchStr;
178
+ });
179
+ };
180
+ /**
181
+ * 统计含有的子字符串的个数
182
+ * @param {string} input 输入字符串
183
+ * @param {string} sub 输入子字符串
184
+ * @example
185
+ * countMatches('dabddadb', 'da'); => 2
186
+ * countMatches('abcdeabcdeabcde','ab'); => 3
187
+ */
188
+ StringUtil.countMatches = function (input, sub) {
189
+ if (isEmpty(input) || isEmpty(sub)) {
190
+ return 0;
191
+ }
192
+ var count = 0;
193
+ var index = 0;
194
+ while ((index = input.indexOf(sub, index)) !== -1) {
195
+ index = input.indexOf(sub, index) + sub.length;
196
+ count++;
197
+ }
198
+ return count;
199
+ };
200
+ /**
201
+ * 判断字符串是否为字母
202
+ * @param {string} input 输入字符串
203
+ * @example
204
+ * isAlpha('abce测试'); => false
205
+ * isAlpha('abcdeabcdeabcde'); => true
206
+ */
207
+ StringUtil.isAlpha = function (input) {
208
+ return /^[a-z]+$/i.test(input);
209
+ };
210
+ /**
211
+ * 判断字符串是否为字母、空格
212
+ * @param {string} input 输入字符串
213
+ * @example
214
+ * isAlphaSpace(' abc 测试 '); => false
215
+ * isAlphaSpace('abcd eabc deab cde'); => true
216
+ */
217
+ StringUtil.isAlphaSpace = function (input) {
218
+ return /^[a-z\s]*$/i.test(input);
219
+ };
220
+ /**
221
+ * 判断字符串是否为字母、数字
222
+ * @param {string} input 输入字符串
223
+ * @example
224
+ * isAlphanumeric('abcd串abcd'); => false
225
+ * isAlphanumeric('22abcdeabcdeabcde22'); => true
226
+ */
227
+ StringUtil.isAlphanumeric = function (input) {
228
+ return /^[a-z0-9]+$/i.test(input);
229
+ };
230
+ /**
231
+ * 判断字符串是否为字母、数字和空格
232
+ * @param {string} input 输入字符串
233
+ * @example
234
+ * isAlphanumericSpace('我是测试的 222字符串'); => false
235
+ * isAlphanumericSpace('22abcde abcde abcde 22'); => true
236
+ */
237
+ StringUtil.isAlphanumericSpace = function (input) {
238
+ return /^[a-z0-9\s]*$/i.test(input);
239
+ };
240
+ /**
241
+ * 判断字符串是否为数字
242
+ * @param {string} input 输入数字
243
+ * @example
244
+ * isNumeric('我是测试的 字符串'); => false
245
+ * isNumeric(220022); => true
246
+ */
247
+ StringUtil.isNumeric = function (input) {
248
+ return /^(?:[1-9]\d*|0)(?:\.\d+)?$/.test(input);
249
+ };
250
+ /**
251
+ * 判断字符串是否为小数
252
+ * @param {string} input 输入数字
253
+ * @example
254
+ * isDecimal('220022'); => false
255
+ * isDecimal(22.0022); => true
256
+ */
257
+ StringUtil.isDecimal = function (input) {
258
+ return /^[-+]?(?:0|[1-9]\d*)\.\d+$/.test(input);
259
+ };
260
+ /**
261
+ * 判断字符串是否为负小数
262
+ * @param {number} input 输入数字
263
+ * @example
264
+ * isNegativeDecimal('22.0022'); => false
265
+ * isNegativeDecimal('-22.0022'); => true
266
+ */
267
+ StringUtil.isNegativeDecimal = function (input) {
268
+ return /^\-?(?:0|[1-9]\d*)\.\d+$/.test(input);
269
+ };
270
+ /**
271
+ * 判断字符串是否为正小数
272
+ * @param {string} input 输入数字
273
+ * @example
274
+ * isPositiveDecimal('22.0022'); => true
275
+ * isPositiveDecimal('-22.0022'); => false
276
+ */
277
+ StringUtil.isPositiveDecimal = function (input) {
278
+ return /^\+?(?:0|[1-9]\d*)\.\d+$/.test(input);
279
+ };
280
+ /**
281
+ * 判断字符串是否为整数
282
+ * @param {string} input 输入数字
283
+ * @example
284
+ * isInteger('-220022'); => true
285
+ * isInteger('22.0022'); => false
286
+ */
287
+ StringUtil.isInteger = function (input) {
288
+ return /^[-+]?(?:0|[1-9]\d*)$/.test(input);
289
+ };
290
+ /**
291
+ * 判断字符串是否为正整数
292
+ * @param {string} input 输入数字
293
+ * @example
294
+ * isPositiveInteger('220022'); => true
295
+ * isPositiveInteger('-22.22'); => false
296
+ */
297
+ StringUtil.isPositiveInteger = function (input) {
298
+ return /^\+?(?:0|[1-9]\d*)$/.test(input);
299
+ };
300
+ /**
301
+ * 判断字符串是否为负整数
302
+ * @param {string} input 输入数字
303
+ * @example
304
+ * isNegativeInteger('-220022'); => true
305
+ * isNegativeInteger('22.22'); => false
306
+ */
307
+ StringUtil.isNegativeInteger = function (input) {
308
+ return /^\-?(?:0|[1-9]\d*)$/.test(input);
309
+ };
310
+ /**
311
+ * 判断字符串是否为数字、空格
312
+ * @param {string} input 输入字符串
313
+ * @example
314
+ * isNumericSpace('2 2 0 0 2 2'); => true
315
+ * isNumericSpace('2222aa'); => false
316
+ */
317
+ StringUtil.isNumericSpace = function (input) {
318
+ return /^[\d\s]*$/.test(input);
319
+ };
320
+ /**
321
+ * 判断字符串是否为空格
322
+ * @param {string} input 输入字符串
323
+ * @example
324
+ * isWhitespace(' '); => true
325
+ * isWhitespace('22.22'); => false
326
+ */
327
+ StringUtil.isWhitespace = function (input) {
328
+ return /^\s*$/.test(input);
329
+ };
330
+ /**
331
+ * 判断字符串是否为小写字母
332
+ * @param {string} input 输入字符串
333
+ * @example
334
+ * isAllLowerCase('abcdefg'); => true
335
+ * isAllLowerCase('isAllLowerCase'); => false
336
+ */
337
+ StringUtil.isAllLowerCase = function (input) {
338
+ return /^[a-z]+$/.test(input);
339
+ };
340
+ /**
341
+ * 判断字符串是否为大写字母
342
+ * @param {string} input 输入字符串
343
+ * @example
344
+ * isAllUpperCase('ABCDEFG'); => true
345
+ * isAllUpperCase('isAllLowerCase'); => false
346
+ */
347
+ StringUtil.isAllUpperCase = function (input) {
348
+ return /^[A-Z]+$/.test(input);
349
+ };
350
+ /**
351
+ * 如果字符串为空则使用默认字符串, 否则不变
352
+ * @param {string} input 输入字符串
353
+ * @param {string} defaultStr 输入字符串
354
+ * @example
355
+ * defaultIfEmpty('', 'abcd'); => 'abcd'
356
+ * defaultIfEmpty('我是测试的字符串isAllLowerCase', '我是测试的字符串'); => '我是测试的字符串isAllLowerCase'
357
+ */
358
+ StringUtil.defaultIfEmpty = function (input, defaultStr) {
359
+ return isEmpty(input) ? defaultStr : input;
360
+ };
361
+ /**
362
+ * 字符串反转
363
+ * @param {string} input 输入字符串
364
+ * @example
365
+ * reverse('abcd'); => 'dcba'
366
+ * reverse('ABCD'); => 'DCBA'
367
+ */
368
+ StringUtil.reverse = function (input) {
369
+ if (isEmpty(input)) {
370
+ return '';
371
+ }
372
+ return input.split('').reverse().join('');
373
+ };
374
+ /**
375
+ * 删掉特殊字符(英文状态下)
376
+ * @param {string} input 输入字符串
377
+ * @example
378
+ * removeSpecialCharacter('remove SpecialCharacter$%%^'); => 'remove SpecialCharacter'
379
+ * removeSpecialCharacter('removeSpecialCharacter##*'); => 'removeSpecialCharacter'
380
+ */
381
+ StringUtil.removeSpecialCharacter = function (input) {
382
+ return input.replace(/[!-/:-@\[-`{-~]/g, '');
383
+ };
384
+ /**
385
+ * 只包含特殊字符、数字和字母
386
+ * @param {string} input 输入字符串
387
+ * @example
388
+ * isSpecialCharacterAlphanumeric('2222SpecialCharacter$%%^'); => true
389
+ * isSpecialCharacterAlphanumeric('(字符串2222SpecialCharacter$%%^)'); => false
390
+ */
391
+ StringUtil.isSpecialCharacterAlphanumeric = function (input) {
392
+ return /^[!-~]+$/.test(input);
393
+ };
394
+ /**
395
+ * 中文校验
396
+ * @param {string} input 输入字符串
397
+ * @example
398
+ * isChinese('我是测试的字符串'); => true
399
+ * isChinese('我是测试的字 abc 符串'); => false
400
+ */
401
+ StringUtil.isChinese = function (input) {
402
+ return /^[\u4E00-\u9FA5]+$/.test(input);
403
+ };
404
+ /**
405
+ * 去掉中文字符
406
+ * @param {string} input 输入字符串
407
+ * @example
408
+ * removeChinese('我是测试的字 abc 符串'); => abc
409
+ * removeChinese('测试abcd'); => abc
410
+ */
411
+ StringUtil.removeChinese = function (input) {
412
+ return input.replace(/[\u4E00-\u9FA5]+/gm, '');
413
+ };
414
+ /**
415
+ * 转义元字符
416
+ * @param {string} input 输入字符串
417
+ * @example
418
+ * escapeMetacharacter('\'\''); => '\'\''
419
+ * escapeMetacharacter('\n\\?'); => '\n\\?'
420
+ */
421
+ StringUtil.escapeMetacharacter = function (input) {
422
+ var metacharacter = '^$()*+.[]|\\-?{}|';
423
+ if (metacharacter.indexOf(input) >= 0) {
424
+ input = '\\' + input;
425
+ }
426
+ return input;
427
+ };
428
+ /**
429
+ * 转义字符串中的元字符
430
+ * @param {string} input 输入字符串
431
+ * @example
432
+ * escapeMetacharacterOfStr('\'\''); => '\'\''
433
+ * escapeMetacharacterOfStr('我是测试的字abc\n符串'); => '我是测试的字abc\n符串'
434
+ */
435
+ StringUtil.escapeMetacharacterOfStr = function (input) {
436
+ return input.replace(/[\^\$\(\)\*\+\.\[\]\|\\\-?\{\}\|]/gm, '\\$&');
437
+ };
438
+ /**
439
+ * 将中划线分隔形式的字符串,转换为驼峰式的字符串
440
+ * @param {string} input 输入字符串
441
+ * @example
442
+ * camelize('last-index-of'); => 'lastIndexOf'
443
+ * camelize('escape-metacharacter-of-str'); => 'escapeMetacharacterOfStr'
444
+ */
445
+ StringUtil.camelize = function (input) {
446
+ return (input + '').replace(/-\D/g, function (match) {
447
+ return match.charAt(1).toUpperCase();
448
+ });
449
+ };
450
+ /**
451
+ * 将驼峰式的字符串转换为中划线分隔形式的字符串
452
+ * @param {string} input 输入字符串
453
+ * @example
454
+ * hyphenate('lastIndexOf'); => 'last-index-of'
455
+ * hyphenate('escapeMetacharacterOfStr'); => 'escape-metacharacter-of-str'
456
+ */
457
+ StringUtil.hyphenate = function (input) {
458
+ return (input + '').replace(/[A-Z]/g, function (match) {
459
+ return '-' + match.toLowerCase();
460
+ });
461
+ };
462
+ /**
463
+ * 将下划线分隔形式的字符串转换为驼峰式的字符串
464
+ * @param {string} input 输入字符串
465
+ * @example
466
+ * camelize('last_index_of'); => 'lastIndexOf'
467
+ * camelize('escape_metacharacter_of_str'); => 'escapeMetacharacterOfStr'
468
+ */
469
+ StringUtil.uncamelize = function (input) {
470
+ return (input + '').replace(/_\D/g, function (match) {
471
+ return match.charAt(1).toUpperCase();
472
+ });
473
+ };
474
+ /**
475
+ * 将驼峰式的字符串转换为下划线分隔形式的字符串
476
+ * @param {string} input 输入字符串
477
+ * @example
478
+ * hyphenate('lastIndexOf'); => 'last_index_of'
479
+ * hyphenate('escapeMetacharacterOfStr'); => 'escape_metacharacter_of_str'
480
+ */
481
+ StringUtil.unhyphenate = function (input) {
482
+ return (input + '').replace(/[A-Z]/g, function (match) {
483
+ return '_' + match.toLowerCase();
484
+ });
485
+ };
486
+ /**
487
+ * 检测密码强度
488
+ * @param {string} str 密码
489
+ * @example
490
+ * checkPwd('data123') => 2
491
+ */
492
+ StringUtil.checkPwd = function (str) {
493
+ var Lv = 0;
494
+ if (str.length < 6) {
495
+ return Lv;
496
+ }
497
+ if (/[0-9]/.test(str)) {
498
+ Lv++;
499
+ }
500
+ if (/[a-z]/.test(str)) {
501
+ Lv++;
502
+ }
503
+ if (/[A-Z]/.test(str)) {
504
+ Lv++;
505
+ }
506
+ if (/[\.|-|_]/.test(str)) {
507
+ Lv++;
508
+ }
509
+ return Lv;
510
+ };
511
+ /**
512
+ * html转换文本
513
+ * @param {string} str html代码段
514
+ * @example
515
+ * filterTag('<p>你好</p>') => 你好
516
+ */
517
+ StringUtil.filterTag = function (str) {
518
+ return str.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, '').replace(/<[^>]+?>/g, '').replace(/\s+/g, ' ').replace(/ /g, ' ').replace(/>/g, ' ');
519
+ };
520
+ /**
521
+ * 格式化json
522
+ * @param {string} str
523
+ * @example
524
+ * verifyJson('{"a":1}') => {\n\t"a": 1\n}
525
+ */
526
+ StringUtil.verifyJson = function (str) {
527
+ if (str === '') return '';
528
+ try {
529
+ var result = JSON.stringify(JSON.parse(str), null, '\t');
530
+ return result;
531
+ } catch (error) {
532
+ return '';
533
+ }
534
+ };
535
+ /**
536
+ * 生成一个用不重复的ID
537
+ * @default 9
538
+ */
539
+ function getUuiD(randomLength) {
540
+ if (randomLength === void 0) {
541
+ randomLength = 9;
542
+ }
543
+ return Number(Math.random().toString().slice(2, randomLength + 2) + Date.now()).toString(36).slice(2, randomLength + 2);
544
+ }
545
+ StringUtil.getUuiD = getUuiD;
546
+ /** 默认颜色数组 */
547
+ StringUtil.DEFAULT_COLORS = ['#5ab1ef', '#588dd5', '#b6a2de', '#dc69aa', '#d87a80', '#f5994e', '#ffb980', '#e5cf0d', '#b5dc5c', '#7eb00a', '#2ec7c9', '#07a2a4', '#8d98b3', '#59678c'];
548
+ /**
549
+ * @name 获取颜色值
550
+ * @param index 默认随机
551
+ */
552
+ StringUtil.getColor = function (index) {
553
+ return StringUtil.DEFAULT_COLORS[(index !== null && index !== void 0 ? index : Math.random() + StringUtil.DEFAULT_COLORS.length) % StringUtil.DEFAULT_COLORS.length];
554
+ };
555
+ })(StringUtil || (StringUtil = {}));
556
+ export default StringUtil;
@@ -0,0 +1,46 @@
1
+ declare namespace SystemUtil {
2
+ /**
3
+ * @name 把fileList转换为stringList(仅用于antd组件上传)
4
+ * @param list 文件list
5
+ * @example
6
+ * const list = [{ fileList: { response: { data: 'asfja.png' },{ fileList: { response: { data: 'asfja1.png' }]
7
+ * getUrlByFileList(list) => 'asfja.png,asfja1.png'
8
+ */
9
+ const getUrlByFileList: (list: {
10
+ fileList: {
11
+ response: {
12
+ data: string;
13
+ };
14
+ }[];
15
+ }) => string | undefined;
16
+ /**
17
+ * 通过url地址下载文件
18
+ * @param url 地址
19
+ * @param name 文件名
20
+ * @example
21
+ * downloadFile('http://XXX.txt','text.txt')
22
+ */
23
+ function downloadFile(url: string, name?: string): void;
24
+ /**
25
+ * 通过base64下载文件
26
+ * @param base64 base64字符串
27
+ * @param name 文件名
28
+ * @example
29
+ * downloadFileByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==','text.txt')
30
+ */
31
+ function downloadFileByBase64(base64: string, name?: string): void;
32
+ /**
33
+ * 通过Blob下载文件
34
+ * @param response BlobPart
35
+ * @param name 文件名
36
+ */
37
+ const downloadFileByBlob: (response: any, name: string) => void;
38
+ /**
39
+ * 拷贝文本至剪切板
40
+ * @param text 文本
41
+ * @example
42
+ * copyText2Clipboard('🦄🌈');
43
+ */
44
+ function copyText2Clipboard(text: string): boolean;
45
+ }
46
+ export default SystemUtil;