@jhqn/utils-core 0.0.3-beta.8 → 0.1.0
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 +82 -106
- package/dist/index.d.cts +138 -48
- package/dist/index.d.mts +138 -48
- package/dist/index.d.ts +138 -48
- package/dist/index.mjs +74 -106
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -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,7 +121,7 @@ const isJSONStr = (str) => {
|
|
|
120
121
|
JSON.parse(str);
|
|
121
122
|
return true;
|
|
122
123
|
} catch (e) {
|
|
123
|
-
|
|
124
|
+
jWarn("Failed to parse invalid string", e);
|
|
124
125
|
return false;
|
|
125
126
|
}
|
|
126
127
|
}
|
|
@@ -131,7 +132,7 @@ const isArrStr = (str) => {
|
|
|
131
132
|
try {
|
|
132
133
|
return Array.isArray(JSON.parse(str));
|
|
133
134
|
} catch (e) {
|
|
134
|
-
|
|
135
|
+
jWarn("Failed to parse invalid string", e);
|
|
135
136
|
return false;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
@@ -143,39 +144,35 @@ const isEmpty = (val) => {
|
|
|
143
144
|
};
|
|
144
145
|
|
|
145
146
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
146
|
-
const cnTelRE = /^0\d{
|
|
147
|
+
const cnTelRE = /^0\d{2,3}-?\d{7,8}$/;
|
|
148
|
+
const cnTelRE2 = /^\(0\d{2,3}\)\d{7,8}$/;
|
|
147
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;
|
|
148
153
|
const isUSCI = (val) => {
|
|
149
|
-
if (!isDef(val))
|
|
150
|
-
return false;
|
|
154
|
+
if (!isDef(val)) return false;
|
|
151
155
|
return cnUSCIRE.test(val);
|
|
152
156
|
};
|
|
153
157
|
const isPhone = (val) => {
|
|
154
|
-
if (!isDef(val))
|
|
155
|
-
return false;
|
|
158
|
+
if (!isDef(val)) return false;
|
|
156
159
|
return cnPhoneRE.test(val.toString());
|
|
157
160
|
};
|
|
158
161
|
const isTel = (val) => {
|
|
159
|
-
if (!isDef(val))
|
|
160
|
-
|
|
161
|
-
return cnTelRE.test(
|
|
162
|
+
if (!isDef(val)) return false;
|
|
163
|
+
const valStr = val.toString().replaceAll(" ", "");
|
|
164
|
+
return cnTelRE.test(valStr) || cnTelRE2.test(valStr);
|
|
162
165
|
};
|
|
163
166
|
const isEmail = (val) => {
|
|
164
|
-
if (!isDef(val))
|
|
165
|
-
|
|
166
|
-
const reg = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
167
|
-
return reg.test(val);
|
|
167
|
+
if (!isDef(val)) return false;
|
|
168
|
+
return emailRE.test(val);
|
|
168
169
|
};
|
|
169
170
|
const isIdCard = (val, compatible = true) => {
|
|
170
|
-
if (!isDef(val))
|
|
171
|
-
|
|
172
|
-
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
173
|
-
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;
|
|
174
|
-
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);
|
|
175
173
|
};
|
|
176
174
|
const isNumeric = (val) => {
|
|
177
|
-
if (isDef(val))
|
|
178
|
-
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
175
|
+
if (isDef(val)) return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
179
176
|
return false;
|
|
180
177
|
};
|
|
181
178
|
const checkImg = (ext) => {
|
|
@@ -183,8 +180,7 @@ const checkImg = (ext) => {
|
|
|
183
180
|
};
|
|
184
181
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
185
182
|
const isValidFileType = (file, type) => {
|
|
186
|
-
if (type === "*")
|
|
187
|
-
return true;
|
|
183
|
+
if (type === "*") return true;
|
|
188
184
|
const fileType = file.type;
|
|
189
185
|
const fileName = file.name;
|
|
190
186
|
function validate(item) {
|
|
@@ -212,51 +208,43 @@ const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(
|
|
|
212
208
|
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
213
209
|
|
|
214
210
|
const hideMiddle = (str) => {
|
|
215
|
-
if (!isDef(str))
|
|
216
|
-
return "";
|
|
211
|
+
if (!isDef(str)) return "";
|
|
217
212
|
const len = str.length;
|
|
218
|
-
if (len
|
|
219
|
-
return "*";
|
|
220
|
-
if (len === 2)
|
|
221
|
-
return "**";
|
|
213
|
+
if (len <= 2) return "*".repeat(len);
|
|
222
214
|
return str[0] + "*".repeat(len - 2) + str[len - 1];
|
|
223
215
|
};
|
|
224
216
|
const hideThird = (str) => {
|
|
225
|
-
if (!isDef(str))
|
|
226
|
-
return "";
|
|
217
|
+
if (!isDef(str)) return "";
|
|
227
218
|
const len = str.length;
|
|
219
|
+
if (len <= 2) return "*".repeat(len);
|
|
228
220
|
const partLen = Math.round(len / 3);
|
|
229
|
-
if (len === 1)
|
|
230
|
-
return "*";
|
|
231
|
-
if (len === 2)
|
|
232
|
-
return "**";
|
|
233
221
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
234
222
|
};
|
|
235
223
|
const hideHead = (str, count) => {
|
|
236
|
-
if (!isDef(str))
|
|
237
|
-
return "";
|
|
224
|
+
if (!isDef(str)) return "";
|
|
238
225
|
const len = str.length;
|
|
226
|
+
if (len <= 1) return "*".repeat(len);
|
|
239
227
|
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
240
|
-
if (len === 1)
|
|
241
|
-
return "*";
|
|
242
228
|
return "*".repeat(cnt) + str.substring(cnt);
|
|
243
229
|
};
|
|
244
230
|
const hideTail = (str, count) => {
|
|
245
|
-
if (!isDef(str))
|
|
246
|
-
return "";
|
|
231
|
+
if (!isDef(str)) return "";
|
|
247
232
|
const len = str.length;
|
|
233
|
+
if (len <= 1) return "*".repeat(len);
|
|
248
234
|
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
249
|
-
if (len === 1)
|
|
250
|
-
return "*";
|
|
251
235
|
return str.substring(0, len - cnt) + "*".repeat(cnt);
|
|
252
236
|
};
|
|
253
237
|
const hidePhone = (phone) => {
|
|
254
238
|
if (phone) {
|
|
255
|
-
|
|
256
|
-
|
|
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");
|
|
257
245
|
}
|
|
258
|
-
if (
|
|
259
|
-
return
|
|
246
|
+
if (cnTelRE2.test(phoneStr)) {
|
|
247
|
+
return phoneStr.replace(/^\((0\d{2,3})\)\d{3,4}(\d{4})$/, "$1****$2");
|
|
260
248
|
}
|
|
261
249
|
return phone;
|
|
262
250
|
}
|
|
@@ -271,20 +259,6 @@ const hideCardNo = (cardNo, strong = true) => {
|
|
|
271
259
|
}
|
|
272
260
|
return "";
|
|
273
261
|
};
|
|
274
|
-
const hideName = (name) => {
|
|
275
|
-
if (name) {
|
|
276
|
-
let res = "";
|
|
277
|
-
for (let i = 0; i < name.length; i += 1) {
|
|
278
|
-
if (i === 0) {
|
|
279
|
-
res += "*";
|
|
280
|
-
} else {
|
|
281
|
-
res += name[i];
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return res;
|
|
285
|
-
}
|
|
286
|
-
return "";
|
|
287
|
-
};
|
|
288
262
|
const hideSurname = (name) => {
|
|
289
263
|
return hideHead(name, 1);
|
|
290
264
|
};
|
|
@@ -293,13 +267,11 @@ const hideFirstName = (name) => {
|
|
|
293
267
|
};
|
|
294
268
|
const hideEmail = (email) => {
|
|
295
269
|
if (email) {
|
|
296
|
-
if (!email.includes("@"))
|
|
297
|
-
return email;
|
|
270
|
+
if (!email.includes("@")) return email;
|
|
298
271
|
const arr = email.split("@");
|
|
299
272
|
const name = arr[0];
|
|
300
273
|
const domain = arr[1];
|
|
301
|
-
if (!name || !domain)
|
|
302
|
-
return email;
|
|
274
|
+
if (!name || !domain) return email;
|
|
303
275
|
const len = name.length;
|
|
304
276
|
let newName;
|
|
305
277
|
if (len <= 3) {
|
|
@@ -314,8 +286,7 @@ const hideEmail = (email) => {
|
|
|
314
286
|
const hideBankCard = (bankCard) => {
|
|
315
287
|
if (bankCard) {
|
|
316
288
|
const len = bankCard.length;
|
|
317
|
-
if (len <= 10)
|
|
318
|
-
return bankCard;
|
|
289
|
+
if (len <= 10) return bankCard;
|
|
319
290
|
return bankCard.substring(0, 6) + "*".repeat(len - 10) + bankCard.substring(len - 4, len);
|
|
320
291
|
}
|
|
321
292
|
return "";
|
|
@@ -329,8 +300,16 @@ function getBaseAttachUrl() {
|
|
|
329
300
|
return __BASE_ATTACH_URL__;
|
|
330
301
|
}
|
|
331
302
|
|
|
332
|
-
|
|
333
|
-
|
|
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) {
|
|
334
313
|
if (isMap(value)) {
|
|
335
314
|
return {
|
|
336
315
|
dataType: "Map",
|
|
@@ -350,8 +329,8 @@ const replacer = (_, value) => {
|
|
|
350
329
|
};
|
|
351
330
|
}
|
|
352
331
|
return value;
|
|
353
|
-
}
|
|
354
|
-
|
|
332
|
+
}
|
|
333
|
+
function reviver(_key, value) {
|
|
355
334
|
if (typeof value === "object" && value !== null) {
|
|
356
335
|
if (value.dataType === "Map") {
|
|
357
336
|
return new Map(value.value);
|
|
@@ -364,22 +343,19 @@ const reviver = (_, value) => {
|
|
|
364
343
|
}
|
|
365
344
|
}
|
|
366
345
|
return value;
|
|
367
|
-
}
|
|
346
|
+
}
|
|
368
347
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
369
348
|
|
|
370
349
|
const toThousands = (num) => {
|
|
371
350
|
const arr = num.toString().split(".");
|
|
372
351
|
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
373
|
-
if (arr.length > 1)
|
|
374
|
-
return `${integer}.${arr[1]}`;
|
|
352
|
+
if (arr.length > 1) return `${integer}.${arr[1]}`;
|
|
375
353
|
return integer;
|
|
376
354
|
};
|
|
377
355
|
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
378
|
-
if (!isDef(currency))
|
|
379
|
-
return "";
|
|
356
|
+
if (!isDef(currency)) return "";
|
|
380
357
|
const num = Number(currency);
|
|
381
|
-
if (Number.isNaN(num))
|
|
382
|
-
return "";
|
|
358
|
+
if (Number.isNaN(num)) return "";
|
|
383
359
|
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
384
360
|
};
|
|
385
361
|
|
|
@@ -391,19 +367,15 @@ dayjs__default.extend(objectSupport__default);
|
|
|
391
367
|
const dateFmt = (date, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
392
368
|
const dd = dayjs__default(date);
|
|
393
369
|
let fmt = format;
|
|
394
|
-
if (!isDef(date) || !dd.isValid())
|
|
395
|
-
|
|
396
|
-
if (format === "
|
|
397
|
-
fmt = "YYYY-MM-DD";
|
|
398
|
-
if (format === "datetime")
|
|
399
|
-
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";
|
|
400
373
|
return dd.format(fmt);
|
|
401
374
|
};
|
|
402
375
|
const dateDuration = (start, end) => {
|
|
403
376
|
const startDay = dayjs__default(start);
|
|
404
377
|
const endDay = dayjs__default(end);
|
|
405
|
-
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid())
|
|
406
|
-
return "";
|
|
378
|
+
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid()) return "";
|
|
407
379
|
const dd = dayjs__default.duration(endDay.diff(startDay));
|
|
408
380
|
const year = dd.years();
|
|
409
381
|
const month = dd.months();
|
|
@@ -417,8 +389,7 @@ const dateDuration = (start, end) => {
|
|
|
417
389
|
};
|
|
418
390
|
|
|
419
391
|
const resUrl = (url) => {
|
|
420
|
-
if (!isDef(url))
|
|
421
|
-
return void 0;
|
|
392
|
+
if (!isDef(url)) return void 0;
|
|
422
393
|
if (/^https?:\/\//.test(url) || url.startsWith("blob:") || url.startsWith("data:")) {
|
|
423
394
|
return url;
|
|
424
395
|
}
|
|
@@ -449,14 +420,12 @@ const attachFmt = (data) => {
|
|
|
449
420
|
attachList = data.filter(Boolean);
|
|
450
421
|
} else if (typeof data === "string") {
|
|
451
422
|
if (isArrStr(data)) {
|
|
452
|
-
attachList = (
|
|
423
|
+
attachList = (parseJSON(data) || []).filter(Boolean);
|
|
453
424
|
} else {
|
|
454
|
-
const jsonData =
|
|
425
|
+
const jsonData = parseJSON(data);
|
|
455
426
|
const prototypeJson = Object.prototype.toString.call(jsonData);
|
|
456
|
-
if (prototypeJson === "[object Object]")
|
|
457
|
-
|
|
458
|
-
else
|
|
459
|
-
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" }];
|
|
460
429
|
}
|
|
461
430
|
} else if (prototype === "[object Object]") {
|
|
462
431
|
attachList = [data];
|
|
@@ -467,8 +436,7 @@ const attachFmt = (data) => {
|
|
|
467
436
|
const isNumberArray = (arr) => arr.every((item) => typeof item === "number");
|
|
468
437
|
const isStringArray = (arr) => arr.every((item) => typeof item === "string");
|
|
469
438
|
const naturalSort = (arr) => {
|
|
470
|
-
if (isNumberArray(arr))
|
|
471
|
-
return [...arr].sort((a, b) => a - b);
|
|
439
|
+
if (isNumberArray(arr)) return [...arr].sort((a, b) => a - b);
|
|
472
440
|
if (isStringArray(arr)) {
|
|
473
441
|
return [...arr].sort((a, b) => a.localeCompare(b, "zh-CN")).sort((a, b) => a.length - b.length);
|
|
474
442
|
}
|
|
@@ -520,7 +488,7 @@ const getHostEnv = () => {
|
|
|
520
488
|
};
|
|
521
489
|
const XOR_VAL = 1111;
|
|
522
490
|
const getCodeOfTime = (time) => Math.abs(new Date(time).getTime() ^ XOR_VAL);
|
|
523
|
-
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`);
|
|
524
492
|
const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "date"));
|
|
525
493
|
const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs__default().endOf("month"), "date"));
|
|
526
494
|
|
|
@@ -532,9 +500,16 @@ exports.camel2Pascal = camel2Pascal;
|
|
|
532
500
|
exports.camel2Snake = camel2Snake;
|
|
533
501
|
exports.camel2Title = camel2Title;
|
|
534
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;
|
|
535
509
|
exports.currencyFmt = currencyFmt;
|
|
536
510
|
exports.dateDuration = dateDuration;
|
|
537
511
|
exports.dateFmt = dateFmt;
|
|
512
|
+
exports.emailRE = emailRE;
|
|
538
513
|
exports.filterObj = filterObj;
|
|
539
514
|
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
540
515
|
exports.getBaseAttachUrl = getBaseAttachUrl;
|
|
@@ -549,7 +524,6 @@ exports.hideEmail = hideEmail;
|
|
|
549
524
|
exports.hideFirstName = hideFirstName;
|
|
550
525
|
exports.hideHead = hideHead;
|
|
551
526
|
exports.hideMiddle = hideMiddle;
|
|
552
|
-
exports.hideName = hideName;
|
|
553
527
|
exports.hidePhone = hidePhone;
|
|
554
528
|
exports.hideSurname = hideSurname;
|
|
555
529
|
exports.hideTail = hideTail;
|
|
@@ -612,6 +586,7 @@ exports.kebab2Title = kebab2Title;
|
|
|
612
586
|
exports.naturalSort = naturalSort;
|
|
613
587
|
exports.naturalSortBy = naturalSortBy;
|
|
614
588
|
exports.nonASCII = nonASCII;
|
|
589
|
+
exports.parseJSON = parseJSON;
|
|
615
590
|
exports.parseToJSON = parseToJSON;
|
|
616
591
|
exports.pascal2Camel = pascal2Camel;
|
|
617
592
|
exports.pascal2Kebab = pascal2Kebab;
|
|
@@ -626,6 +601,7 @@ exports.snake2Camel = snake2Camel;
|
|
|
626
601
|
exports.snake2Kebab = snake2Kebab;
|
|
627
602
|
exports.snake2Pascal = snake2Pascal;
|
|
628
603
|
exports.snake2Title = snake2Title;
|
|
604
|
+
exports.stringifyJSON = stringifyJSON;
|
|
629
605
|
exports.title2Camel = title2Camel;
|
|
630
606
|
exports.title2Kebab = title2Kebab;
|
|
631
607
|
exports.title2Pascal = title2Pascal;
|
package/dist/index.d.cts
CHANGED
|
@@ -60,6 +60,37 @@ type Dict<T = string> = Record<string, T>;
|
|
|
60
60
|
*/
|
|
61
61
|
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
62
|
|
|
63
|
+
interface HostEnv {
|
|
64
|
+
/**
|
|
65
|
+
* 是否是浙里办
|
|
66
|
+
*/
|
|
67
|
+
readonly zlb: boolean
|
|
68
|
+
/**
|
|
69
|
+
* 是否是专有钉
|
|
70
|
+
*/
|
|
71
|
+
readonly zyd: boolean
|
|
72
|
+
/**
|
|
73
|
+
* 是否是浙政钉
|
|
74
|
+
*/
|
|
75
|
+
readonly zzd: boolean
|
|
76
|
+
/**
|
|
77
|
+
* 是否是钉钉/专有钉/浙政钉
|
|
78
|
+
*/
|
|
79
|
+
readonly dd: boolean
|
|
80
|
+
/**
|
|
81
|
+
* 是否是微信
|
|
82
|
+
*/
|
|
83
|
+
readonly wx: boolean
|
|
84
|
+
/**
|
|
85
|
+
* 是否是支付宝
|
|
86
|
+
*/
|
|
87
|
+
readonly zfb: boolean
|
|
88
|
+
/**
|
|
89
|
+
* 是否是小程序
|
|
90
|
+
*/
|
|
91
|
+
readonly mini: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
63
94
|
/**
|
|
64
95
|
* snake2Kebab
|
|
65
96
|
* @param {string} str 字符串
|
|
@@ -273,94 +304,126 @@ declare const jLogOnce: (...args: any[]) => void;
|
|
|
273
304
|
/**
|
|
274
305
|
* 隐藏中间部分
|
|
275
306
|
* @param {string} str 需要隐藏的字符串
|
|
307
|
+
* @returns {string} 隐藏后的字符串
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* hideMiddle('A') // '*'
|
|
311
|
+
* hideMiddle('AB') // '**'
|
|
312
|
+
* hideMiddle('ABC') // 'A*C'
|
|
313
|
+
* hideMiddle('ABCD') // 'A**D'
|
|
314
|
+
* hideMiddle('ABCDE') // 'A***E'
|
|
315
|
+
* ```
|
|
276
316
|
*/
|
|
277
317
|
declare const hideMiddle: (str: UnDef<string>) => string;
|
|
278
318
|
/**
|
|
279
319
|
* 隐藏首尾仅保留中间3分之1
|
|
280
320
|
* @param {string} str 需要隐藏的字符串
|
|
321
|
+
* @returns {string} 隐藏后的字符串
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* hideThird('A') // '*'
|
|
325
|
+
* hideThird('AB') // '**'
|
|
326
|
+
* hideThird('ABC') // 'A*C'
|
|
327
|
+
* hideThird('ABCD') // 'A**D'
|
|
328
|
+
* hideThird('ABCDE') // 'AB*DE'
|
|
329
|
+
* ```
|
|
281
330
|
*/
|
|
282
331
|
declare const hideThird: (str: UnDef<string>) => string;
|
|
283
332
|
/**
|
|
284
333
|
* 隐藏首部
|
|
285
334
|
* @param {string} str 需要隐藏的字符串
|
|
286
335
|
* @param {number} count 隐藏的字符数
|
|
336
|
+
* @returns {string} 隐藏后的字符串
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* hideHead('A') // '*'
|
|
340
|
+
* hideHead('AB') // '*B'
|
|
341
|
+
* hideHead('ABC') // '**C'
|
|
342
|
+
* hideHead('ABC', 1) // '*BC'
|
|
343
|
+
* ```
|
|
287
344
|
*/
|
|
288
345
|
declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
289
346
|
/**
|
|
290
347
|
* 隐藏尾部
|
|
291
348
|
* @param {string} str 需要隐藏的字符串
|
|
292
349
|
* @param {number} count 隐藏的字符数
|
|
350
|
+
* @returns {string} 隐藏后的字符串
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* hideTail('A') // '*'
|
|
354
|
+
* hideTail('AB') // 'A*'
|
|
355
|
+
* hideTail('ABC') // 'A**'
|
|
356
|
+
* hideTail('ABC', 1) // 'AB*'
|
|
357
|
+
* ```
|
|
293
358
|
*/
|
|
294
359
|
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
295
360
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @param {string} phone
|
|
361
|
+
* 隐藏手机号/座机号
|
|
362
|
+
* @param {string} phone 手机号/座机号
|
|
363
|
+
* @returns {string} 隐藏后的手机号/座机号
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* hidePhone('13800138000') // '138****8000'
|
|
367
|
+
* hidePhone('010-12345678') // '010****5678'
|
|
368
|
+
* hidePhone('(010)12345678') // '(010)****5678'
|
|
369
|
+
* ```
|
|
298
370
|
*/
|
|
299
371
|
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
300
372
|
/**
|
|
301
373
|
* 隐藏身份证号
|
|
302
374
|
* @param {string} cardNo 身份证号
|
|
303
375
|
* @param {boolean} strong 是否强化隐藏
|
|
376
|
+
* @returns {string} 隐藏后的身份证号
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts
|
|
379
|
+
* hideCardNo('33072319641008384x') // '3****************x'
|
|
380
|
+
* hideCardNo('33072319641008384x', false) // '3***23196410*****x'
|
|
381
|
+
* ```
|
|
304
382
|
*/
|
|
305
383
|
declare const hideCardNo: (cardNo: UnDef<string>, strong?: boolean) => string;
|
|
306
|
-
/**
|
|
307
|
-
* 隐藏姓名第一个字
|
|
308
|
-
* @param {string} name 姓名
|
|
309
|
-
* @deprecated 请使用 hideSurname
|
|
310
|
-
*/
|
|
311
|
-
declare const hideName: (name: UnDef<string>) => string;
|
|
312
384
|
/**
|
|
313
385
|
* 隐藏姓氏
|
|
314
386
|
* @param {string} name 姓名
|
|
387
|
+
* @returns {string} 隐藏后的姓名
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* hideSurname('张三') // '*三'
|
|
391
|
+
* hideSurname('司马懿') // '*马懿'
|
|
392
|
+
* ```
|
|
315
393
|
*/
|
|
316
394
|
declare const hideSurname: (name: UnDef<string>) => string;
|
|
317
395
|
/**
|
|
318
396
|
* 隐藏名字
|
|
319
397
|
* @param {string} name 姓名
|
|
398
|
+
* @returns {string} 隐藏后的姓名
|
|
399
|
+
* @example
|
|
400
|
+
* ```ts
|
|
401
|
+
* hideFirstName('张三') // '张*'
|
|
402
|
+
* hideFirstName('司马懿') // '司马*'
|
|
403
|
+
* ```
|
|
320
404
|
*/
|
|
321
405
|
declare const hideFirstName: (name: UnDef<string>) => string;
|
|
322
406
|
/**
|
|
323
407
|
* 隐藏邮箱
|
|
324
408
|
* @param {string} email 邮箱
|
|
409
|
+
* @returns {string} 隐藏后的邮箱
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* hideEmail('example@hotmail.com') // 'exam***@hotmail.com'
|
|
413
|
+
* ```
|
|
325
414
|
*/
|
|
326
415
|
declare const hideEmail: (email: UnDef<string>) => string;
|
|
327
416
|
/**
|
|
328
417
|
* 隐藏银行卡号
|
|
329
418
|
* @param {string} bankCard 银行卡号
|
|
419
|
+
* @returns {string} 隐藏后的银行卡号
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* hideBankCard('6222021001123456789') // '622202********6789'
|
|
423
|
+
* ```
|
|
330
424
|
*/
|
|
331
425
|
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
332
426
|
|
|
333
|
-
interface HostEnv {
|
|
334
|
-
/**
|
|
335
|
-
* 是否是浙里办
|
|
336
|
-
*/
|
|
337
|
-
readonly zlb: boolean
|
|
338
|
-
/**
|
|
339
|
-
* 是否是专有钉
|
|
340
|
-
*/
|
|
341
|
-
readonly zyd: boolean
|
|
342
|
-
/**
|
|
343
|
-
* 是否是浙政钉
|
|
344
|
-
*/
|
|
345
|
-
readonly zzd: boolean
|
|
346
|
-
/**
|
|
347
|
-
* 是否是钉钉/专有钉/浙政钉
|
|
348
|
-
*/
|
|
349
|
-
readonly dd: boolean
|
|
350
|
-
/**
|
|
351
|
-
* 是否是微信
|
|
352
|
-
*/
|
|
353
|
-
readonly wx: boolean
|
|
354
|
-
/**
|
|
355
|
-
* 是否是支付宝
|
|
356
|
-
*/
|
|
357
|
-
readonly zfb: boolean
|
|
358
|
-
/**
|
|
359
|
-
* 是否是小程序
|
|
360
|
-
*/
|
|
361
|
-
readonly mini: boolean
|
|
362
|
-
}
|
|
363
|
-
|
|
364
427
|
/**
|
|
365
428
|
* 判断是否是浏览器环境
|
|
366
429
|
*/
|
|
@@ -419,23 +482,42 @@ declare function setBaseAttachUrl(baseUrl: string): void;
|
|
|
419
482
|
declare function getBaseAttachUrl(): string;
|
|
420
483
|
|
|
421
484
|
/**
|
|
422
|
-
*
|
|
423
|
-
* @
|
|
424
|
-
* @param
|
|
485
|
+
* JSON 字符串转对象
|
|
486
|
+
* @template T - 解析数据类型
|
|
487
|
+
* @param {string} str - JSON字符串
|
|
488
|
+
* @param {(this: any, key: string, value: any) => any} reviverFn - 解析函数
|
|
489
|
+
* @returns {Nullable<T>} 解析后的对象
|
|
490
|
+
* @deprecated 请使用 `parseJSON`
|
|
491
|
+
*/
|
|
492
|
+
declare function parseToJSON<T = any>(str: string, reviverFn?: (this: any, key: string, value: any) => any): Nullable<T>;
|
|
493
|
+
/**
|
|
494
|
+
* JSON 字符串转对象
|
|
495
|
+
* @alias parseToJSON
|
|
496
|
+
* @template T - 解析数据类型
|
|
497
|
+
* @param {string} str - JSON字符串
|
|
498
|
+
* @param {(this: any, key: string, value: any) => any} reviverFn - 解析函数
|
|
499
|
+
* @returns {Nullable<T>} 解析后的对象
|
|
500
|
+
*/
|
|
501
|
+
declare function parseJSON<T = any>(str: string, reviverFn?: (this: any, key: string, value: any) => any): Nullable<T>;
|
|
502
|
+
/**
|
|
503
|
+
* 对象转 JSON 字符串
|
|
504
|
+
* @param {any} value - 对象
|
|
505
|
+
* @param {(this: any, key: string, value: any) => any} replacerFn - 替换函数
|
|
506
|
+
* @returns {string} JSON 字符串
|
|
425
507
|
*/
|
|
426
|
-
declare
|
|
508
|
+
declare function stringifyJSON(value: any, replacerFn?: (this: any, key: string, value: any) => any): string;
|
|
427
509
|
/**
|
|
428
510
|
* JSON.stringify() second param
|
|
429
|
-
* @param
|
|
511
|
+
* @param _key
|
|
430
512
|
* @param value
|
|
431
513
|
*/
|
|
432
|
-
declare
|
|
514
|
+
declare function replacer(_key: any, value: any): any;
|
|
433
515
|
/**
|
|
434
516
|
* JSON.parse() second param
|
|
435
|
-
* @param
|
|
517
|
+
* @param _key
|
|
436
518
|
* @param value
|
|
437
519
|
*/
|
|
438
|
-
declare
|
|
520
|
+
declare function reviver(_key: any, value: any): any;
|
|
439
521
|
/**
|
|
440
522
|
* 过滤obj中仅包括keys的部分
|
|
441
523
|
* @param {Record<string,any>} obj 对象
|
|
@@ -714,6 +796,13 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
714
796
|
*/
|
|
715
797
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
798
|
|
|
799
|
+
declare const cnPhoneRE: RegExp;
|
|
800
|
+
declare const cnTelRE: RegExp;
|
|
801
|
+
declare const cnTelRE2: RegExp;
|
|
802
|
+
declare const cnUSCIRE: RegExp;
|
|
803
|
+
declare const cnIdCard15Re: RegExp;
|
|
804
|
+
declare const cnIdCard18Re: RegExp;
|
|
805
|
+
declare const emailRE: RegExp;
|
|
717
806
|
/**
|
|
718
807
|
* 是否是[统一社会信用代码](https://zh.wikipedia.org/zh-cn/%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81)
|
|
719
808
|
* @example
|
|
@@ -793,4 +882,5 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
793
882
|
*/
|
|
794
883
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
884
|
|
|
796
|
-
export {
|
|
885
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUSCI, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, nonASCII, parseJSON, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, stringifyJSON, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
886
|
+
export type { Dict, HostEnv, MaybeArray, NullOrUndefinable, Nullable, Numeric, PageReq, PageRes, PageResData, PartialBy, Res, UnDef, Undefinable, VK };
|