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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -7,6 +7,90 @@ 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
+
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
+
10
94
  /**
11
95
  * snake2Kebab
12
96
  * @param {string} str 字符串
@@ -217,43 +301,6 @@ declare const jLogDedupe: (...args: any[]) => void;
217
301
  */
218
302
  declare const jLogOnce: (...args: any[]) => void;
219
303
 
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
304
  /**
258
305
  * 隐藏中间部分
259
306
  * @param {string} str 需要隐藏的字符串
@@ -277,8 +324,9 @@ declare const hideHead: (str: UnDef<string>, count?: number) => string;
277
324
  */
278
325
  declare const hideTail: (str: UnDef<string>, count?: number) => string;
279
326
  /**
280
- * 隐藏手机号
281
- * @param {string} phone 手机号
327
+ * 隐藏手机号/座机号
328
+ * @param {string} phone 手机号/座机号
329
+ * @returns {string} 隐藏后的手机号/座机号
282
330
  */
283
331
  declare const hidePhone: (phone: UnDef<string>) => string;
284
332
  /**
@@ -314,33 +362,6 @@ declare const hideEmail: (email: UnDef<string>) => string;
314
362
  */
315
363
  declare const hideBankCard: (bankCard: UnDef<string>) => string;
316
364
 
317
- interface HostEnv {
318
- /**
319
- * 是否是浙里办
320
- */
321
- readonly zlb: boolean
322
- /**
323
- * 是否是专有钉
324
- */
325
- readonly zyd: boolean
326
- /**
327
- * 是否是浙政钉
328
- */
329
- readonly zzd: boolean
330
- /**
331
- * 是否是微信
332
- */
333
- readonly wx: boolean
334
- /**
335
- * 是否是支付宝
336
- */
337
- readonly zfb: boolean
338
- /**
339
- * 是否是小程序
340
- */
341
- readonly mini: boolean
342
- }
343
-
344
365
  /**
345
366
  * 判断是否是浏览器环境
346
367
  */
@@ -362,6 +383,16 @@ declare const fixiOSInputAutoZoomIn: () => void;
362
383
  declare const userAgent: string;
363
384
  /**
364
385
  * 获取宿主环境信息
386
+ * @returns {HostEnv} 宿主环境信息
387
+ * @example
388
+ * const hostEnv = getHostEnv()
389
+ * hostEnv.zlb // 浙里办
390
+ * hostEnv.zyd // 专有钉
391
+ * hostEnv.zzd // 浙政钉
392
+ * hostEnv.dd // 钉钉/专有钉/浙政钉
393
+ * hostEnv.wx // 微信
394
+ * hostEnv.zfb // 支付宝
395
+ * hostEnv.mini // 小程序
365
396
  */
366
397
  declare const getHostEnv: () => HostEnv;
367
398
 
@@ -378,12 +409,22 @@ declare const getCodeOfDate: () => number;
378
409
  */
379
410
  declare const getCodeOfMonth: () => number;
380
411
 
412
+ /**
413
+ * 设置文件基本路径
414
+ * @param baseUrl
415
+ */
416
+ declare function setBaseAttachUrl(baseUrl: string): void;
417
+ /**
418
+ * 获取文件基本路径
419
+ */
420
+ declare function getBaseAttachUrl(): string;
421
+
381
422
  /**
382
423
  * Json字符串转对象
383
424
  * @param str
384
425
  * @param reviver
385
426
  */
386
- declare const parseToJSON: <T = any>(str: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => Nullable<T>;
427
+ declare const parseToJSON: <T = any>(str: string, reviver?: (this: any, key: string, value: any) => any) => Nullable<T>;
387
428
  /**
388
429
  * JSON.stringify() second param
389
430
  * @param _
@@ -406,13 +447,25 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
406
447
  [k: string]: any;
407
448
  };
408
449
 
450
+ /**
451
+ * 千位分隔符
452
+ * @param num
453
+ */
454
+ declare const toThousands: (num: number) => string | undefined;
455
+ /**
456
+ * 货币格式化
457
+ * @param {number | string | bigint} currency - 金额
458
+ * @param {number} [maximumFractionDigits] - 小数位数
459
+ */
460
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
461
+
409
462
  /**
410
463
  * 格式化时间
411
464
  * @param {import('dayjs').ConfigType} date 时间
412
465
  * @param {string} format 格式
413
466
  * @returns {string} 格式化后的时间
414
467
  */
415
- declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime') => string;
468
+ declare const dateFmt: (date: ConfigType, format?: string | "date" | "datetime") => string;
416
469
  /**
417
470
  * 格式化时间间隔
418
471
  * @param {import('dayjs').ConfigType} start 开始时间
@@ -420,29 +473,6 @@ declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime')
420
473
  */
421
474
  declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
422
475
 
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
476
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
447
477
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
448
478
  type ElementPlusUploadFileStatus = 'ready' | 'uploading' | 'success' | 'fail'
@@ -491,16 +521,16 @@ declare const recoverFile: (resource: Resource) => {
491
521
  group: string;
492
522
  id: string;
493
523
  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;
524
+ size?: number;
525
+ uid?: string;
526
+ objectUrl?: string;
527
+ isImage?: boolean;
528
+ message?: string;
529
+ deletable?: boolean;
530
+ reupload?: boolean;
531
+ fileName?: string;
532
+ thumbUrl?: string;
533
+ percentage?: number;
504
534
  };
505
535
  /**
506
536
  * 附件格式
@@ -515,18 +545,32 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
515
545
  group: string;
516
546
  id: string;
517
547
  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;
548
+ size?: number;
549
+ uid?: string;
550
+ objectUrl?: string;
551
+ isImage?: boolean;
552
+ message?: string;
553
+ deletable?: boolean;
554
+ reupload?: boolean;
555
+ fileName?: string;
556
+ thumbUrl?: string;
557
+ percentage?: number;
528
558
  }[];
529
559
 
560
+ /**
561
+ * 自然排序
562
+ * @param {UnDef<string>[] | UnDef<number>[]} arr - 数字或字符串数组
563
+ * @returns {UnDef<string>[] | UnDef<number>[]} - 排序后的数组
564
+ */
565
+ declare const naturalSort: (arr: UnDef<string>[] | UnDef<number>[]) => UnDef<string>[] | UnDef<number>[];
566
+ /**
567
+ * 根据 key 自然排序
568
+ * @param arr - 数组
569
+ * @param {string} key - 键名
570
+ * @returns {any[]} - 排序后的数组
571
+ */
572
+ declare const naturalSortBy: <T extends Record<string, UnDef<Numeric>>>(arr: T[], key: keyof T) => T[];
573
+
530
574
  /**
531
575
  * 检测变量类型
532
576
  * @param {any} val 检测的目标
@@ -576,7 +620,7 @@ declare const isObject: (val: any) => val is Record<any, any>;
576
620
  * 是否是数组
577
621
  * @param {any} val 检测的目标
578
622
  */
579
- declare const isArray: (val: any) => val is any[];
623
+ declare const isArray: (val: any) => val is Array<any>;
580
624
  /**
581
625
  * 是否是函数,但也有可能是Class
582
626
  * @param {any} val 检测的目标
@@ -664,38 +708,30 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
664
708
  * ```
665
709
  * @returns {boolean} boolean
666
710
  */
667
- declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
711
+ declare const isValidKey: (key: string | number | symbol, object: object) => key is keyof typeof object;
668
712
  /**
669
713
  * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
670
714
  * @param val
671
715
  */
672
716
  declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
673
717
 
674
- /**
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
718
+ declare const cnPhoneRE: RegExp;
719
+ declare const cnTelRE: RegExp;
720
+ declare const cnTelRE2: RegExp;
721
+ declare const cnUSCIRE: RegExp;
722
+ declare const cnIdCard15Re: RegExp;
723
+ declare const cnIdCard18Re: RegExp;
724
+ declare const emailRE: RegExp;
725
+ /**
726
+ * 是否是[统一社会信用代码](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)
727
+ * @example
728
+ * ```ts
729
+ * isUSCI('91350100M000100Y43') // true
730
+ * ```
731
+ * @param {UnDef<string>} val - 待校验的值
732
+ * @returns {boolean} 是否是统一社会信用代码
690
733
  */
691
- declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
692
- /**
693
- * 校验接口分页返回内容
694
- * @param res
695
- * @param code
696
- */
697
- declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
698
-
734
+ declare const isUSCI: (val: UnDef<string>) => boolean;
699
735
  /**
700
736
  * 是否是中国手机号
701
737
  * @param val
@@ -740,4 +776,29 @@ declare const nonASCII: (text: string) => boolean;
740
776
  */
741
777
  declare const isValidFileType: (file: File, type: string) => boolean;
742
778
 
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 };
779
+ /**
780
+ * 校验接口返回code
781
+ * @param res
782
+ * @param code
783
+ */
784
+ declare const isValidResCode: (res: Res, code?: number) => boolean;
785
+ /**
786
+ * 校验接口返回内容
787
+ * @param res
788
+ * @param code
789
+ */
790
+ declare const isValidRes: (res: Res, code?: number) => boolean;
791
+ /**
792
+ * 校验接口数组返回内容
793
+ * @param res
794
+ * @param code
795
+ */
796
+ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
797
+ /**
798
+ * 校验接口分页返回内容
799
+ * @param res
800
+ * @param code
801
+ */
802
+ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
803
+
804
+ export { type Dict, type HostEnv, 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, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, 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 };