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,110 @@
1
+ import { STR_TYPE } from '../common';
2
+ export type StrType = keyof typeof STR_TYPE;
3
+ declare namespace CheckUtil {
4
+ /**
5
+ * 检查手机号是否合法
6
+ * @param {String} phone 手机号
7
+ *
8
+ * @example
9
+ * phoneIsValid('123') => false
10
+ * phoneIsValid('12345678901') => true
11
+ */
12
+ const phoneIsValid: (phone: string) => boolean;
13
+ /**
14
+ * 检查身份证是否合法
15
+ * @param {String} idcard 身份证
16
+ *
17
+ * @example
18
+ * idcardIsValid('110410199001011234') => false
19
+ * idcardIsValid('410482199001080000') => true
20
+ */
21
+ const idcardIsValid: (idcard: string) => boolean;
22
+ /**
23
+ * 对手机号进行去敏处理,用*替换
24
+ * @param phone 手机号
25
+ * @param start 掩码开始位置,从0开始
26
+ * @param len 掩码长度
27
+ *
28
+ * @example
29
+ * maskPhone('13641601234') => '136****1234'
30
+ * maskPhone('1234') => '1234'
31
+ * maskPhone('13641601234', 3, 8) => '136********'
32
+ */
33
+ const maskPhone: (phone: string, start?: number, len?: number) => string;
34
+ /**
35
+ * 对身份证进行去敏处理,用*替换
36
+ * @param idcard 身份证
37
+ * @param start 掩码开始位置,从0开始
38
+ * @param len 掩码长度
39
+ *
40
+ * @example
41
+ * maskIDCard('110410199001011234') => '110410********1234'
42
+ * maskIDCard('110410199001011234', 6, 10) => '110410**********34'
43
+ */
44
+ const maskIDCard: (idcard: string, start?: number, len?: number) => string;
45
+ /**
46
+ * 对邮箱进行去敏处理
47
+ * @param email
48
+ * @example
49
+ * maskEMail('1111111111@qq.com') => 11***11@qq.com
50
+ */
51
+ const maskEMail: (email: string) => string;
52
+ /**
53
+ * 对姓名进行去敏处理
54
+ * @param name
55
+ * @example
56
+ * maskName("王标") => 王****
57
+ * maskName("王标沙皮") => 王*皮
58
+ */
59
+ const maskName: (name: string) => string;
60
+ /**
61
+ * 对一个字符串进行去敏处理
62
+ * @param text 原始字符串(必填)
63
+ * @param start 开头保留多少位明文(必填)
64
+ * @param end 结尾保留多少位明文(必填)
65
+ * @param len 中间显示多少个*
66
+ *
67
+ * @example
68
+ * mask('123456', 2, 3) => '12*456'
69
+ * mask('123456', 2, 3, 4) => '12****456'
70
+ */
71
+ const mask: (text: string, start: number, end: number, len?: number) => string;
72
+ /**
73
+ * 验证统一社会信用代码
74
+ * @param { string | undefined } code 统一社会信用代码
75
+ * @returns { isPass: boolean; errorMessage: string }
76
+ * @example
77
+ * socialCreditCodeValid('') => { isPass: false, errorMessage: '请输入统一社会信用代码!' }
78
+ * socialCreditCodeValid('123456') => { isPass: false, errorMessage: '不是有效的统一社会信用代码!' }
79
+ **/
80
+ const socialCreditCodeValid: (code: string | undefined) => {
81
+ isPass: boolean;
82
+ errorMessage: string;
83
+ };
84
+ /**
85
+ * 常用检验集合
86
+ * @param str 字符串
87
+ * @param type 类型
88
+ * @example
89
+ * strCheck('1231','MOBILE') => false
90
+ */
91
+ const checkAny: (str: string, type: StrType) => boolean;
92
+ /**
93
+ * 获取校验正则
94
+ * @param type 类型
95
+ * @example
96
+ * getStrCheck('MOBILE') => /^1[2-9]\d{9}$/
97
+ */
98
+ const getRegExp: (type: StrType) => RegExp;
99
+ /**
100
+ * FormItem的规则
101
+ * @param type 类型
102
+ * @param options
103
+ */
104
+ function getFormItemRules<T>(type: StrType, options?: {
105
+ label?: string;
106
+ errMsg?: string;
107
+ _validator?: any;
108
+ }): T[];
109
+ }
110
+ export default CheckUtil;
@@ -0,0 +1,465 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) {
9
+ try {
10
+ step(generator.next(value));
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ }
15
+ function rejected(value) {
16
+ try {
17
+ step(generator["throw"](value));
18
+ } catch (e) {
19
+ reject(e);
20
+ }
21
+ }
22
+ function step(result) {
23
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
24
+ }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ };
28
+ var __generator = this && this.__generator || function (thisArg, body) {
29
+ var _ = {
30
+ label: 0,
31
+ sent: function sent() {
32
+ if (t[0] & 1) throw t[1];
33
+ return t[1];
34
+ },
35
+ trys: [],
36
+ ops: []
37
+ },
38
+ f,
39
+ y,
40
+ t,
41
+ g;
42
+ return g = {
43
+ next: verb(0),
44
+ "throw": verb(1),
45
+ "return": verb(2)
46
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
47
+ return this;
48
+ }), g;
49
+ function verb(n) {
50
+ return function (v) {
51
+ return step([n, v]);
52
+ };
53
+ }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [0];
74
+ continue;
75
+ case 7:
76
+ op = _.ops.pop();
77
+ _.trys.pop();
78
+ continue;
79
+ default:
80
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
81
+ _ = 0;
82
+ continue;
83
+ }
84
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
+ _.label = op[1];
86
+ break;
87
+ }
88
+ if (op[0] === 6 && _.label < t[1]) {
89
+ _.label = t[1];
90
+ t = op;
91
+ break;
92
+ }
93
+ if (t && _.label < t[2]) {
94
+ _.label = t[2];
95
+ _.ops.push(op);
96
+ break;
97
+ }
98
+ if (t[2]) _.ops.pop();
99
+ _.trys.pop();
100
+ continue;
101
+ }
102
+ op = body.call(thisArg, _);
103
+ } catch (e) {
104
+ op = [6, e];
105
+ y = 0;
106
+ } finally {
107
+ f = t = 0;
108
+ }
109
+ if (op[0] & 5) throw op[1];
110
+ return {
111
+ value: op[0] ? op[1] : void 0,
112
+ done: true
113
+ };
114
+ }
115
+ };
116
+ /**
117
+ * 校验工具
118
+ * @description
119
+ * @author nanshen
120
+ * @creat 2021-09-15 10:30:46
121
+ */
122
+ import BaseUtil from '../base/BaseUtil';
123
+ import { STR_TYPE } from '../common';
124
+ var CheckUtil;
125
+ (function (CheckUtil) {
126
+ /**
127
+ * 检查手机号是否合法
128
+ * @param {String} phone 手机号
129
+ *
130
+ * @example
131
+ * phoneIsValid('123') => false
132
+ * phoneIsValid('12345678901') => true
133
+ */
134
+ CheckUtil.phoneIsValid = function (phone) {
135
+ if (!BaseUtil.isString(phone) || phone.length !== 11) {
136
+ return false;
137
+ }
138
+ return /^1[2-9]\d{9}$/.test(phone);
139
+ };
140
+ /**
141
+ * 检查身份证是否合法
142
+ * @param {String} idcard 身份证
143
+ *
144
+ * @example
145
+ * idcardIsValid('110410199001011234') => false
146
+ * idcardIsValid('410482199001080000') => true
147
+ */
148
+ CheckUtil.idcardIsValid = function (idcard) {
149
+ var weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; // 十七位数字本体码权重
150
+ var validate = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; // 校验码列表
151
+ var validChar = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'x', 'X'];
152
+ if (!BaseUtil.isString(idcard) || idcard.length !== 18) {
153
+ return false;
154
+ }
155
+ var idcardCharArr = idcard.split('');
156
+ if (idcardCharArr.some(function (c) {
157
+ return validChar.indexOf(c) === -1;
158
+ })) {
159
+ return false;
160
+ }
161
+ var sum = 0;
162
+ for (var i = 0; i < 17; i++) {
163
+ sum += +idcardCharArr[i] * weight[i];
164
+ }
165
+ var mode = sum % 11;
166
+ return validate[mode] === idcardCharArr[17].toUpperCase();
167
+ };
168
+ /**
169
+ * 对手机号进行去敏处理,用*替换
170
+ * @param phone 手机号
171
+ * @param start 掩码开始位置,从0开始
172
+ * @param len 掩码长度
173
+ *
174
+ * @example
175
+ * maskPhone('13641601234') => '136****1234'
176
+ * maskPhone('1234') => '1234'
177
+ * maskPhone('13641601234', 3, 8) => '136********'
178
+ */
179
+ CheckUtil.maskPhone = function (phone, start, len) {
180
+ if (start === void 0) {
181
+ start = 3;
182
+ }
183
+ if (len === void 0) {
184
+ len = 4;
185
+ }
186
+ if (!CheckUtil.phoneIsValid(phone)) {
187
+ return phone;
188
+ }
189
+ if (start < 0) {
190
+ start = 0;
191
+ }
192
+ if (start > 11) {
193
+ start = 11;
194
+ }
195
+ if (len < 0) {
196
+ len = 0;
197
+ }
198
+ if (len > 11) {
199
+ len = 11;
200
+ }
201
+ if (start + len > 11) {
202
+ len = 11 - start;
203
+ }
204
+ return phone.substr(0, start) + '*'.repeat(len) + phone.substring(start + len);
205
+ };
206
+ /**
207
+ * 对身份证进行去敏处理,用*替换
208
+ * @param idcard 身份证
209
+ * @param start 掩码开始位置,从0开始
210
+ * @param len 掩码长度
211
+ *
212
+ * @example
213
+ * maskIDCard('110410199001011234') => '110410********1234'
214
+ * maskIDCard('110410199001011234', 6, 10) => '110410**********34'
215
+ */
216
+ CheckUtil.maskIDCard = function (idcard, start, len) {
217
+ if (start === void 0) {
218
+ start = 6;
219
+ }
220
+ if (len === void 0) {
221
+ len = 8;
222
+ }
223
+ if (!CheckUtil.idcardIsValid(idcard)) {
224
+ return idcard;
225
+ }
226
+ if (start < 0) {
227
+ start = 0;
228
+ }
229
+ if (start > 18) {
230
+ start = 18;
231
+ }
232
+ if (len < 0) {
233
+ len = 0;
234
+ }
235
+ if (len > 18) {
236
+ len = 18;
237
+ }
238
+ if (start + len > 18) {
239
+ len = 18 - start;
240
+ }
241
+ return idcard.substr(0, start) + '*'.repeat(len) + idcard.substring(start + len);
242
+ };
243
+ /**
244
+ * 对邮箱进行去敏处理
245
+ * @param email
246
+ * @example
247
+ * maskEMail('1111111111@qq.com') => 11***11@qq.com
248
+ */
249
+ CheckUtil.maskEMail = function (email) {
250
+ return email && email.replace(/(.*?)(@.+)/g, function (_, name, suffix) {
251
+ return CheckUtil.mask(name, 2, 2, 3) + suffix;
252
+ });
253
+ };
254
+ /**
255
+ * 对姓名进行去敏处理
256
+ * @param name
257
+ * @example
258
+ * maskName("王标") => 王****
259
+ * maskName("王标沙皮") => 王*皮
260
+ */
261
+ CheckUtil.maskName = function (name) {
262
+ if (!name) {
263
+ return name;
264
+ }
265
+ if (name.length <= 2) {
266
+ return CheckUtil.mask(name, 1, 0);
267
+ } else {
268
+ return CheckUtil.mask(name, 1, 1, 1);
269
+ }
270
+ };
271
+ /**
272
+ * 对一个字符串进行去敏处理
273
+ * @param text 原始字符串(必填)
274
+ * @param start 开头保留多少位明文(必填)
275
+ * @param end 结尾保留多少位明文(必填)
276
+ * @param len 中间显示多少个*
277
+ *
278
+ * @example
279
+ * mask('123456', 2, 3) => '12*456'
280
+ * mask('123456', 2, 3, 4) => '12****456'
281
+ */
282
+ CheckUtil.mask = function (text, start, end, len) {
283
+ if (len === void 0) {
284
+ len = 4;
285
+ }
286
+ if (!text) {
287
+ return text;
288
+ }
289
+ if (start < 0 || end < 0 || len < 0) {
290
+ throw new TypeError('参数不能小于0');
291
+ }
292
+ if (len === undefined) {
293
+ // 没有指定 len 参数,则根据原始字符串长度计算
294
+ if (start >= text.length || end >= text.length) {
295
+ return text;
296
+ }
297
+ if (start + end >= text.length) {
298
+ return text;
299
+ }
300
+ return text.substr(0, start) + '*'.repeat(Math.max(text.length - start - end, 0)) + text.substring(text.length - end);
301
+ } else {
302
+ return text.substr(0, start) + '*'.repeat(len) + text.substring(text.length - end);
303
+ }
304
+ };
305
+ /**
306
+ * 验证统一社会信用代码
307
+ * @param { string | undefined } code 统一社会信用代码
308
+ * @returns { isPass: boolean; errorMessage: string }
309
+ * @example
310
+ * socialCreditCodeValid('') => { isPass: false, errorMessage: '请输入统一社会信用代码!' }
311
+ * socialCreditCodeValid('123456') => { isPass: false, errorMessage: '不是有效的统一社会信用代码!' }
312
+ **/
313
+ CheckUtil.socialCreditCodeValid = function (code) {
314
+ var isPass = true; // 是否验证通过,默认通过,为true
315
+ var errorMessage = ''; // 错误信息
316
+ // 空值直接返回false
317
+ if (!code) {
318
+ isPass = false;
319
+ errorMessage = '请输入统一社会信用代码!';
320
+ return {
321
+ isPass: isPass,
322
+ errorMessage: errorMessage
323
+ };
324
+ }
325
+ // 18位及正则校验
326
+ var reg = /^\w\w\d{6}\w{9}\w$/;
327
+ if (code.length !== 18 || !reg.test(code)) {
328
+ isPass = false;
329
+ errorMessage = '不是有效的统一社会信用代码!';
330
+ return {
331
+ isPass: isPass,
332
+ errorMessage: errorMessage
333
+ };
334
+ }
335
+ var codeOrigin = '0123456789ABCDEFGHJKLMNPQRTUWXY'; // 统一社会信用代码可用字符 不含I、O、S、V、Z
336
+ var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28]; // 统一社会信用代码相对应顺序的加权因子
337
+ var ci; // 统一社会信用代码相应顺序的值
338
+ var wi; // 统一社会信用代码相应顺序的加权因子
339
+ var total = 0; // 计算结果
340
+ // 数值与加权因子相乘之和
341
+ for (var i = 0; i < code.length - 1; i++) {
342
+ ci = codeOrigin.indexOf(code[i]);
343
+ wi = weightedfactors[i];
344
+ total += ci * wi;
345
+ }
346
+ // 最后一位校验
347
+ var logicCheckCode = 31 - total % 31;
348
+ if (logicCheckCode === 31) logicCheckCode = 0;
349
+ logicCheckCode = codeOrigin[logicCheckCode];
350
+ if (logicCheckCode !== code.slice(17)) {
351
+ isPass = false;
352
+ errorMessage = '不是有效的统一社会信用代码!';
353
+ }
354
+ return {
355
+ isPass: isPass,
356
+ errorMessage: errorMessage
357
+ };
358
+ };
359
+ /**
360
+ * 常用检验集合
361
+ * @param str 字符串
362
+ * @param type 类型
363
+ * @example
364
+ * strCheck('1231','MOBILE') => false
365
+ */
366
+ CheckUtil.checkAny = function (str, type) {
367
+ var _a, _b, _c;
368
+ if (type === 'MOBILE') return CheckUtil.phoneIsValid(str);
369
+ if (type === 'ID_CARD') return CheckUtil.idcardIsValid(str);
370
+ if (type === 'SC_CODE') return CheckUtil.socialCreditCodeValid(str).isPass;
371
+ if (type === 'URL') return !!((_a = CheckUtil.getRegExp(type)) === null || _a === void 0 ? void 0 : _a.test(encodeURI(str)));
372
+ if (['PHOTO', 'VIDEO', 'AUDIO', 'DOCUMENT'].includes(type)) {
373
+ return !!((_b = CheckUtil.getRegExp(type)) === null || _b === void 0 ? void 0 : _b.test(str === null || str === void 0 ? void 0 : str.toLocaleLowerCase()));
374
+ }
375
+ return !!((_c = CheckUtil.getRegExp(type)) === null || _c === void 0 ? void 0 : _c.test(str));
376
+ };
377
+ /**
378
+ * 获取校验正则
379
+ * @param type 类型
380
+ * @example
381
+ * getStrCheck('MOBILE') => /^1[2-9]\d{9}$/
382
+ */
383
+ CheckUtil.getRegExp = function (type) {
384
+ switch (type) {
385
+ case 'LOGIN_NAME':
386
+ return /^[a-zA-Z][a-zA-Z0-9_-]{5,17}$/;
387
+ case 'MOBILE':
388
+ return /^1[2-9]\d{9}$/;
389
+ case 'TEL':
390
+ return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/;
391
+ case 'ID_CARD':
392
+ return /^((\d{18})|([0-9x]{18})|([0-9X]{18}))$/;
393
+ case 'SC_CODE':
394
+ return /^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/;
395
+ case 'PASSWORD':
396
+ return /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W_]).{8,15}$/;
397
+ case 'POSTAL':
398
+ return /[1-9]\d{5}(?!\d)/;
399
+ case 'QQ':
400
+ return /^[1-9][0-9]{4,9}$/;
401
+ case 'EMAIL':
402
+ return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
403
+ case 'URL':
404
+ return /^(http|https|ftp)\:\/\/([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\*\?\'\\\+&amp;%\$#\=~_\-]+))*$/;
405
+ case 'IP':
406
+ return /((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))/;
407
+ case 'DATE':
408
+ return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/;
409
+ case 'NUMBER':
410
+ return /^[0-9]*$/;
411
+ case 'ENGLISH':
412
+ return /^[a-zA-Z]+$/;
413
+ case 'CHINESE':
414
+ return /^[\u4E00-\u9FA5]+$/;
415
+ case 'LOWER':
416
+ return /^[a-z]+$/;
417
+ case 'LOWER_UNDERLINE':
418
+ return /^[a-z]+(?:_[a-z]+)*$/;
419
+ case 'UPPER':
420
+ return /^[A-Z]+$/;
421
+ case 'UPPER_UNDERLINE':
422
+ return /^[A-Z]+(?:_[A-Z]+)*$/;
423
+ case 'HTML':
424
+ return /<("[^"]*"|'[^']*'|[^'">])*>/;
425
+ case 'PHOTO':
426
+ return /\.(jpeg|jpg|png|bmp|gif|tiff|raw)$/;
427
+ case 'VIDEO':
428
+ return /\.(swf|avi|flv|mpg|rm|mov|asf|3gp|mkv|rmvb|mp4)$/;
429
+ case 'AUDIO':
430
+ return /\.(wav|mp3)$/;
431
+ case 'DOCUMENT':
432
+ return /\.(doc|docx|ppt|pptx|xls|xlsx|pdf)$/;
433
+ default:
434
+ throw Error('类型错误!');
435
+ }
436
+ };
437
+ /**
438
+ * FormItem的规则
439
+ * @param type 类型
440
+ * @param options
441
+ */
442
+ function getFormItemRules(type, options) {
443
+ var _this = this;
444
+ return [{
445
+ validator: function validator(_, value, c) {
446
+ return __awaiter(_this, void 0, void 0, function () {
447
+ var _a;
448
+ return __generator(this, function (_b) {
449
+ (_a = options === null || options === void 0 ? void 0 : options._validator) === null || _a === void 0 ? void 0 : _a.call(options, _, value, c);
450
+ if (!value || CheckUtil.checkAny(value, type)) return [2 /*return*/, Promise.resolve()];
451
+ if (type === 'LOGIN_NAME') {
452
+ return [2 /*return*/, Promise.reject(new Error((options === null || options === void 0 ? void 0 : options.errMsg) || "".concat((options === null || options === void 0 ? void 0 : options.label) || STR_TYPE[type], "\u53EA\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u6216\u51CF\u53F7\uFF1B\u9996\u5B57\u6BCD\u5FC5\u987B\u4E3A\u5B57\u6BCD\uFF1B\u957F\u5EA6\u4E3A6-18\u4E2A\u5B57\u7B26\uFF1B\u4E0D\u80FD\u5305\u542B\u7279\u6B8A\u5B57\u7B26")))];
453
+ }
454
+ if (type === 'PASSWORD') {
455
+ return [2 /*return*/, Promise.reject(new Error((options === null || options === void 0 ? void 0 : options.errMsg) || "".concat((options === null || options === void 0 ? void 0 : options.label) || STR_TYPE[type], "\u5FC5\u987B\u957F\u5EA6\u8D85\u8FC78-15\u4F4D\uFF0C\u5305\u62EC\u5927\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u7279\u6B8A\u7B26\u53F7")))];
456
+ }
457
+ return [2 /*return*/, Promise.reject(new Error((options === null || options === void 0 ? void 0 : options.errMsg) || "\u683C\u5F0F\u9519\u8BEF\uFF0C\u8BF7\u8F93\u5165\u6B63\u786E\u7684".concat((options === null || options === void 0 ? void 0 : options.label) || STR_TYPE[type], "\uFF01")))];
458
+ });
459
+ });
460
+ }
461
+ }];
462
+ }
463
+ CheckUtil.getFormItemRules = getFormItemRules;
464
+ })(CheckUtil || (CheckUtil = {}));
465
+ export default CheckUtil;
@@ -0,0 +1,43 @@
1
+ export declare const STR_TYPE: {
2
+ LOGIN_NAME: string;
3
+ MOBILE: string;
4
+ TEL: string;
5
+ ID_CARD: string;
6
+ SC_CODE: string;
7
+ /** @name 密码 @description 密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线 */
8
+ PASSWORD: string;
9
+ POSTAL: string;
10
+ QQ: string;
11
+ EMAIL: string;
12
+ URL: string;
13
+ IP: string;
14
+ DATE: string;
15
+ NUMBER: string;
16
+ ENGLISH: string;
17
+ CHINESE: string;
18
+ LOWER: string;
19
+ LOWER_UNDERLINE: string;
20
+ UPPER: string;
21
+ UPPER_UNDERLINE: string;
22
+ HTML: string;
23
+ PHOTO: string;
24
+ VIDEO: string;
25
+ AUDIO: string;
26
+ DOCUMENT: string;
27
+ };
28
+ export declare const WATERMARK_SETTINGS: {
29
+ watermark_txt: string;
30
+ watermark_x: number;
31
+ watermark_y: number;
32
+ watermark_rows: number;
33
+ watermark_cols: number;
34
+ watermark_x_space: number;
35
+ watermark_y_space: number;
36
+ watermark_color: string;
37
+ watermark_alpha: number;
38
+ watermark_fontsize: string;
39
+ watermark_font: string;
40
+ watermark_width: number;
41
+ watermark_height: number;
42
+ watermark_angle: number;
43
+ };
package/esm/common.js ADDED
@@ -0,0 +1,44 @@
1
+ export var STR_TYPE = {
2
+ LOGIN_NAME: "账号",
3
+ MOBILE: "手机号码",
4
+ TEL: "座机",
5
+ ID_CARD: "身份证",
6
+ SC_CODE: "统一社会信用代码",
7
+ /** @name 密码 @description 密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线 */
8
+ PASSWORD: "密码",
9
+ POSTAL: "邮政编码",
10
+ QQ: "QQ号",
11
+ EMAIL: "邮箱",
12
+ URL: "网址",
13
+ IP: "IP",
14
+ DATE: "日期时间",
15
+ NUMBER: "数字",
16
+ ENGLISH: "英文",
17
+ CHINESE: "中文",
18
+ LOWER: "小写",
19
+ LOWER_UNDERLINE: "小写加下划线",
20
+ UPPER: "大写",
21
+ UPPER_UNDERLINE: "大写加下划线",
22
+ HTML: "HTML标记",
23
+ PHOTO: "图片",
24
+ VIDEO: "视频",
25
+ AUDIO: "音频",
26
+ DOCUMENT: "文稿"
27
+ };
28
+ // 水印默认设置
29
+ export var WATERMARK_SETTINGS = {
30
+ watermark_txt: "text",
31
+ watermark_x: 20,
32
+ watermark_y: 20,
33
+ watermark_rows: 20,
34
+ watermark_cols: 20,
35
+ watermark_x_space: 100,
36
+ watermark_y_space: 50,
37
+ watermark_color: "#aaa",
38
+ watermark_alpha: 0.1,
39
+ watermark_fontsize: "18px",
40
+ watermark_font: "微软雅黑",
41
+ watermark_width: 210,
42
+ watermark_height: 80,
43
+ watermark_angle: 20 // 水印倾斜度数
44
+ };
@@ -0,0 +1,7 @@
1
+ declare const config: {
2
+ title: string;
3
+ cacheType: string;
4
+ aesKey: string;
5
+ md5Key: string;
6
+ };
7
+ export default config;
package/esm/config.js ADDED
@@ -0,0 +1,7 @@
1
+ var config = {
2
+ title: 'wyz_',
3
+ cacheType: 'session',
4
+ aesKey: '1234567891123456',
5
+ md5Key: 'ns'
6
+ };
7
+ export default config;