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