@haluo/util 2.0.23 → 2.0.25
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/dist/index.d.ts +3 -1
- package/dist/index.js +33 -61
- package/dist/modules/cookie/index.js +18 -24
- package/dist/modules/date/index.js +49 -56
- package/dist/modules/dom/index.js +16 -23
- package/dist/modules/filter/index.js +15 -25
- package/dist/modules/format/index.js +6 -12
- package/dist/modules/match/index.js +6 -10
- package/dist/modules/monitor/index.js +7 -14
- package/dist/modules/monitor/lib/jsError.js +39 -35
- package/dist/modules/monitor/lib/timing.js +24 -28
- package/dist/modules/monitor/lib/xhr.js +26 -33
- package/dist/modules/monitor/utils/onload.js +1 -4
- package/dist/modules/monitor/utils/tracker.js +13 -27
- package/dist/modules/number/index.js +31 -35
- package/dist/modules/open-app/index.js +66 -61
- package/dist/modules/sentry/index.js +19 -27
- package/dist/modules/tools/index.d.ts +1 -1
- package/dist/modules/tools/index.js +158 -169
- package/dist/modules/upload/aliOss.d.ts +78 -127
- package/dist/modules/upload/aliOss.js +178 -358
- package/dist/modules/upload/index.d.ts +2 -14
- package/dist/modules/upload/index.js +2 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.js +1 -2
- package/package.json +14 -3
- package/dist/modules/upload/aliOss copy.d.ts +0 -321
- package/dist/modules/upload/aliOss copy.js +0 -734
- package/dist/modules/upload/backup-aliOss.d.ts +0 -321
- package/dist/modules/upload/backup-aliOss.js +0 -734
|
@@ -3,98 +3,19 @@
|
|
|
3
3
|
* @Author: wanghui
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 蒙层显示后,html禁止滚动操作
|
|
14
|
-
* @param {String} className
|
|
15
|
-
* @return {Void}
|
|
16
|
-
*/
|
|
17
|
-
this.stopScroll = function (className) {
|
|
18
|
-
if (!(window && window.document)) {
|
|
19
|
-
return new Error('仅支持浏览器');
|
|
20
|
-
}
|
|
21
|
-
var html = document.documentElement;
|
|
22
|
-
html.style.overflow = 'hidden';
|
|
23
|
-
html.style.height = '100%';
|
|
24
|
-
var body = document.body;
|
|
25
|
-
body.style.overflow = 'hidden';
|
|
26
|
-
body.style.height = '100%';
|
|
27
|
-
if (className) {
|
|
28
|
-
var dom = document.querySelector(".".concat(className));
|
|
29
|
-
dom && dom.addEventListener('touchmove', _this.__setDefault__);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* 蒙层隐藏后,html开启滚动操作
|
|
34
|
-
* @param {String} className
|
|
35
|
-
* @return {Void}
|
|
36
|
-
*/
|
|
37
|
-
this.startScroll = function (className) {
|
|
38
|
-
if (!(window && window.document)) {
|
|
39
|
-
return new Error('仅支持浏览器');
|
|
40
|
-
}
|
|
41
|
-
var html = document.documentElement;
|
|
42
|
-
html.style.overflow = 'visible';
|
|
43
|
-
html.style.height = 'auto';
|
|
44
|
-
var body = document.body;
|
|
45
|
-
body.style.overflow = 'visible';
|
|
46
|
-
body.style.height = 'auto';
|
|
47
|
-
if (className) {
|
|
48
|
-
var dom = document.querySelector(".".concat(className));
|
|
49
|
-
dom && dom.removeEventListener('touchmove', _this.__setDefault__);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* object 对象转 array 数组
|
|
54
|
-
* demo:
|
|
55
|
-
* objectToArray({a:1,b:2}) 输出:["a=1", "b=2"]
|
|
56
|
-
* @param {Object} obj
|
|
57
|
-
* @returns {Array} arr
|
|
58
|
-
*/
|
|
59
|
-
this.objectToArray = function (obj) {
|
|
60
|
-
var arr = [];
|
|
61
|
-
if (typeof obj === 'object') {
|
|
62
|
-
for (var key in obj) {
|
|
63
|
-
if (obj.hasOwnProperty(key)) {
|
|
64
|
-
arr.push([key, obj[key]].join('='));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return arr;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* convertEnum
|
|
72
|
-
* 枚举键值互换
|
|
73
|
-
* @param {Object} obj
|
|
74
|
-
* convertKeyValueEnum({a: 1, b: 2}) // {1: "a", 2: "b"}
|
|
75
|
-
* @returns {Object} result
|
|
76
|
-
*/
|
|
77
|
-
this.convertKeyValueEnum = function (obj) {
|
|
78
|
-
var result = {};
|
|
79
|
-
if (typeof obj === 'object') {
|
|
80
|
-
for (var key in obj) {
|
|
81
|
-
if (obj.hasOwnProperty(key)) {
|
|
82
|
-
result[obj[key]] = key;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
|
-
this.isDefined = function (val) {
|
|
89
|
-
return val !== undefined && val !== null;
|
|
90
|
-
};
|
|
6
|
+
let previous = 0;
|
|
7
|
+
let timeout = null;
|
|
8
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
9
|
+
import copy from 'clipboard-copy';
|
|
10
|
+
class ToolsClass {
|
|
11
|
+
constructor() {
|
|
91
12
|
this.__loaded__ = {}; // 已加载的资源
|
|
92
13
|
/**
|
|
93
14
|
* 阻止事件传递
|
|
94
15
|
* @param {Event} e
|
|
95
16
|
* @return {Void}
|
|
96
17
|
*/
|
|
97
|
-
this.__setDefault__ =
|
|
18
|
+
this.__setDefault__ = (e) => {
|
|
98
19
|
e && e.preventDefault();
|
|
99
20
|
};
|
|
100
21
|
}
|
|
@@ -104,32 +25,31 @@ var ToolsClass = /** @class */ (function () {
|
|
|
104
25
|
* @param {String} data
|
|
105
26
|
* @return {Object}
|
|
106
27
|
*/
|
|
107
|
-
|
|
28
|
+
deepCopy(data) {
|
|
108
29
|
return JSON.parse(JSON.stringify(data));
|
|
109
|
-
}
|
|
30
|
+
}
|
|
110
31
|
/**
|
|
111
32
|
* 深拷贝 Object|Array
|
|
112
33
|
* 支持 普通对象、数组和函数的深复制,但是未解决循环引用、Date、RegExp
|
|
113
34
|
* @param {Object|Array} data
|
|
114
35
|
* @return {Object}
|
|
115
36
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
for (
|
|
37
|
+
deepCopy2(obj) {
|
|
38
|
+
const _obj = Array.isArray(obj) ? [] : {};
|
|
39
|
+
for (const i in obj) {
|
|
119
40
|
_obj[i] = typeof obj[i] === 'object' ? this.deepCopy2(obj[i]) : obj[i];
|
|
120
41
|
}
|
|
121
42
|
return _obj;
|
|
122
|
-
}
|
|
43
|
+
}
|
|
123
44
|
/**
|
|
124
45
|
* 深拷贝 Object|Array
|
|
125
46
|
* 注意:需要 yarn add lodash
|
|
126
47
|
* @param {Object|Array} data
|
|
127
48
|
* @return {Object}
|
|
128
49
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
50
|
+
deepCopy3(obj) {
|
|
51
|
+
return cloneDeep(obj);
|
|
52
|
+
}
|
|
133
53
|
/**
|
|
134
54
|
* 防抖
|
|
135
55
|
* demo:debounce(func, 300)(args)
|
|
@@ -137,17 +57,17 @@ var ToolsClass = /** @class */ (function () {
|
|
|
137
57
|
* @param {Number} wait 节流时间,毫秒
|
|
138
58
|
* @return {Function} delay
|
|
139
59
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
60
|
+
debounce(func, wait) {
|
|
61
|
+
const delay = function () {
|
|
62
|
+
const args = arguments;
|
|
143
63
|
if (timeout)
|
|
144
64
|
clearTimeout(timeout);
|
|
145
|
-
timeout = setTimeout(
|
|
65
|
+
timeout = setTimeout(() => {
|
|
146
66
|
func.apply(delay, args);
|
|
147
67
|
}, wait);
|
|
148
68
|
};
|
|
149
69
|
return delay;
|
|
150
|
-
}
|
|
70
|
+
}
|
|
151
71
|
/**
|
|
152
72
|
* 节流
|
|
153
73
|
* demo:throttle(func, 300)(args)
|
|
@@ -155,86 +75,124 @@ var ToolsClass = /** @class */ (function () {
|
|
|
155
75
|
* @param {Number} wait 节流时间,毫秒
|
|
156
76
|
* @return {Function} delay
|
|
157
77
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
78
|
+
throttle(func, wait) {
|
|
79
|
+
const delay = function () {
|
|
80
|
+
const now = Date.now();
|
|
161
81
|
if (now - previous > wait) {
|
|
162
82
|
func.apply(delay, arguments);
|
|
163
83
|
previous = now;
|
|
164
84
|
}
|
|
165
85
|
};
|
|
166
86
|
return delay;
|
|
167
|
-
}
|
|
87
|
+
}
|
|
168
88
|
/**
|
|
169
89
|
* 获取路径中文件名称
|
|
170
90
|
* @param {String} url
|
|
171
91
|
* @return {String}
|
|
172
92
|
*/
|
|
173
|
-
|
|
93
|
+
getUrlName(url) {
|
|
174
94
|
return (url && url.split('?')[0].split('/').reverse()[0]);
|
|
175
|
-
}
|
|
95
|
+
}
|
|
176
96
|
/**
|
|
177
97
|
* 动态加载脚本
|
|
178
98
|
* tip:按需加载时用(多次调用,js不会重复加载)
|
|
179
99
|
* @param {String} url
|
|
180
100
|
* @return {Promise}
|
|
181
101
|
*/
|
|
182
|
-
|
|
183
|
-
var _this = this;
|
|
102
|
+
loadJs(url) {
|
|
184
103
|
if (!(window && window.document)) {
|
|
185
104
|
return new Error('仅支持浏览器');
|
|
186
105
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return new Promise(
|
|
190
|
-
if (
|
|
106
|
+
const name = this.getUrlName(url);
|
|
107
|
+
const id = 'js_' + name;
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
if (this.__loaded__[id]) {
|
|
191
110
|
return resolve();
|
|
192
111
|
}
|
|
193
|
-
|
|
112
|
+
const script = document.createElement('script');
|
|
194
113
|
script.type = 'text/javascript';
|
|
195
114
|
script.async = true;
|
|
196
115
|
script.src = url;
|
|
197
116
|
script.id = id;
|
|
198
|
-
script.onload =
|
|
199
|
-
|
|
117
|
+
script.onload = () => {
|
|
118
|
+
this.__loaded__[id] = true;
|
|
200
119
|
resolve();
|
|
201
120
|
};
|
|
202
|
-
script.onerror =
|
|
121
|
+
script.onerror = (e) => {
|
|
203
122
|
reject(e);
|
|
204
123
|
};
|
|
205
124
|
document.body.appendChild(script);
|
|
206
125
|
});
|
|
207
|
-
}
|
|
126
|
+
}
|
|
208
127
|
/**
|
|
209
128
|
* 动态加载样式
|
|
210
129
|
* @param {String} url
|
|
211
130
|
* @return {Promise}
|
|
212
131
|
*/
|
|
213
|
-
|
|
214
|
-
var _this = this;
|
|
132
|
+
loadCss(url) {
|
|
215
133
|
if (!(window && window.document)) {
|
|
216
134
|
return new Error('仅支持浏览器');
|
|
217
135
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return new Promise(
|
|
221
|
-
if (
|
|
136
|
+
const name = this.getUrlName(url);
|
|
137
|
+
const id = 'css_' + name;
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
if (this.__loaded__[id]) {
|
|
222
140
|
return resolve();
|
|
223
141
|
}
|
|
224
|
-
|
|
142
|
+
const link = document.createElement('link');
|
|
225
143
|
link.type = 'text/css';
|
|
226
144
|
link.rel = 'stylesheet';
|
|
227
145
|
link.href = url;
|
|
228
146
|
link.id = id;
|
|
229
|
-
link.onload =
|
|
230
|
-
|
|
147
|
+
link.onload = () => {
|
|
148
|
+
this.__loaded__[id] = true;
|
|
231
149
|
resolve();
|
|
232
150
|
};
|
|
233
|
-
link.onerror =
|
|
151
|
+
link.onerror = (e) => {
|
|
234
152
|
reject(e);
|
|
235
153
|
};
|
|
236
154
|
document.head.appendChild(link);
|
|
237
155
|
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 蒙层显示后,html禁止滚动操作
|
|
159
|
+
* @param {String} className
|
|
160
|
+
* @return {Void}
|
|
161
|
+
*/
|
|
162
|
+
stopScroll = (className) => {
|
|
163
|
+
if (!(window && window.document)) {
|
|
164
|
+
return new Error('仅支持浏览器');
|
|
165
|
+
}
|
|
166
|
+
const html = document.documentElement;
|
|
167
|
+
html.style.overflow = 'hidden';
|
|
168
|
+
html.style.height = '100%';
|
|
169
|
+
const body = document.body;
|
|
170
|
+
body.style.overflow = 'hidden';
|
|
171
|
+
body.style.height = '100%';
|
|
172
|
+
if (className) {
|
|
173
|
+
const dom = document.querySelector(`.${className}`);
|
|
174
|
+
dom && dom.addEventListener('touchmove', this.__setDefault__);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* 蒙层隐藏后,html开启滚动操作
|
|
179
|
+
* @param {String} className
|
|
180
|
+
* @return {Void}
|
|
181
|
+
*/
|
|
182
|
+
startScroll = (className) => {
|
|
183
|
+
if (!(window && window.document)) {
|
|
184
|
+
return new Error('仅支持浏览器');
|
|
185
|
+
}
|
|
186
|
+
const html = document.documentElement;
|
|
187
|
+
html.style.overflow = 'visible';
|
|
188
|
+
html.style.height = 'auto';
|
|
189
|
+
const body = document.body;
|
|
190
|
+
body.style.overflow = 'visible';
|
|
191
|
+
body.style.height = 'auto';
|
|
192
|
+
if (className) {
|
|
193
|
+
const dom = document.querySelector(`.${className}`);
|
|
194
|
+
dom && dom.removeEventListener('touchmove', this.__setDefault__);
|
|
195
|
+
}
|
|
238
196
|
};
|
|
239
197
|
/**
|
|
240
198
|
* 字符串复制到剪贴板
|
|
@@ -242,59 +200,91 @@ var ToolsClass = /** @class */ (function () {
|
|
|
242
200
|
* @param {String} str
|
|
243
201
|
* @return {String}
|
|
244
202
|
*/
|
|
245
|
-
|
|
203
|
+
clipboard(str) {
|
|
246
204
|
if (!(window && window.document)) {
|
|
247
205
|
return new Error('仅支持浏览器');
|
|
248
206
|
}
|
|
249
|
-
var copy = require('clipboard-copy');
|
|
250
207
|
return copy(str);
|
|
251
|
-
}
|
|
208
|
+
}
|
|
252
209
|
/**
|
|
253
210
|
* 首字母大写
|
|
254
211
|
* @param {String} str
|
|
255
212
|
* @return {String}
|
|
256
213
|
*/
|
|
257
|
-
|
|
214
|
+
firstUpperCase(str) {
|
|
258
215
|
return str.charAt(0).toUpperCase() + str.toString().slice(1);
|
|
259
|
-
}
|
|
216
|
+
}
|
|
260
217
|
/**
|
|
261
218
|
* 截取数组或字符串,示例:slice('1234', 3)
|
|
262
219
|
* @param {Array|String} target 数组或字符串
|
|
263
220
|
* @param {Number} length 截取长度,从0开始
|
|
264
221
|
* @return {any}
|
|
265
222
|
*/
|
|
266
|
-
|
|
267
|
-
if (target === void 0) { target = ''; }
|
|
268
|
-
if (length === void 0) { length = 0; }
|
|
223
|
+
slice(target = '', length = 0) {
|
|
269
224
|
return target.slice(0, length);
|
|
270
|
-
}
|
|
225
|
+
}
|
|
271
226
|
/**
|
|
272
227
|
* 获取guid
|
|
273
228
|
* @return {String}
|
|
274
229
|
*/
|
|
275
|
-
|
|
230
|
+
guid() {
|
|
276
231
|
function S4() {
|
|
277
232
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
278
233
|
}
|
|
279
234
|
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
|
|
280
|
-
}
|
|
235
|
+
}
|
|
281
236
|
/**
|
|
282
237
|
* 获取文本字节数(含中文)
|
|
283
238
|
* @param {String} str
|
|
284
239
|
* @return {String}
|
|
285
240
|
*/
|
|
286
|
-
|
|
287
|
-
if (str === void 0) { str = ''; }
|
|
241
|
+
getBytesOfText(str = '') {
|
|
288
242
|
return str.replace(/[^\u0000-\u00ff]/g, "aa").length;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* object 对象转 array 数组
|
|
246
|
+
* demo:
|
|
247
|
+
* objectToArray({a:1,b:2}) 输出:["a=1", "b=2"]
|
|
248
|
+
* @param {Object} obj
|
|
249
|
+
* @returns {Array} arr
|
|
250
|
+
*/
|
|
251
|
+
objectToArray = (obj) => {
|
|
252
|
+
var arr = [];
|
|
253
|
+
if (typeof obj === 'object') {
|
|
254
|
+
for (var key in obj) {
|
|
255
|
+
if (obj.hasOwnProperty(key)) {
|
|
256
|
+
arr.push([key, obj[key]].join('='));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return arr;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* convertEnum
|
|
264
|
+
* 枚举键值互换
|
|
265
|
+
* @param {Object} obj
|
|
266
|
+
* convertKeyValueEnum({a: 1, b: 2}) // {1: "a", 2: "b"}
|
|
267
|
+
* @returns {Object} result
|
|
268
|
+
*/
|
|
269
|
+
convertKeyValueEnum = (obj) => {
|
|
270
|
+
const result = {};
|
|
271
|
+
if (typeof obj === 'object') {
|
|
272
|
+
for (const key in obj) {
|
|
273
|
+
if (obj.hasOwnProperty(key)) {
|
|
274
|
+
result[obj[key]] = key;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
289
279
|
};
|
|
290
280
|
/**
|
|
291
281
|
* 数组去重
|
|
292
282
|
* @param {Array} arr
|
|
293
283
|
* @returns {Array}
|
|
294
284
|
*/
|
|
295
|
-
|
|
285
|
+
uniqueArr(arr) {
|
|
296
286
|
return Array.from(new Set(arr));
|
|
297
|
-
}
|
|
287
|
+
}
|
|
298
288
|
/**
|
|
299
289
|
* 数组元素交换位置
|
|
300
290
|
* index1和index2分别是两个数组的索引值,即是两个要交换元素位置的索引值,如1,5就是数组中下标为1和5的两个元素交换位置
|
|
@@ -304,38 +294,37 @@ var ToolsClass = /** @class */ (function () {
|
|
|
304
294
|
* swapArray([1, 2, 3, 4], 2, 3) // [1, 2, 4, 3]
|
|
305
295
|
* @returns {Array<string | number>} array
|
|
306
296
|
*/
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
_a = [array[index2], array[index1]], array[index1] = _a[0], array[index2] = _a[1];
|
|
297
|
+
swapArray(array, index1, index2) {
|
|
298
|
+
[array[index1], array[index2]] = [array[index2], array[index1]];
|
|
310
299
|
return array;
|
|
311
|
-
}
|
|
300
|
+
}
|
|
312
301
|
/**
|
|
313
302
|
* 过滤表情符号
|
|
314
303
|
* @param {String} str
|
|
315
304
|
* @return {String}
|
|
316
305
|
*/
|
|
317
|
-
|
|
306
|
+
filterEmoji(str) {
|
|
318
307
|
return str.replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/mg, '');
|
|
319
|
-
}
|
|
308
|
+
}
|
|
320
309
|
/**
|
|
321
310
|
* 是否包含表情
|
|
322
311
|
* @param {String} str
|
|
323
312
|
* @return {boolean}
|
|
324
313
|
*/
|
|
325
|
-
|
|
326
|
-
|
|
314
|
+
containsEmoji(str) {
|
|
315
|
+
const reg = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/mg;
|
|
327
316
|
return reg.test(str);
|
|
328
|
-
}
|
|
317
|
+
}
|
|
329
318
|
/**
|
|
330
319
|
* 是否包含表汉字
|
|
331
320
|
* @param {String} str
|
|
332
321
|
* @return {boolean}
|
|
333
322
|
*/
|
|
334
|
-
|
|
335
|
-
|
|
323
|
+
containsHanZi(str) {
|
|
324
|
+
const reg = /[\u4e00-\u9fa5]/mg;
|
|
336
325
|
return reg.test(str);
|
|
337
|
-
}
|
|
338
|
-
|
|
326
|
+
}
|
|
327
|
+
isEmpty(val) {
|
|
339
328
|
// null or undefined
|
|
340
329
|
if (val == null)
|
|
341
330
|
return true;
|
|
@@ -362,8 +351,11 @@ var ToolsClass = /** @class */ (function () {
|
|
|
362
351
|
}
|
|
363
352
|
}
|
|
364
353
|
return false;
|
|
365
|
-
}
|
|
354
|
+
}
|
|
366
355
|
;
|
|
356
|
+
isDefined = (val) => {
|
|
357
|
+
return val !== undefined && val !== null;
|
|
358
|
+
};
|
|
367
359
|
/**
|
|
368
360
|
* 字段脱敏处理
|
|
369
361
|
* @param {String} field 未脱敏字段
|
|
@@ -371,23 +363,20 @@ var ToolsClass = /** @class */ (function () {
|
|
|
371
363
|
* @param {Int} after 结尾未脱敏字符数
|
|
372
364
|
* @return {String} 已脱敏字段
|
|
373
365
|
*/
|
|
374
|
-
|
|
375
|
-
if (before === void 0) { before = 3; }
|
|
376
|
-
if (after === void 0) { after = 4; }
|
|
366
|
+
sensitiveField(field, before = 3, after = 4) {
|
|
377
367
|
if (!field) {
|
|
378
368
|
return '';
|
|
379
369
|
}
|
|
380
370
|
field = String(field);
|
|
381
|
-
|
|
371
|
+
let sensitiveLen = field.length - before - after;
|
|
382
372
|
if (sensitiveLen < 0) {
|
|
383
373
|
sensitiveLen = 0;
|
|
384
374
|
}
|
|
385
375
|
// 匹配中文、英文、数字
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return field.replace(reg,
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
exports.default = new ToolsClass();
|
|
376
|
+
const regItem = '[\u4e00-\u9fa5a-zA-Z0-9]';
|
|
377
|
+
const regExp = `(${regItem}{${before}})${regItem}*(${regItem}{${after}})`;
|
|
378
|
+
const reg = new RegExp(regExp);
|
|
379
|
+
return field.replace(reg, `$1${"*".repeat(sensitiveLen)}$2`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
export default new ToolsClass();
|