@jhqn/utils-core 0.0.3-beta.7 → 0.0.3
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.cjs +138 -135
- package/dist/index.d.cts +270 -170
- package/dist/index.d.mts +270 -170
- package/dist/index.d.ts +270 -170
- package/dist/index.mjs +125 -131
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
const detectBrowser = require('detect-browser');
|
|
4
4
|
const dayjs = require('dayjs');
|
|
5
|
-
const
|
|
6
|
-
const duration = require('dayjs/plugin/duration');
|
|
7
|
-
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
5
|
+
const zhCN = require('dayjs/locale/zh-cn');
|
|
8
6
|
const customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
7
|
+
const duration = require('dayjs/plugin/duration');
|
|
8
|
+
const localeData = require('dayjs/plugin/localeData');
|
|
9
9
|
const objectSupport = require('dayjs/plugin/objectSupport');
|
|
10
|
-
const
|
|
10
|
+
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
13
13
|
|
|
14
14
|
const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
|
|
15
|
-
const
|
|
16
|
-
const duration__default = /*#__PURE__*/_interopDefaultCompat(duration);
|
|
17
|
-
const relativeTime__default = /*#__PURE__*/_interopDefaultCompat(relativeTime);
|
|
15
|
+
const zhCN__default = /*#__PURE__*/_interopDefaultCompat(zhCN);
|
|
18
16
|
const customParseFormat__default = /*#__PURE__*/_interopDefaultCompat(customParseFormat);
|
|
17
|
+
const duration__default = /*#__PURE__*/_interopDefaultCompat(duration);
|
|
18
|
+
const localeData__default = /*#__PURE__*/_interopDefaultCompat(localeData);
|
|
19
19
|
const objectSupport__default = /*#__PURE__*/_interopDefaultCompat(objectSupport);
|
|
20
|
-
const
|
|
20
|
+
const relativeTime__default = /*#__PURE__*/_interopDefaultCompat(relativeTime);
|
|
21
21
|
|
|
22
22
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
23
23
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
@@ -55,8 +55,12 @@ const jDebug = (...args) => console.log.bind(
|
|
|
55
55
|
`%c[${args.length === 1 ? "DEBUG" : "%s"}]`,
|
|
56
56
|
`${sharedStyle} background: linear-gradient(LightSalmon, Tomato); border-radius: 2px; font-weight: bold; border-top: 2px solid Crimson; border-bottom: 2px solid Crimson;`
|
|
57
57
|
)(...args);
|
|
58
|
-
const jWarn = console.
|
|
59
|
-
const jError = console.error.bind(
|
|
58
|
+
const jWarn = (...args) => console.warn.bind(console, `%c[${args.length === 1 ? "WARN" : "%s"}]`, `${sharedStyle} background: tomato;`)(...args);
|
|
59
|
+
const jError = (...args) => console.error.bind(
|
|
60
|
+
console,
|
|
61
|
+
`%c[${args.length === 1 ? "ERROR" : "%s"}]`,
|
|
62
|
+
`${sharedStyle} background: crimson;`
|
|
63
|
+
)(...args);
|
|
60
64
|
const jInfo = (...args) => console.info.bind(
|
|
61
65
|
console,
|
|
62
66
|
`%c[${args.length === 1 ? "INFO" : "%s"}]`,
|
|
@@ -71,18 +75,15 @@ const jClear = console.clear.bind(console);
|
|
|
71
75
|
|
|
72
76
|
let prevValue;
|
|
73
77
|
const jLogDedupe = (...args) => {
|
|
74
|
-
if (args.length === 0)
|
|
75
|
-
|
|
76
|
-
if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue))
|
|
77
|
-
return;
|
|
78
|
+
if (args.length === 0) return;
|
|
79
|
+
if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue)) return;
|
|
78
80
|
jLog(...args);
|
|
79
81
|
prevValue = args;
|
|
80
82
|
};
|
|
81
83
|
|
|
82
84
|
let logged = false;
|
|
83
85
|
const jLogOnce = (...args) => {
|
|
84
|
-
if (logged)
|
|
85
|
-
return;
|
|
86
|
+
if (logged) return;
|
|
86
87
|
jLog(...args);
|
|
87
88
|
logged = true;
|
|
88
89
|
};
|
|
@@ -120,6 +121,7 @@ const isJSONStr = (str) => {
|
|
|
120
121
|
JSON.parse(str);
|
|
121
122
|
return true;
|
|
122
123
|
} catch (e) {
|
|
124
|
+
jWarn("Failed to parse invalid string", e);
|
|
123
125
|
return false;
|
|
124
126
|
}
|
|
125
127
|
}
|
|
@@ -130,6 +132,7 @@ const isArrStr = (str) => {
|
|
|
130
132
|
try {
|
|
131
133
|
return Array.isArray(JSON.parse(str));
|
|
132
134
|
} catch (e) {
|
|
135
|
+
jWarn("Failed to parse invalid string", e);
|
|
133
136
|
return false;
|
|
134
137
|
}
|
|
135
138
|
}
|
|
@@ -140,39 +143,36 @@ const isEmpty = (val) => {
|
|
|
140
143
|
return !isDef(val) || val === "" || isArray(val) && val.length === 0 || isObject(val) && Object.keys(val).length === 0 || isMap(val) && val.size === 0 || isSet(val) && val.size === 0;
|
|
141
144
|
};
|
|
142
145
|
|
|
143
|
-
const isValidResCode = (res, code = 200) => res.code === code;
|
|
144
|
-
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
145
|
-
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
146
|
-
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
147
|
-
|
|
148
146
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
149
|
-
const cnTelRE = /^0\d{
|
|
147
|
+
const cnTelRE = /^0\d{2,3}-?\d{7,8}$/;
|
|
148
|
+
const cnTelRE2 = /^\(0\d{2,3}\)\d{7,8}$/;
|
|
149
|
+
const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
150
|
+
const cnIdCard15Re = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
151
|
+
const cnIdCard18Re = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
152
|
+
const emailRE = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
153
|
+
const isUSCI = (val) => {
|
|
154
|
+
if (!isDef(val)) return false;
|
|
155
|
+
return cnUSCIRE.test(val);
|
|
156
|
+
};
|
|
150
157
|
const isPhone = (val) => {
|
|
151
|
-
if (!isDef(val))
|
|
152
|
-
return false;
|
|
158
|
+
if (!isDef(val)) return false;
|
|
153
159
|
return cnPhoneRE.test(val.toString());
|
|
154
160
|
};
|
|
155
161
|
const isTel = (val) => {
|
|
156
|
-
if (!isDef(val))
|
|
157
|
-
|
|
158
|
-
return cnTelRE.test(
|
|
162
|
+
if (!isDef(val)) return false;
|
|
163
|
+
const valStr = val.toString().replaceAll(" ", "");
|
|
164
|
+
return cnTelRE.test(valStr) || cnTelRE2.test(valStr);
|
|
159
165
|
};
|
|
160
166
|
const isEmail = (val) => {
|
|
161
|
-
if (!isDef(val))
|
|
162
|
-
|
|
163
|
-
const reg = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
164
|
-
return reg.test(val);
|
|
167
|
+
if (!isDef(val)) return false;
|
|
168
|
+
return emailRE.test(val);
|
|
165
169
|
};
|
|
166
170
|
const isIdCard = (val, compatible = true) => {
|
|
167
|
-
if (!isDef(val))
|
|
168
|
-
|
|
169
|
-
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
170
|
-
const card18 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
171
|
-
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
171
|
+
if (!isDef(val)) return false;
|
|
172
|
+
return cnIdCard18Re.test(val) || (compatible ? cnIdCard15Re.test(val) : false);
|
|
172
173
|
};
|
|
173
174
|
const isNumeric = (val) => {
|
|
174
|
-
if (isDef(val))
|
|
175
|
-
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
175
|
+
if (isDef(val)) return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
176
176
|
return false;
|
|
177
177
|
};
|
|
178
178
|
const checkImg = (ext) => {
|
|
@@ -180,8 +180,7 @@ const checkImg = (ext) => {
|
|
|
180
180
|
};
|
|
181
181
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
182
182
|
const isValidFileType = (file, type) => {
|
|
183
|
-
if (type === "*")
|
|
184
|
-
return true;
|
|
183
|
+
if (type === "*") return true;
|
|
185
184
|
const fileType = file.type;
|
|
186
185
|
const fileName = file.name;
|
|
187
186
|
function validate(item) {
|
|
@@ -203,52 +202,49 @@ const isValidFileType = (file, type) => {
|
|
|
203
202
|
return validate(type);
|
|
204
203
|
};
|
|
205
204
|
|
|
205
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
206
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
207
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
208
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
209
|
+
|
|
206
210
|
const hideMiddle = (str) => {
|
|
207
|
-
if (!isDef(str))
|
|
208
|
-
return "";
|
|
211
|
+
if (!isDef(str)) return "";
|
|
209
212
|
const len = str.length;
|
|
210
|
-
if (len
|
|
211
|
-
return "*";
|
|
212
|
-
if (len === 2)
|
|
213
|
-
return "**";
|
|
213
|
+
if (len <= 2) return "*".repeat(len);
|
|
214
214
|
return str[0] + "*".repeat(len - 2) + str[len - 1];
|
|
215
215
|
};
|
|
216
216
|
const hideThird = (str) => {
|
|
217
|
-
if (!isDef(str))
|
|
218
|
-
return "";
|
|
217
|
+
if (!isDef(str)) return "";
|
|
219
218
|
const len = str.length;
|
|
219
|
+
if (len <= 2) return "*".repeat(len);
|
|
220
220
|
const partLen = Math.round(len / 3);
|
|
221
|
-
if (len === 1)
|
|
222
|
-
return "*";
|
|
223
|
-
if (len === 2)
|
|
224
|
-
return "**";
|
|
225
221
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
226
222
|
};
|
|
227
223
|
const hideHead = (str, count) => {
|
|
228
|
-
if (!isDef(str))
|
|
229
|
-
return "";
|
|
224
|
+
if (!isDef(str)) return "";
|
|
230
225
|
const len = str.length;
|
|
226
|
+
if (len <= 1) return "*".repeat(len);
|
|
231
227
|
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
232
|
-
if (len === 1)
|
|
233
|
-
return "*";
|
|
234
228
|
return "*".repeat(cnt) + str.substring(cnt);
|
|
235
229
|
};
|
|
236
230
|
const hideTail = (str, count) => {
|
|
237
|
-
if (!isDef(str))
|
|
238
|
-
return "";
|
|
231
|
+
if (!isDef(str)) return "";
|
|
239
232
|
const len = str.length;
|
|
233
|
+
if (len <= 1) return "*".repeat(len);
|
|
240
234
|
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
241
|
-
if (len === 1)
|
|
242
|
-
return "*";
|
|
243
235
|
return str.substring(0, len - cnt) + "*".repeat(cnt);
|
|
244
236
|
};
|
|
245
237
|
const hidePhone = (phone) => {
|
|
246
238
|
if (phone) {
|
|
247
|
-
|
|
248
|
-
|
|
239
|
+
const phoneStr = phone.replaceAll(" ", "");
|
|
240
|
+
if (isPhone(phoneStr)) {
|
|
241
|
+
return phoneStr.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
242
|
+
}
|
|
243
|
+
if (cnTelRE.test(phoneStr)) {
|
|
244
|
+
return phoneStr.replace(/^(0\d{2,3})-?\d{3,4}(\d{4})$/, "$1****$2");
|
|
249
245
|
}
|
|
250
|
-
if (
|
|
251
|
-
return
|
|
246
|
+
if (cnTelRE2.test(phoneStr)) {
|
|
247
|
+
return phoneStr.replace(/^\((0\d{2,3})\)\d{3,4}(\d{4})$/, "$1****$2");
|
|
252
248
|
}
|
|
253
249
|
return phone;
|
|
254
250
|
}
|
|
@@ -263,20 +259,6 @@ const hideCardNo = (cardNo, strong = true) => {
|
|
|
263
259
|
}
|
|
264
260
|
return "";
|
|
265
261
|
};
|
|
266
|
-
const hideName = (name) => {
|
|
267
|
-
if (name) {
|
|
268
|
-
let res = "";
|
|
269
|
-
for (let i = 0; i < name.length; i += 1) {
|
|
270
|
-
if (i === 0) {
|
|
271
|
-
res += "*";
|
|
272
|
-
} else {
|
|
273
|
-
res += name[i];
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return res;
|
|
277
|
-
}
|
|
278
|
-
return "";
|
|
279
|
-
};
|
|
280
262
|
const hideSurname = (name) => {
|
|
281
263
|
return hideHead(name, 1);
|
|
282
264
|
};
|
|
@@ -285,13 +267,11 @@ const hideFirstName = (name) => {
|
|
|
285
267
|
};
|
|
286
268
|
const hideEmail = (email) => {
|
|
287
269
|
if (email) {
|
|
288
|
-
if (!email.includes("@"))
|
|
289
|
-
return email;
|
|
270
|
+
if (!email.includes("@")) return email;
|
|
290
271
|
const arr = email.split("@");
|
|
291
272
|
const name = arr[0];
|
|
292
273
|
const domain = arr[1];
|
|
293
|
-
if (!name || !domain)
|
|
294
|
-
return email;
|
|
274
|
+
if (!name || !domain) return email;
|
|
295
275
|
const len = name.length;
|
|
296
276
|
let newName;
|
|
297
277
|
if (len <= 3) {
|
|
@@ -306,33 +286,79 @@ const hideEmail = (email) => {
|
|
|
306
286
|
const hideBankCard = (bankCard) => {
|
|
307
287
|
if (bankCard) {
|
|
308
288
|
const len = bankCard.length;
|
|
309
|
-
if (len <= 10)
|
|
310
|
-
return bankCard;
|
|
289
|
+
if (len <= 10) return bankCard;
|
|
311
290
|
return bankCard.substring(0, 6) + "*".repeat(len - 10) + bankCard.substring(len - 4, len);
|
|
312
291
|
}
|
|
313
292
|
return "";
|
|
314
293
|
};
|
|
315
294
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
295
|
+
let __BASE_ATTACH_URL__;
|
|
296
|
+
function setBaseAttachUrl(baseUrl) {
|
|
297
|
+
__BASE_ATTACH_URL__ = baseUrl;
|
|
298
|
+
}
|
|
299
|
+
function getBaseAttachUrl() {
|
|
300
|
+
return __BASE_ATTACH_URL__;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function parseToJSON(str, reviverFn) {
|
|
304
|
+
return isJSONStr(str) ? JSON.parse(str, reviverFn) : null;
|
|
305
|
+
}
|
|
306
|
+
function parseJSON(str, reviverFn = reviver) {
|
|
307
|
+
return isJSONStr(str) ? JSON.parse(str, reviverFn) : null;
|
|
308
|
+
}
|
|
309
|
+
function stringifyJSON(value, replacerFn = replacer) {
|
|
310
|
+
return JSON.stringify(value, replacerFn);
|
|
311
|
+
}
|
|
312
|
+
function replacer(_key, value) {
|
|
313
|
+
if (isMap(value)) {
|
|
319
314
|
return {
|
|
320
315
|
dataType: "Map",
|
|
321
316
|
value: [...value]
|
|
322
317
|
};
|
|
323
318
|
}
|
|
319
|
+
if (isSet(value)) {
|
|
320
|
+
return {
|
|
321
|
+
dataType: "Set",
|
|
322
|
+
value: [...value]
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (isDate(value)) {
|
|
326
|
+
return {
|
|
327
|
+
dataType: "Date",
|
|
328
|
+
value: value.toISOString()
|
|
329
|
+
};
|
|
330
|
+
}
|
|
324
331
|
return value;
|
|
325
|
-
}
|
|
326
|
-
|
|
332
|
+
}
|
|
333
|
+
function reviver(_key, value) {
|
|
327
334
|
if (typeof value === "object" && value !== null) {
|
|
328
335
|
if (value.dataType === "Map") {
|
|
329
336
|
return new Map(value.value);
|
|
330
337
|
}
|
|
338
|
+
if (value.dataType === "Set") {
|
|
339
|
+
return new Set(value.value);
|
|
340
|
+
}
|
|
341
|
+
if (value.dataType === "Date") {
|
|
342
|
+
return new Date(value.value);
|
|
343
|
+
}
|
|
331
344
|
}
|
|
332
345
|
return value;
|
|
333
|
-
}
|
|
346
|
+
}
|
|
334
347
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
335
348
|
|
|
349
|
+
const toThousands = (num) => {
|
|
350
|
+
const arr = num.toString().split(".");
|
|
351
|
+
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
352
|
+
if (arr.length > 1) return `${integer}.${arr[1]}`;
|
|
353
|
+
return integer;
|
|
354
|
+
};
|
|
355
|
+
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
356
|
+
if (!isDef(currency)) return "";
|
|
357
|
+
const num = Number(currency);
|
|
358
|
+
if (Number.isNaN(num)) return "";
|
|
359
|
+
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
360
|
+
};
|
|
361
|
+
|
|
336
362
|
dayjs__default.extend(localeData__default).locale("zh-cn", zhCN__default);
|
|
337
363
|
dayjs__default.extend(duration__default);
|
|
338
364
|
dayjs__default.extend(relativeTime__default);
|
|
@@ -341,19 +367,15 @@ dayjs__default.extend(objectSupport__default);
|
|
|
341
367
|
const dateFmt = (date, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
342
368
|
const dd = dayjs__default(date);
|
|
343
369
|
let fmt = format;
|
|
344
|
-
if (!isDef(date) || !dd.isValid())
|
|
345
|
-
|
|
346
|
-
if (format === "
|
|
347
|
-
fmt = "YYYY-MM-DD";
|
|
348
|
-
if (format === "datetime")
|
|
349
|
-
fmt = "YYYY-MM-DD HH:mm:ss";
|
|
370
|
+
if (!isDef(date) || !dd.isValid()) return "";
|
|
371
|
+
if (format === "date") fmt = "YYYY-MM-DD";
|
|
372
|
+
if (format === "datetime") fmt = "YYYY-MM-DD HH:mm:ss";
|
|
350
373
|
return dd.format(fmt);
|
|
351
374
|
};
|
|
352
375
|
const dateDuration = (start, end) => {
|
|
353
376
|
const startDay = dayjs__default(start);
|
|
354
377
|
const endDay = dayjs__default(end);
|
|
355
|
-
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid())
|
|
356
|
-
return "";
|
|
378
|
+
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid()) return "";
|
|
357
379
|
const dd = dayjs__default.duration(endDay.diff(startDay));
|
|
358
380
|
const year = dd.years();
|
|
359
381
|
const month = dd.months();
|
|
@@ -366,34 +388,9 @@ const dateDuration = (start, end) => {
|
|
|
366
388
|
return dd.format(format);
|
|
367
389
|
};
|
|
368
390
|
|
|
369
|
-
let __BASE_ATTACH_URL__;
|
|
370
|
-
function setBaseAttachUrl(baseUrl) {
|
|
371
|
-
__BASE_ATTACH_URL__ = baseUrl;
|
|
372
|
-
}
|
|
373
|
-
function getBaseAttachUrl() {
|
|
374
|
-
return __BASE_ATTACH_URL__;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const toThousands = (num) => {
|
|
378
|
-
const arr = num.toString().split(".");
|
|
379
|
-
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
380
|
-
if (arr.length > 1)
|
|
381
|
-
return `${integer}.${arr[1]}`;
|
|
382
|
-
return integer;
|
|
383
|
-
};
|
|
384
|
-
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
385
|
-
if (!isDef(currency))
|
|
386
|
-
return "";
|
|
387
|
-
const num = Number(currency);
|
|
388
|
-
if (Number.isNaN(num))
|
|
389
|
-
return "";
|
|
390
|
-
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
391
|
-
};
|
|
392
|
-
|
|
393
391
|
const resUrl = (url) => {
|
|
394
|
-
if (!isDef(url))
|
|
395
|
-
|
|
396
|
-
if (/^https?:\/\//.test(url) || /^blob:/.test(url) || /^data:/.test(url)) {
|
|
392
|
+
if (!isDef(url)) return void 0;
|
|
393
|
+
if (/^https?:\/\//.test(url) || url.startsWith("blob:") || url.startsWith("data:")) {
|
|
397
394
|
return url;
|
|
398
395
|
}
|
|
399
396
|
const baseUrl = getBaseAttachUrl();
|
|
@@ -423,14 +420,12 @@ const attachFmt = (data) => {
|
|
|
423
420
|
attachList = data.filter(Boolean);
|
|
424
421
|
} else if (typeof data === "string") {
|
|
425
422
|
if (isArrStr(data)) {
|
|
426
|
-
attachList = (
|
|
423
|
+
attachList = (parseJSON(data) || []).filter(Boolean);
|
|
427
424
|
} else {
|
|
428
|
-
const jsonData =
|
|
425
|
+
const jsonData = parseJSON(data);
|
|
429
426
|
const prototypeJson = Object.prototype.toString.call(jsonData);
|
|
430
|
-
if (prototypeJson === "[object Object]")
|
|
431
|
-
|
|
432
|
-
else
|
|
433
|
-
attachList = [{ id: data, name: "name", uri: data, group: "default" }];
|
|
427
|
+
if (prototypeJson === "[object Object]") attachList = [jsonData].filter(Boolean);
|
|
428
|
+
else attachList = [{ id: data, name: "name", uri: data, group: "default" }];
|
|
434
429
|
}
|
|
435
430
|
} else if (prototype === "[object Object]") {
|
|
436
431
|
attachList = [data];
|
|
@@ -441,8 +436,7 @@ const attachFmt = (data) => {
|
|
|
441
436
|
const isNumberArray = (arr) => arr.every((item) => typeof item === "number");
|
|
442
437
|
const isStringArray = (arr) => arr.every((item) => typeof item === "string");
|
|
443
438
|
const naturalSort = (arr) => {
|
|
444
|
-
if (isNumberArray(arr))
|
|
445
|
-
return [...arr].sort((a, b) => a - b);
|
|
439
|
+
if (isNumberArray(arr)) return [...arr].sort((a, b) => a - b);
|
|
446
440
|
if (isStringArray(arr)) {
|
|
447
441
|
return [...arr].sort((a, b) => a.localeCompare(b, "zh-CN")).sort((a, b) => a.length - b.length);
|
|
448
442
|
}
|
|
@@ -494,7 +488,7 @@ const getHostEnv = () => {
|
|
|
494
488
|
};
|
|
495
489
|
const XOR_VAL = 1111;
|
|
496
490
|
const getCodeOfTime = (time) => Math.abs(new Date(time).getTime() ^ XOR_VAL);
|
|
497
|
-
const getCodeOfHour = () => getCodeOfTime(`${dateFmt( new Date(), "YYYY-MM-DD HH")}:00:00`);
|
|
491
|
+
const getCodeOfHour = () => getCodeOfTime(`${dateFmt(/* @__PURE__ */ new Date(), "YYYY-MM-DD HH")}:00:00`);
|
|
498
492
|
const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "date"));
|
|
499
493
|
const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs__default().endOf("month"), "date"));
|
|
500
494
|
|
|
@@ -506,9 +500,16 @@ exports.camel2Pascal = camel2Pascal;
|
|
|
506
500
|
exports.camel2Snake = camel2Snake;
|
|
507
501
|
exports.camel2Title = camel2Title;
|
|
508
502
|
exports.checkImg = checkImg;
|
|
503
|
+
exports.cnIdCard15Re = cnIdCard15Re;
|
|
504
|
+
exports.cnIdCard18Re = cnIdCard18Re;
|
|
505
|
+
exports.cnPhoneRE = cnPhoneRE;
|
|
506
|
+
exports.cnTelRE = cnTelRE;
|
|
507
|
+
exports.cnTelRE2 = cnTelRE2;
|
|
508
|
+
exports.cnUSCIRE = cnUSCIRE;
|
|
509
509
|
exports.currencyFmt = currencyFmt;
|
|
510
510
|
exports.dateDuration = dateDuration;
|
|
511
511
|
exports.dateFmt = dateFmt;
|
|
512
|
+
exports.emailRE = emailRE;
|
|
512
513
|
exports.filterObj = filterObj;
|
|
513
514
|
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
514
515
|
exports.getBaseAttachUrl = getBaseAttachUrl;
|
|
@@ -523,7 +524,6 @@ exports.hideEmail = hideEmail;
|
|
|
523
524
|
exports.hideFirstName = hideFirstName;
|
|
524
525
|
exports.hideHead = hideHead;
|
|
525
526
|
exports.hideMiddle = hideMiddle;
|
|
526
|
-
exports.hideName = hideName;
|
|
527
527
|
exports.hidePhone = hidePhone;
|
|
528
528
|
exports.hideSurname = hideSurname;
|
|
529
529
|
exports.hideTail = hideTail;
|
|
@@ -556,6 +556,7 @@ exports.isString = isString;
|
|
|
556
556
|
exports.isSymbol = isSymbol;
|
|
557
557
|
exports.isTel = isTel;
|
|
558
558
|
exports.isURL = isURL;
|
|
559
|
+
exports.isUSCI = isUSCI;
|
|
559
560
|
exports.isUndefined = isUndefined;
|
|
560
561
|
exports.isValidArrRes = isValidArrRes;
|
|
561
562
|
exports.isValidFileType = isValidFileType;
|
|
@@ -585,6 +586,7 @@ exports.kebab2Title = kebab2Title;
|
|
|
585
586
|
exports.naturalSort = naturalSort;
|
|
586
587
|
exports.naturalSortBy = naturalSortBy;
|
|
587
588
|
exports.nonASCII = nonASCII;
|
|
589
|
+
exports.parseJSON = parseJSON;
|
|
588
590
|
exports.parseToJSON = parseToJSON;
|
|
589
591
|
exports.pascal2Camel = pascal2Camel;
|
|
590
592
|
exports.pascal2Kebab = pascal2Kebab;
|
|
@@ -599,6 +601,7 @@ exports.snake2Camel = snake2Camel;
|
|
|
599
601
|
exports.snake2Kebab = snake2Kebab;
|
|
600
602
|
exports.snake2Pascal = snake2Pascal;
|
|
601
603
|
exports.snake2Title = snake2Title;
|
|
604
|
+
exports.stringifyJSON = stringifyJSON;
|
|
602
605
|
exports.title2Camel = title2Camel;
|
|
603
606
|
exports.title2Kebab = title2Kebab;
|
|
604
607
|
exports.title2Pascal = title2Pascal;
|