@jhqn/utils-core 0.0.3-beta.1 → 0.0.3-beta.10

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 CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  const detectBrowser = require('detect-browser');
4
4
  const dayjs = require('dayjs');
5
- const localeData = require('dayjs/plugin/localeData');
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 zhCN = require('dayjs/locale/zh-cn');
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 localeData__default = /*#__PURE__*/_interopDefaultCompat(localeData);
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 zhCN__default = /*#__PURE__*/_interopDefaultCompat(zhCN);
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());
@@ -115,22 +115,26 @@ const isURL = (val) => getVariableType(val) === "url";
115
115
  const isError = (val) => getVariableType(val) === "error";
116
116
  const isDef = (val) => !isNull(val) && !isUndefined(val);
117
117
  const isJSONStr = (str) => {
118
- if (isDef(str))
118
+ if (isDef(str)) {
119
119
  try {
120
120
  JSON.parse(str);
121
121
  return true;
122
122
  } catch (e) {
123
+ jError("isJSONStr", e);
123
124
  return false;
124
125
  }
126
+ }
125
127
  return false;
126
128
  };
127
129
  const isArrStr = (str) => {
128
- if (isDef(str))
130
+ if (isDef(str)) {
129
131
  try {
130
132
  return Array.isArray(JSON.parse(str));
131
133
  } catch (e) {
134
+ jError("isArrStr", e);
132
135
  return false;
133
136
  }
137
+ }
134
138
  return false;
135
139
  };
136
140
  const isValidKey = (key, object) => key in object;
@@ -138,13 +142,14 @@ const isEmpty = (val) => {
138
142
  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;
139
143
  };
140
144
 
141
- const isValidResCode = (res, code = 200) => res.code === code;
142
- const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
143
- const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
144
- const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
145
-
146
145
  const cnPhoneRE = /^1[3-9]\d{9}$/;
147
146
  const cnTelRE = /^0\d{9,11}$/;
147
+ const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
148
+ const isUSCI = (val) => {
149
+ if (!isDef(val))
150
+ return false;
151
+ return cnUSCIRE.test(val);
152
+ };
148
153
  const isPhone = (val) => {
149
154
  if (!isDef(val))
150
155
  return false;
@@ -158,14 +163,14 @@ const isTel = (val) => {
158
163
  const isEmail = (val) => {
159
164
  if (!isDef(val))
160
165
  return false;
161
- const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
166
+ const reg = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
162
167
  return reg.test(val);
163
168
  };
164
169
  const isIdCard = (val, compatible = true) => {
165
170
  if (!isDef(val))
166
171
  return false;
167
- const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
168
- 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}[\dXx]$/;
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;
169
174
  return card18.test(val) || (compatible ? card15.test(val) : false);
170
175
  };
171
176
  const isNumeric = (val) => {
@@ -201,10 +206,17 @@ const isValidFileType = (file, type) => {
201
206
  return validate(type);
202
207
  };
203
208
 
209
+ const isValidResCode = (res, code = 200) => res.code === code;
210
+ const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
211
+ const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
212
+ const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
213
+
204
214
  const hideMiddle = (str) => {
205
215
  if (!isDef(str))
206
216
  return "";
207
217
  const len = str.length;
218
+ if (len === 0)
219
+ return "";
208
220
  if (len === 1)
209
221
  return "*";
210
222
  if (len === 2)
@@ -227,6 +239,8 @@ const hideHead = (str, count) => {
227
239
  return "";
228
240
  const len = str.length;
229
241
  const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
242
+ if (len === 0)
243
+ return "";
230
244
  if (len === 1)
231
245
  return "*";
232
246
  return "*".repeat(cnt) + str.substring(cnt);
@@ -236,6 +250,8 @@ const hideTail = (str, count) => {
236
250
  return "";
237
251
  const len = str.length;
238
252
  const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
253
+ if (len === 0)
254
+ return "";
239
255
  if (len === 1)
240
256
  return "*";
241
257
  return str.substring(0, len - cnt) + "*".repeat(cnt);
@@ -311,14 +327,34 @@ const hideBankCard = (bankCard) => {
311
327
  return "";
312
328
  };
313
329
 
330
+ let __BASE_ATTACH_URL__;
331
+ function setBaseAttachUrl(baseUrl) {
332
+ __BASE_ATTACH_URL__ = baseUrl;
333
+ }
334
+ function getBaseAttachUrl() {
335
+ return __BASE_ATTACH_URL__;
336
+ }
337
+
314
338
  const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
315
339
  const replacer = (_, value) => {
316
- if (value instanceof Map) {
340
+ if (isMap(value)) {
317
341
  return {
318
342
  dataType: "Map",
319
343
  value: [...value]
320
344
  };
321
345
  }
346
+ if (isSet(value)) {
347
+ return {
348
+ dataType: "Set",
349
+ value: [...value]
350
+ };
351
+ }
352
+ if (isDate(value)) {
353
+ return {
354
+ dataType: "Date",
355
+ value: value.toISOString()
356
+ };
357
+ }
322
358
  return value;
323
359
  };
324
360
  const reviver = (_, value) => {
@@ -326,11 +362,33 @@ const reviver = (_, value) => {
326
362
  if (value.dataType === "Map") {
327
363
  return new Map(value.value);
328
364
  }
365
+ if (value.dataType === "Set") {
366
+ return new Set(value.value);
367
+ }
368
+ if (value.dataType === "Date") {
369
+ return new Date(value.value);
370
+ }
329
371
  }
330
372
  return value;
331
373
  };
332
374
  const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
333
375
 
376
+ const toThousands = (num) => {
377
+ const arr = num.toString().split(".");
378
+ const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
379
+ if (arr.length > 1)
380
+ return `${integer}.${arr[1]}`;
381
+ return integer;
382
+ };
383
+ const currencyFmt = (currency, maximumFractionDigits = 2) => {
384
+ if (!isDef(currency))
385
+ return "";
386
+ const num = Number(currency);
387
+ if (Number.isNaN(num))
388
+ return "";
389
+ return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
390
+ };
391
+
334
392
  dayjs__default.extend(localeData__default).locale("zh-cn", zhCN__default);
335
393
  dayjs__default.extend(duration__default);
336
394
  dayjs__default.extend(relativeTime__default);
@@ -364,34 +422,10 @@ const dateDuration = (start, end) => {
364
422
  return dd.format(format);
365
423
  };
366
424
 
367
- let __BASE_ATTACH_URL__;
368
- function setBaseAttachUrl(baseUrl) {
369
- __BASE_ATTACH_URL__ = baseUrl;
370
- }
371
- function getBaseAttachUrl() {
372
- return __BASE_ATTACH_URL__;
373
- }
374
-
375
- const toThousands = (num) => {
376
- const arr = num.toString().split(".");
377
- const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
378
- if (arr.length > 1)
379
- return `${integer}.${arr[1]}`;
380
- return integer;
381
- };
382
- const currencyFmt = (currency, maximumFractionDigits = 2) => {
383
- if (!isDef(currency))
384
- return "";
385
- const num = Number(currency);
386
- if (Number.isNaN(num))
387
- return "";
388
- return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
389
- };
390
-
391
425
  const resUrl = (url) => {
392
426
  if (!isDef(url))
393
427
  return void 0;
394
- if (/^https?:\/\//.test(url) || /^blob:/.test(url) || /^data:/.test(url)) {
428
+ if (/^https?:\/\//.test(url) || url.startsWith("blob:") || url.startsWith("data:")) {
395
429
  return url;
396
430
  }
397
431
  const baseUrl = getBaseAttachUrl();
@@ -415,11 +449,11 @@ const recoverFile = (resource) => {
415
449
  const attachFmt = (data) => {
416
450
  let attachList = [];
417
451
  const prototype = Object.prototype.toString.call(data);
418
- if (!data)
452
+ if (!data) {
419
453
  attachList = [];
420
- else if (Array.isArray(data))
454
+ } else if (Array.isArray(data)) {
421
455
  attachList = data.filter(Boolean);
422
- else if (typeof data === "string") {
456
+ } else if (typeof data === "string") {
423
457
  if (isArrStr(data)) {
424
458
  attachList = (parseToJSON(data) || []).filter(Boolean);
425
459
  } else {
@@ -430,11 +464,29 @@ const attachFmt = (data) => {
430
464
  else
431
465
  attachList = [{ id: data, name: "name", uri: data, group: "default" }];
432
466
  }
433
- } else if (prototype === "[object Object]")
467
+ } else if (prototype === "[object Object]") {
434
468
  attachList = [data];
469
+ }
435
470
  return attachList.map(recoverFile);
436
471
  };
437
472
 
473
+ const isNumberArray = (arr) => arr.every((item) => typeof item === "number");
474
+ const isStringArray = (arr) => arr.every((item) => typeof item === "string");
475
+ const naturalSort = (arr) => {
476
+ if (isNumberArray(arr))
477
+ return [...arr].sort((a, b) => a - b);
478
+ if (isStringArray(arr)) {
479
+ return [...arr].sort((a, b) => a.localeCompare(b, "zh-CN")).sort((a, b) => a.length - b.length);
480
+ }
481
+ const newArr = [...arr].sort();
482
+ const validArr = newArr.filter((a) => isDef(a));
483
+ const invalidArr = newArr.filter((a) => !isDef(a));
484
+ return naturalSort(validArr).concat(invalidArr);
485
+ };
486
+ const naturalSortBy = (arr, key) => {
487
+ return [...arr].sort((a, b) => naturalSort([a[key], b[key]])[0] === a[key] ? -1 : 1);
488
+ };
489
+
438
490
  const inBrowser = typeof window !== "undefined";
439
491
  const waitTime = (time = 100) => {
440
492
  return new Promise((resolve) => {
@@ -456,7 +508,8 @@ const getHostEnv = () => {
456
508
  const ua = userAgent.toLowerCase();
457
509
  const zlb = ua.includes("@zlb");
458
510
  const zyd = ua.includes("saas");
459
- const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
511
+ const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd") || ua.includes("dingtalk-win");
512
+ const dd = ua.includes("taurusapp");
460
513
  const wx = ua.includes("micromessenger");
461
514
  const zfb = ua.includes("alipay");
462
515
  const mini = ua.includes("miniprogram");
@@ -464,6 +517,7 @@ const getHostEnv = () => {
464
517
  zlb,
465
518
  zyd,
466
519
  zzd,
520
+ dd,
467
521
  wx,
468
522
  zfb,
469
523
  mini
@@ -534,6 +588,7 @@ exports.isString = isString;
534
588
  exports.isSymbol = isSymbol;
535
589
  exports.isTel = isTel;
536
590
  exports.isURL = isURL;
591
+ exports.isUSCI = isUSCI;
537
592
  exports.isUndefined = isUndefined;
538
593
  exports.isValidArrRes = isValidArrRes;
539
594
  exports.isValidFileType = isValidFileType;
@@ -560,6 +615,8 @@ exports.kebab2Camel = kebab2Camel;
560
615
  exports.kebab2Pascal = kebab2Pascal;
561
616
  exports.kebab2Snake = kebab2Snake;
562
617
  exports.kebab2Title = kebab2Title;
618
+ exports.naturalSort = naturalSort;
619
+ exports.naturalSortBy = naturalSortBy;
563
620
  exports.nonASCII = nonASCII;
564
621
  exports.parseToJSON = parseToJSON;
565
622
  exports.pascal2Camel = pascal2Camel;
package/dist/index.d.cts CHANGED
@@ -7,6 +7,59 @@ import { ConfigType } from 'dayjs';
7
7
  export { Dayjs, default as dayjs } from 'dayjs';
8
8
  export { detect } from 'detect-browser';
9
9
 
10
+ /**
11
+ * 数字或字符串
12
+ */
13
+ type Numeric = number | string;
14
+ /**
15
+ * 可 Null
16
+ */
17
+ type Nullable<T> = T | null;
18
+ /**
19
+ * 可 Undefined
20
+ */
21
+ type Undefinable<T> = T | undefined;
22
+ /**
23
+ * 可 Null 或 Undefined
24
+ */
25
+ type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
26
+ /**
27
+ * alias for NullOrUndefinable
28
+ */
29
+ type UnDef<T> = NullOrUndefinable<T>;
30
+ /**
31
+ * 请求结果
32
+ */
33
+ type Res<T = any> = Service.Response<T>;
34
+ /**
35
+ * 分页请求结果数据
36
+ */
37
+ type PageResData<T = any> = Service.PageResponseData<T>;
38
+ /**
39
+ * 分页请求结果
40
+ */
41
+ type PageRes<T = any> = Service.PageResponse<T>;
42
+ /**
43
+ * 分页请求参数
44
+ */
45
+ type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
46
+ /**
47
+ * 可能是数组
48
+ */
49
+ type MaybeArray<T = any> = T | Array<T>;
50
+ /**
51
+ * 枚举键值对
52
+ */
53
+ type VK<T = string> = Record<string | number, T>;
54
+ /**
55
+ * 字典
56
+ */
57
+ type Dict<T = string> = Record<string, T>;
58
+ /**
59
+ * 使某键可选
60
+ */
61
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
62
+
10
63
  /**
11
64
  * snake2Kebab
12
65
  * @param {string} str 字符串
@@ -217,43 +270,6 @@ declare const jLogDedupe: (...args: any[]) => void;
217
270
  */
218
271
  declare const jLogOnce: (...args: any[]) => void;
219
272
 
220
- /**
221
- * 数字或字符串
222
- */
223
- declare type Numeric = number | string;
224
- /**
225
- * 可 Null
226
- */
227
- declare type Nullable<T> = T | null;
228
- /**
229
- * 可 Undefined
230
- */
231
- declare type Undefinable<T> = T | undefined;
232
- /**
233
- * 可 Null 或 Undefined
234
- */
235
- declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
236
- /**
237
- * alias for NullOrUndefinable
238
- */
239
- declare type UnDef<T> = NullOrUndefinable<T>;
240
- /**
241
- * 请求结果
242
- */
243
- declare type Res<T = any> = Service.Response<T>;
244
- /**
245
- * 分页请求结果数据
246
- */
247
- declare type PageResData<T = any> = Service.PageResponseData<T>;
248
- /**
249
- * 分页请求结果
250
- */
251
- declare type PageRes<T = any> = Service.PageResponse<T>;
252
- /**
253
- * 可能是数组
254
- */
255
- declare type MaybeArray<T = any> = T | Array<T>;
256
-
257
273
  /**
258
274
  * 隐藏中间部分
259
275
  * @param {string} str 需要隐藏的字符串
@@ -327,6 +343,10 @@ interface HostEnv {
327
343
  * 是否是浙政钉
328
344
  */
329
345
  readonly zzd: boolean
346
+ /**
347
+ * 是否是钉钉/专有钉/浙政钉
348
+ */
349
+ readonly dd: boolean
330
350
  /**
331
351
  * 是否是微信
332
352
  */
@@ -362,6 +382,16 @@ declare const fixiOSInputAutoZoomIn: () => void;
362
382
  declare const userAgent: string;
363
383
  /**
364
384
  * 获取宿主环境信息
385
+ * @returns {HostEnv} 宿主环境信息
386
+ * @example
387
+ * const hostEnv = getHostEnv()
388
+ * hostEnv.zlb // 浙里办
389
+ * hostEnv.zyd // 专有钉
390
+ * hostEnv.zzd // 浙政钉
391
+ * hostEnv.dd // 钉钉/专有钉/浙政钉
392
+ * hostEnv.wx // 微信
393
+ * hostEnv.zfb // 支付宝
394
+ * hostEnv.mini // 小程序
365
395
  */
366
396
  declare const getHostEnv: () => HostEnv;
367
397
 
@@ -378,12 +408,22 @@ declare const getCodeOfDate: () => number;
378
408
  */
379
409
  declare const getCodeOfMonth: () => number;
380
410
 
411
+ /**
412
+ * 设置文件基本路径
413
+ * @param baseUrl
414
+ */
415
+ declare function setBaseAttachUrl(baseUrl: string): void;
416
+ /**
417
+ * 获取文件基本路径
418
+ */
419
+ declare function getBaseAttachUrl(): string;
420
+
381
421
  /**
382
422
  * Json字符串转对象
383
423
  * @param str
384
424
  * @param reviver
385
425
  */
386
- declare const parseToJSON: <T = any>(str: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => Nullable<T>;
426
+ declare const parseToJSON: <T = any>(str: string, reviver?: (this: any, key: string, value: any) => any) => Nullable<T>;
387
427
  /**
388
428
  * JSON.stringify() second param
389
429
  * @param _
@@ -406,13 +446,25 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
406
446
  [k: string]: any;
407
447
  };
408
448
 
449
+ /**
450
+ * 千位分隔符
451
+ * @param num
452
+ */
453
+ declare const toThousands: (num: number) => string | undefined;
454
+ /**
455
+ * 货币格式化
456
+ * @param {number | string | bigint} currency - 金额
457
+ * @param {number} [maximumFractionDigits] - 小数位数
458
+ */
459
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
460
+
409
461
  /**
410
462
  * 格式化时间
411
463
  * @param {import('dayjs').ConfigType} date 时间
412
464
  * @param {string} format 格式
413
465
  * @returns {string} 格式化后的时间
414
466
  */
415
- declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime') => string;
467
+ declare const dateFmt: (date: ConfigType, format?: string | "date" | "datetime") => string;
416
468
  /**
417
469
  * 格式化时间间隔
418
470
  * @param {import('dayjs').ConfigType} start 开始时间
@@ -420,29 +472,6 @@ declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime')
420
472
  */
421
473
  declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
422
474
 
423
- /**
424
- * 设置文件基本路径
425
- * @param key
426
- * @param baseUrl
427
- */
428
- declare function setBaseAttachUrl(baseUrl: string): void;
429
- /**
430
- * 获取文件基本路径
431
- */
432
- declare function getBaseAttachUrl(): string;
433
-
434
- /**
435
- * 千位分隔符
436
- * @param num
437
- */
438
- declare const toThousands: (num: number) => string | undefined;
439
- /**
440
- * 货币格式化
441
- * @param {number | string | bigint} currency - 金额
442
- * @param {number} [maximumFractionDigits] - 小数位数
443
- */
444
- declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
445
-
446
475
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
447
476
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
448
477
  type ElementPlusUploadFileStatus = 'ready' | 'uploading' | 'success' | 'fail'
@@ -491,16 +520,16 @@ declare const recoverFile: (resource: Resource) => {
491
520
  group: string;
492
521
  id: string;
493
522
  name: string;
494
- size?: number | undefined;
495
- uid?: string | undefined;
496
- objectUrl?: string | undefined;
497
- isImage?: boolean | undefined;
498
- message?: string | undefined;
499
- deletable?: boolean | undefined;
500
- reupload?: boolean | undefined;
501
- fileName?: string | undefined;
502
- thumbUrl?: string | undefined;
503
- percentage?: number | undefined;
523
+ size?: number;
524
+ uid?: string;
525
+ objectUrl?: string;
526
+ isImage?: boolean;
527
+ message?: string;
528
+ deletable?: boolean;
529
+ reupload?: boolean;
530
+ fileName?: string;
531
+ thumbUrl?: string;
532
+ percentage?: number;
504
533
  };
505
534
  /**
506
535
  * 附件格式
@@ -515,18 +544,32 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
515
544
  group: string;
516
545
  id: string;
517
546
  name: string;
518
- size?: number | undefined;
519
- uid?: string | undefined;
520
- objectUrl?: string | undefined;
521
- isImage?: boolean | undefined;
522
- message?: string | undefined;
523
- deletable?: boolean | undefined;
524
- reupload?: boolean | undefined;
525
- fileName?: string | undefined;
526
- thumbUrl?: string | undefined;
527
- percentage?: number | undefined;
547
+ size?: number;
548
+ uid?: string;
549
+ objectUrl?: string;
550
+ isImage?: boolean;
551
+ message?: string;
552
+ deletable?: boolean;
553
+ reupload?: boolean;
554
+ fileName?: string;
555
+ thumbUrl?: string;
556
+ percentage?: number;
528
557
  }[];
529
558
 
559
+ /**
560
+ * 自然排序
561
+ * @param {UnDef<string>[] | UnDef<number>[]} arr - 数字或字符串数组
562
+ * @returns {UnDef<string>[] | UnDef<number>[]} - 排序后的数组
563
+ */
564
+ declare const naturalSort: (arr: UnDef<string>[] | UnDef<number>[]) => UnDef<string>[] | UnDef<number>[];
565
+ /**
566
+ * 根据 key 自然排序
567
+ * @param arr - 数组
568
+ * @param {string} key - 键名
569
+ * @returns {any[]} - 排序后的数组
570
+ */
571
+ declare const naturalSortBy: <T extends Record<string, UnDef<Numeric>>>(arr: T[], key: keyof T) => T[];
572
+
530
573
  /**
531
574
  * 检测变量类型
532
575
  * @param {any} val 检测的目标
@@ -576,7 +619,7 @@ declare const isObject: (val: any) => val is Record<any, any>;
576
619
  * 是否是数组
577
620
  * @param {any} val 检测的目标
578
621
  */
579
- declare const isArray: (val: any) => val is any[];
622
+ declare const isArray: (val: any) => val is Array<any>;
580
623
  /**
581
624
  * 是否是函数,但也有可能是Class
582
625
  * @param {any} val 检测的目标
@@ -664,7 +707,7 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
664
707
  * ```
665
708
  * @returns {boolean} boolean
666
709
  */
667
- declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
710
+ declare const isValidKey: (key: string | number | symbol, object: object) => key is keyof typeof object;
668
711
  /**
669
712
  * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
670
713
  * @param val
@@ -672,30 +715,15 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
672
715
  declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
673
716
 
674
717
  /**
675
- * 校验接口返回code
676
- * @param res
677
- * @param code
678
- */
679
- declare const isValidResCode: (res: Res, code?: number) => boolean;
680
- /**
681
- * 校验接口返回内容
682
- * @param res
683
- * @param code
684
- */
685
- declare const isValidRes: (res: Res, code?: number) => boolean;
686
- /**
687
- * 校验接口数组返回内容
688
- * @param res
689
- * @param code
690
- */
691
- declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
692
- /**
693
- * 校验接口分页返回内容
694
- * @param res
695
- * @param code
718
+ * 是否是[统一社会信用代码](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
+ * @example
720
+ * ```ts
721
+ * isUSCI('91350100M000100Y43') // true
722
+ * ```
723
+ * @param {UnDef<string>} val - 待校验的值
724
+ * @returns {boolean} 是否是统一社会信用代码
696
725
  */
697
- declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
698
-
726
+ declare const isUSCI: (val: UnDef<string>) => boolean;
699
727
  /**
700
728
  * 是否是中国手机号
701
729
  * @param val
@@ -740,4 +768,29 @@ declare const nonASCII: (text: string) => boolean;
740
768
  */
741
769
  declare const isValidFileType: (file: File, type: string) => boolean;
742
770
 
743
- export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, 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, 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, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
771
+ /**
772
+ * 校验接口返回code
773
+ * @param res
774
+ * @param code
775
+ */
776
+ declare const isValidResCode: (res: Res, code?: number) => boolean;
777
+ /**
778
+ * 校验接口返回内容
779
+ * @param res
780
+ * @param code
781
+ */
782
+ declare const isValidRes: (res: Res, code?: number) => boolean;
783
+ /**
784
+ * 校验接口数组返回内容
785
+ * @param res
786
+ * @param code
787
+ */
788
+ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
789
+ /**
790
+ * 校验接口分页返回内容
791
+ * @param res
792
+ * @param code
793
+ */
794
+ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
795
+
796
+ export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, 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, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };