@jhqn/utils-core 0.0.1-beta.25 → 0.0.1-beta.27

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
@@ -71,8 +71,37 @@ const jClear = console.clear.bind(console);
71
71
 
72
72
  const cnPhoneRE = /^1[3-9]\d{9}$/;
73
73
  const cnTelRE = /^0\d{9,11}$/;
74
- const isDef = (val) => val !== void 0 && val !== null;
75
- const isNumeric = (val) => typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
74
+ const getVariableType = (val) => {
75
+ const value = Object.prototype.toString.call(val);
76
+ const result = value.match(/\[object (\S*)\]/)?.[1];
77
+ return result?.toLocaleLowerCase();
78
+ };
79
+ const isNumber = (val) => getVariableType(val) === "number";
80
+ const isString = (val) => getVariableType(val) === "string";
81
+ const isBoolean = (val) => getVariableType(val) === "boolean";
82
+ const isNull = (val) => getVariableType(val) === "null";
83
+ const isUndefined = (val) => getVariableType(val) === "undefined";
84
+ const isSymbol = (val) => getVariableType(val) === "symbol";
85
+ const isObject = (val) => getVariableType(val) === "object";
86
+ const isArray = (val) => getVariableType(val) === "array";
87
+ const isFunction = (val) => getVariableType(val) === "function";
88
+ const isDate = (val) => getVariableType(val) === "date";
89
+ const isRegExp = (val) => getVariableType(val) === "regexp";
90
+ const isPromise = (val) => getVariableType(val) === "promise";
91
+ const isSet = (val) => getVariableType(val) === "set";
92
+ const isMap = (val) => getVariableType(val) === "map";
93
+ const isWeakSet = (val) => getVariableType(val) === "weakset";
94
+ const isWeakMap = (val) => getVariableType(val) === "weakmap";
95
+ const isFile = (val) => getVariableType(val) === "file";
96
+ const isBlob = (val) => getVariableType(val) === "blob";
97
+ const isURL = (val) => getVariableType(val) === "url";
98
+ const isError = (val) => getVariableType(val) === "error";
99
+ const isDef = (val) => !isNull(val) && !isUndefined(val);
100
+ const isNumeric = (val) => {
101
+ if (isDef(val))
102
+ return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
103
+ return false;
104
+ };
76
105
  const checkImg = (ext) => {
77
106
  return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
78
107
  };
@@ -80,19 +109,23 @@ const isEmpty = (val) => {
80
109
  return !isDef(val) || val === "" || Array.isArray(val) && val.length === 0 || Object.prototype.toString.call(val) === "[object Object]" && Object.keys(val).length === 0 || val instanceof Map && val.size === 0 || val instanceof Set && val.size === 0;
81
110
  };
82
111
  const isJSONStr = (str) => {
83
- try {
84
- JSON.parse(str);
85
- return true;
86
- } catch (e) {
87
- return false;
88
- }
112
+ if (isDef(str))
113
+ try {
114
+ JSON.parse(str);
115
+ return true;
116
+ } catch (e) {
117
+ return false;
118
+ }
119
+ return false;
89
120
  };
90
121
  const isArrStr = (str) => {
91
- try {
92
- return Array.isArray(JSON.parse(str));
93
- } catch (e) {
94
- return false;
95
- }
122
+ if (isDef(str))
123
+ try {
124
+ return Array.isArray(JSON.parse(str));
125
+ } catch (e) {
126
+ return false;
127
+ }
128
+ return false;
96
129
  };
97
130
  const isValidKey = (key, object) => key in object;
98
131
  const isPhone = (val) => {
@@ -237,11 +270,11 @@ const hideEmail = (email) => {
237
270
  if (!name || !domain)
238
271
  return email;
239
272
  const len = name.length;
240
- let newName = "";
273
+ let newName;
241
274
  if (len <= 3) {
242
275
  newName = `${name}***`;
243
276
  } else {
244
- newName = `${name.substring(0, len - 3)}***`;
277
+ newName = hideTail(name, 3);
245
278
  }
246
279
  return `${newName}@${domain}`;
247
280
  }
@@ -383,12 +416,13 @@ const toThousands = (num) => {
383
416
  return `${integer}.${arr[1]}`;
384
417
  return integer;
385
418
  };
386
- const currencyFmt = (currency, fraction = 0) => {
419
+ const currencyFmt = (currency, maximumFractionDigits = 2) => {
387
420
  if (!isDef(currency))
388
421
  return "";
389
- return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
390
- currency
391
- );
422
+ const num = Number(currency);
423
+ if (Number.isNaN(num))
424
+ return "";
425
+ return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
392
426
  };
393
427
 
394
428
  const resUrl = (url) => {
@@ -452,6 +486,7 @@ exports.filterObj = filterObj;
452
486
  exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
453
487
  exports.getBaseAttachUrl = getBaseAttachUrl;
454
488
  exports.getHostEnv = getHostEnv;
489
+ exports.getVariableType = getVariableType;
455
490
  exports.hideBankCard = hideBankCard;
456
491
  exports.hideCardNo = hideCardNo;
457
492
  exports.hideEmail = hideEmail;
@@ -465,20 +500,40 @@ exports.hideTail = hideTail;
465
500
  exports.hideThird = hideThird;
466
501
  exports.inBrowser = inBrowser;
467
502
  exports.isArrStr = isArrStr;
503
+ exports.isArray = isArray;
504
+ exports.isBlob = isBlob;
505
+ exports.isBoolean = isBoolean;
506
+ exports.isDate = isDate;
468
507
  exports.isDef = isDef;
469
508
  exports.isEmail = isEmail;
470
509
  exports.isEmpty = isEmpty;
510
+ exports.isError = isError;
511
+ exports.isFile = isFile;
512
+ exports.isFunction = isFunction;
471
513
  exports.isIdCard = isIdCard;
472
514
  exports.isJSONStr = isJSONStr;
515
+ exports.isMap = isMap;
516
+ exports.isNull = isNull;
517
+ exports.isNumber = isNumber;
473
518
  exports.isNumeric = isNumeric;
519
+ exports.isObject = isObject;
474
520
  exports.isPhone = isPhone;
521
+ exports.isPromise = isPromise;
522
+ exports.isRegExp = isRegExp;
523
+ exports.isSet = isSet;
524
+ exports.isString = isString;
525
+ exports.isSymbol = isSymbol;
475
526
  exports.isTel = isTel;
527
+ exports.isURL = isURL;
528
+ exports.isUndefined = isUndefined;
476
529
  exports.isValidArrRes = isValidArrRes;
477
530
  exports.isValidFileType = isValidFileType;
478
531
  exports.isValidKey = isValidKey;
479
532
  exports.isValidPageRes = isValidPageRes;
480
533
  exports.isValidRes = isValidRes;
481
534
  exports.isValidResCode = isValidResCode;
535
+ exports.isWeakMap = isWeakMap;
536
+ exports.isWeakSet = isWeakSet;
482
537
  exports.jClear = jClear;
483
538
  exports.jDebug = jDebug;
484
539
  exports.jError = jError;
package/dist/index.d.cts CHANGED
@@ -558,10 +558,10 @@ declare function getBaseAttachUrl(): string;
558
558
  declare const toThousands: (num: number) => string | undefined;
559
559
  /**
560
560
  * 货币格式化
561
- * @param currency
562
- * @param fraction
561
+ * @param {number | string | bigint} currency - 金额
562
+ * @param {number} [maximumFractionDigits] - 小数位数
563
563
  */
564
- declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
564
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
565
565
 
566
566
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
567
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
@@ -654,15 +654,120 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
654
654
  }[];
655
655
 
656
656
  /**
657
- * 是否有意义的值
658
- * @param val
657
+ * 检测变量类型
658
+ * @param {any} val 检测的目标
659
+ */
660
+ declare const getVariableType: (val: any) => string | undefined;
661
+ /**
662
+ * 是否是数字
663
+ * @param {any} val 检测的目标
664
+ */
665
+ declare const isNumber: (val: any) => val is number;
666
+ /**
667
+ * 是否是字符串
668
+ * @param {any} val 检测的目标
669
+ */
670
+ declare const isString: (val: any) => val is string;
671
+ /**
672
+ * 是否是布尔值
673
+ * @param {any} val 检测的目标
674
+ */
675
+ declare const isBoolean: (val: any) => val is boolean;
676
+ /**
677
+ * 是否是null
678
+ * @param {any} val 检测的目标
679
+ */
680
+ declare const isNull: (val: any) => val is null;
681
+ /**
682
+ * 是否是undefined
683
+ * @param {any} val 检测的目标
684
+ */
685
+ declare const isUndefined: (val: any) => val is undefined;
686
+ /**
687
+ * 是否是symbol
688
+ * @param {any} val 检测的目标
689
+ */
690
+ declare const isSymbol: (val: any) => val is symbol;
691
+ /**
692
+ * 是否是对象
693
+ * @param {any} val 检测的目标
694
+ */
695
+ declare const isObject: (val: any) => val is Record<any, any>;
696
+ /**
697
+ * 是否是数组
698
+ * @param {any} val 检测的目标
699
+ */
700
+ declare const isArray: (val: any) => val is any[];
701
+ /**
702
+ * 是否是函数
703
+ * @param {any} val 检测的目标
704
+ */
705
+ declare const isFunction: (val: any) => val is Function;
706
+ /**
707
+ * 是否是日期
708
+ * @param {any} val 检测的目标
709
+ */
710
+ declare const isDate: (val: any) => val is Date;
711
+ /**
712
+ * 是否是正则
713
+ * @param {any} val 检测的目标
714
+ */
715
+ declare const isRegExp: (val: any) => val is RegExp;
716
+ /**
717
+ * 是否是期望(Promise)
718
+ * @param {any} val 检测的目标
719
+ */
720
+ declare const isPromise: (val: any) => val is Promise<any>;
721
+ /**
722
+ * 是否是集合(Set)
723
+ * @param {any} val 检测的目标
724
+ */
725
+ declare const isSet: (val: any) => val is Set<any>;
726
+ /**
727
+ * 是否是映射(Map)
728
+ * @param {any} val 检测的目标
729
+ */
730
+ declare const isMap: (val: any) => val is Map<any, any>;
731
+ /**
732
+ * 是否是弱集合(WeakSet)
733
+ * @param {any} val 检测的目标
734
+ */
735
+ declare const isWeakSet: (val: any) => val is WeakSet<any>;
736
+ /**
737
+ * 是否是弱映射(WeakMap)
738
+ * @param {any} val 检测的目标
739
+ */
740
+ declare const isWeakMap: (val: any) => val is WeakMap<any, any>;
741
+ /**
742
+ * 是否是File
743
+ * @param {any} val 检测的目标
744
+ */
745
+ declare const isFile: (val: any) => val is File;
746
+ /**
747
+ * 是否是Blob
748
+ * @param {any} val 检测的目标
749
+ */
750
+ declare const isBlob: (val: any) => val is Blob;
751
+ /**
752
+ * 是否是URL
753
+ * @param {any} val 检测的目标
754
+ */
755
+ declare const isURL: (val: any) => val is URL;
756
+ /**
757
+ * 是否是错误(Error)
758
+ * @param {any} val 检测的目标
759
+ */
760
+ declare const isError: (val: any) => val is Error;
761
+ /**
762
+ * 是否既不是 null 也不是 undefined
763
+ * @param {any} val 检测的目标
659
764
  */
660
765
  declare const isDef: <T>(val: T) => val is NonNullable<T>;
661
766
  /**
662
767
  * 是否是数字或字符
663
768
  * @param val
664
769
  */
665
- declare const isNumeric: (val: Numeric) => val is string;
770
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
666
771
  /**
667
772
  * 是否是需要的图片格式
668
773
  * @param ext
@@ -677,12 +782,12 @@ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<
677
782
  * 判断是否合法JSON字符串
678
783
  * @param str
679
784
  */
680
- declare const isJSONStr: (str: string) => boolean;
785
+ declare const isJSONStr: (str: UnDef<string>) => boolean;
681
786
  /**
682
787
  * 判断是否合法JSON数组字符串
683
788
  * @param str
684
789
  */
685
- declare const isArrStr: (str: string) => boolean;
790
+ declare const isArrStr: (str: UnDef<string>) => boolean;
686
791
  /**
687
792
  * 判断是否有效的key
688
793
  * @param {string | number | symbol} key 键名
@@ -754,4 +859,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
754
859
  */
755
860
  declare const isValidFileType: (file: File, type: string) => boolean;
756
861
 
757
- 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, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, 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 };
862
+ 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, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
package/dist/index.d.mts CHANGED
@@ -558,10 +558,10 @@ declare function getBaseAttachUrl(): string;
558
558
  declare const toThousands: (num: number) => string | undefined;
559
559
  /**
560
560
  * 货币格式化
561
- * @param currency
562
- * @param fraction
561
+ * @param {number | string | bigint} currency - 金额
562
+ * @param {number} [maximumFractionDigits] - 小数位数
563
563
  */
564
- declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
564
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
565
565
 
566
566
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
567
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
@@ -654,15 +654,120 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
654
654
  }[];
655
655
 
656
656
  /**
657
- * 是否有意义的值
658
- * @param val
657
+ * 检测变量类型
658
+ * @param {any} val 检测的目标
659
+ */
660
+ declare const getVariableType: (val: any) => string | undefined;
661
+ /**
662
+ * 是否是数字
663
+ * @param {any} val 检测的目标
664
+ */
665
+ declare const isNumber: (val: any) => val is number;
666
+ /**
667
+ * 是否是字符串
668
+ * @param {any} val 检测的目标
669
+ */
670
+ declare const isString: (val: any) => val is string;
671
+ /**
672
+ * 是否是布尔值
673
+ * @param {any} val 检测的目标
674
+ */
675
+ declare const isBoolean: (val: any) => val is boolean;
676
+ /**
677
+ * 是否是null
678
+ * @param {any} val 检测的目标
679
+ */
680
+ declare const isNull: (val: any) => val is null;
681
+ /**
682
+ * 是否是undefined
683
+ * @param {any} val 检测的目标
684
+ */
685
+ declare const isUndefined: (val: any) => val is undefined;
686
+ /**
687
+ * 是否是symbol
688
+ * @param {any} val 检测的目标
689
+ */
690
+ declare const isSymbol: (val: any) => val is symbol;
691
+ /**
692
+ * 是否是对象
693
+ * @param {any} val 检测的目标
694
+ */
695
+ declare const isObject: (val: any) => val is Record<any, any>;
696
+ /**
697
+ * 是否是数组
698
+ * @param {any} val 检测的目标
699
+ */
700
+ declare const isArray: (val: any) => val is any[];
701
+ /**
702
+ * 是否是函数
703
+ * @param {any} val 检测的目标
704
+ */
705
+ declare const isFunction: (val: any) => val is Function;
706
+ /**
707
+ * 是否是日期
708
+ * @param {any} val 检测的目标
709
+ */
710
+ declare const isDate: (val: any) => val is Date;
711
+ /**
712
+ * 是否是正则
713
+ * @param {any} val 检测的目标
714
+ */
715
+ declare const isRegExp: (val: any) => val is RegExp;
716
+ /**
717
+ * 是否是期望(Promise)
718
+ * @param {any} val 检测的目标
719
+ */
720
+ declare const isPromise: (val: any) => val is Promise<any>;
721
+ /**
722
+ * 是否是集合(Set)
723
+ * @param {any} val 检测的目标
724
+ */
725
+ declare const isSet: (val: any) => val is Set<any>;
726
+ /**
727
+ * 是否是映射(Map)
728
+ * @param {any} val 检测的目标
729
+ */
730
+ declare const isMap: (val: any) => val is Map<any, any>;
731
+ /**
732
+ * 是否是弱集合(WeakSet)
733
+ * @param {any} val 检测的目标
734
+ */
735
+ declare const isWeakSet: (val: any) => val is WeakSet<any>;
736
+ /**
737
+ * 是否是弱映射(WeakMap)
738
+ * @param {any} val 检测的目标
739
+ */
740
+ declare const isWeakMap: (val: any) => val is WeakMap<any, any>;
741
+ /**
742
+ * 是否是File
743
+ * @param {any} val 检测的目标
744
+ */
745
+ declare const isFile: (val: any) => val is File;
746
+ /**
747
+ * 是否是Blob
748
+ * @param {any} val 检测的目标
749
+ */
750
+ declare const isBlob: (val: any) => val is Blob;
751
+ /**
752
+ * 是否是URL
753
+ * @param {any} val 检测的目标
754
+ */
755
+ declare const isURL: (val: any) => val is URL;
756
+ /**
757
+ * 是否是错误(Error)
758
+ * @param {any} val 检测的目标
759
+ */
760
+ declare const isError: (val: any) => val is Error;
761
+ /**
762
+ * 是否既不是 null 也不是 undefined
763
+ * @param {any} val 检测的目标
659
764
  */
660
765
  declare const isDef: <T>(val: T) => val is NonNullable<T>;
661
766
  /**
662
767
  * 是否是数字或字符
663
768
  * @param val
664
769
  */
665
- declare const isNumeric: (val: Numeric) => val is string;
770
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
666
771
  /**
667
772
  * 是否是需要的图片格式
668
773
  * @param ext
@@ -677,12 +782,12 @@ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<
677
782
  * 判断是否合法JSON字符串
678
783
  * @param str
679
784
  */
680
- declare const isJSONStr: (str: string) => boolean;
785
+ declare const isJSONStr: (str: UnDef<string>) => boolean;
681
786
  /**
682
787
  * 判断是否合法JSON数组字符串
683
788
  * @param str
684
789
  */
685
- declare const isArrStr: (str: string) => boolean;
790
+ declare const isArrStr: (str: UnDef<string>) => boolean;
686
791
  /**
687
792
  * 判断是否有效的key
688
793
  * @param {string | number | symbol} key 键名
@@ -754,4 +859,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
754
859
  */
755
860
  declare const isValidFileType: (file: File, type: string) => boolean;
756
861
 
757
- 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, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, 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 };
862
+ 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, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
package/dist/index.d.ts CHANGED
@@ -558,10 +558,10 @@ declare function getBaseAttachUrl(): string;
558
558
  declare const toThousands: (num: number) => string | undefined;
559
559
  /**
560
560
  * 货币格式化
561
- * @param currency
562
- * @param fraction
561
+ * @param {number | string | bigint} currency - 金额
562
+ * @param {number} [maximumFractionDigits] - 小数位数
563
563
  */
564
- declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
564
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
565
565
 
566
566
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
567
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
@@ -654,15 +654,120 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
654
654
  }[];
655
655
 
656
656
  /**
657
- * 是否有意义的值
658
- * @param val
657
+ * 检测变量类型
658
+ * @param {any} val 检测的目标
659
+ */
660
+ declare const getVariableType: (val: any) => string | undefined;
661
+ /**
662
+ * 是否是数字
663
+ * @param {any} val 检测的目标
664
+ */
665
+ declare const isNumber: (val: any) => val is number;
666
+ /**
667
+ * 是否是字符串
668
+ * @param {any} val 检测的目标
669
+ */
670
+ declare const isString: (val: any) => val is string;
671
+ /**
672
+ * 是否是布尔值
673
+ * @param {any} val 检测的目标
674
+ */
675
+ declare const isBoolean: (val: any) => val is boolean;
676
+ /**
677
+ * 是否是null
678
+ * @param {any} val 检测的目标
679
+ */
680
+ declare const isNull: (val: any) => val is null;
681
+ /**
682
+ * 是否是undefined
683
+ * @param {any} val 检测的目标
684
+ */
685
+ declare const isUndefined: (val: any) => val is undefined;
686
+ /**
687
+ * 是否是symbol
688
+ * @param {any} val 检测的目标
689
+ */
690
+ declare const isSymbol: (val: any) => val is symbol;
691
+ /**
692
+ * 是否是对象
693
+ * @param {any} val 检测的目标
694
+ */
695
+ declare const isObject: (val: any) => val is Record<any, any>;
696
+ /**
697
+ * 是否是数组
698
+ * @param {any} val 检测的目标
699
+ */
700
+ declare const isArray: (val: any) => val is any[];
701
+ /**
702
+ * 是否是函数
703
+ * @param {any} val 检测的目标
704
+ */
705
+ declare const isFunction: (val: any) => val is Function;
706
+ /**
707
+ * 是否是日期
708
+ * @param {any} val 检测的目标
709
+ */
710
+ declare const isDate: (val: any) => val is Date;
711
+ /**
712
+ * 是否是正则
713
+ * @param {any} val 检测的目标
714
+ */
715
+ declare const isRegExp: (val: any) => val is RegExp;
716
+ /**
717
+ * 是否是期望(Promise)
718
+ * @param {any} val 检测的目标
719
+ */
720
+ declare const isPromise: (val: any) => val is Promise<any>;
721
+ /**
722
+ * 是否是集合(Set)
723
+ * @param {any} val 检测的目标
724
+ */
725
+ declare const isSet: (val: any) => val is Set<any>;
726
+ /**
727
+ * 是否是映射(Map)
728
+ * @param {any} val 检测的目标
729
+ */
730
+ declare const isMap: (val: any) => val is Map<any, any>;
731
+ /**
732
+ * 是否是弱集合(WeakSet)
733
+ * @param {any} val 检测的目标
734
+ */
735
+ declare const isWeakSet: (val: any) => val is WeakSet<any>;
736
+ /**
737
+ * 是否是弱映射(WeakMap)
738
+ * @param {any} val 检测的目标
739
+ */
740
+ declare const isWeakMap: (val: any) => val is WeakMap<any, any>;
741
+ /**
742
+ * 是否是File
743
+ * @param {any} val 检测的目标
744
+ */
745
+ declare const isFile: (val: any) => val is File;
746
+ /**
747
+ * 是否是Blob
748
+ * @param {any} val 检测的目标
749
+ */
750
+ declare const isBlob: (val: any) => val is Blob;
751
+ /**
752
+ * 是否是URL
753
+ * @param {any} val 检测的目标
754
+ */
755
+ declare const isURL: (val: any) => val is URL;
756
+ /**
757
+ * 是否是错误(Error)
758
+ * @param {any} val 检测的目标
759
+ */
760
+ declare const isError: (val: any) => val is Error;
761
+ /**
762
+ * 是否既不是 null 也不是 undefined
763
+ * @param {any} val 检测的目标
659
764
  */
660
765
  declare const isDef: <T>(val: T) => val is NonNullable<T>;
661
766
  /**
662
767
  * 是否是数字或字符
663
768
  * @param val
664
769
  */
665
- declare const isNumeric: (val: Numeric) => val is string;
770
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
666
771
  /**
667
772
  * 是否是需要的图片格式
668
773
  * @param ext
@@ -677,12 +782,12 @@ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<
677
782
  * 判断是否合法JSON字符串
678
783
  * @param str
679
784
  */
680
- declare const isJSONStr: (str: string) => boolean;
785
+ declare const isJSONStr: (str: UnDef<string>) => boolean;
681
786
  /**
682
787
  * 判断是否合法JSON数组字符串
683
788
  * @param str
684
789
  */
685
- declare const isArrStr: (str: string) => boolean;
790
+ declare const isArrStr: (str: UnDef<string>) => boolean;
686
791
  /**
687
792
  * 判断是否有效的key
688
793
  * @param {string | number | symbol} key 键名
@@ -754,4 +859,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
754
859
  */
755
860
  declare const isValidFileType: (file: File, type: string) => boolean;
756
861
 
757
- 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, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, 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 };
862
+ 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, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
package/dist/index.mjs CHANGED
@@ -60,8 +60,37 @@ const jClear = console.clear.bind(console);
60
60
 
61
61
  const cnPhoneRE = /^1[3-9]\d{9}$/;
62
62
  const cnTelRE = /^0\d{9,11}$/;
63
- const isDef = (val) => val !== void 0 && val !== null;
64
- const isNumeric = (val) => typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
63
+ const getVariableType = (val) => {
64
+ const value = Object.prototype.toString.call(val);
65
+ const result = value.match(/\[object (\S*)\]/)?.[1];
66
+ return result?.toLocaleLowerCase();
67
+ };
68
+ const isNumber = (val) => getVariableType(val) === "number";
69
+ const isString = (val) => getVariableType(val) === "string";
70
+ const isBoolean = (val) => getVariableType(val) === "boolean";
71
+ const isNull = (val) => getVariableType(val) === "null";
72
+ const isUndefined = (val) => getVariableType(val) === "undefined";
73
+ const isSymbol = (val) => getVariableType(val) === "symbol";
74
+ const isObject = (val) => getVariableType(val) === "object";
75
+ const isArray = (val) => getVariableType(val) === "array";
76
+ const isFunction = (val) => getVariableType(val) === "function";
77
+ const isDate = (val) => getVariableType(val) === "date";
78
+ const isRegExp = (val) => getVariableType(val) === "regexp";
79
+ const isPromise = (val) => getVariableType(val) === "promise";
80
+ const isSet = (val) => getVariableType(val) === "set";
81
+ const isMap = (val) => getVariableType(val) === "map";
82
+ const isWeakSet = (val) => getVariableType(val) === "weakset";
83
+ const isWeakMap = (val) => getVariableType(val) === "weakmap";
84
+ const isFile = (val) => getVariableType(val) === "file";
85
+ const isBlob = (val) => getVariableType(val) === "blob";
86
+ const isURL = (val) => getVariableType(val) === "url";
87
+ const isError = (val) => getVariableType(val) === "error";
88
+ const isDef = (val) => !isNull(val) && !isUndefined(val);
89
+ const isNumeric = (val) => {
90
+ if (isDef(val))
91
+ return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
92
+ return false;
93
+ };
65
94
  const checkImg = (ext) => {
66
95
  return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
67
96
  };
@@ -69,19 +98,23 @@ const isEmpty = (val) => {
69
98
  return !isDef(val) || val === "" || Array.isArray(val) && val.length === 0 || Object.prototype.toString.call(val) === "[object Object]" && Object.keys(val).length === 0 || val instanceof Map && val.size === 0 || val instanceof Set && val.size === 0;
70
99
  };
71
100
  const isJSONStr = (str) => {
72
- try {
73
- JSON.parse(str);
74
- return true;
75
- } catch (e) {
76
- return false;
77
- }
101
+ if (isDef(str))
102
+ try {
103
+ JSON.parse(str);
104
+ return true;
105
+ } catch (e) {
106
+ return false;
107
+ }
108
+ return false;
78
109
  };
79
110
  const isArrStr = (str) => {
80
- try {
81
- return Array.isArray(JSON.parse(str));
82
- } catch (e) {
83
- return false;
84
- }
111
+ if (isDef(str))
112
+ try {
113
+ return Array.isArray(JSON.parse(str));
114
+ } catch (e) {
115
+ return false;
116
+ }
117
+ return false;
85
118
  };
86
119
  const isValidKey = (key, object) => key in object;
87
120
  const isPhone = (val) => {
@@ -226,11 +259,11 @@ const hideEmail = (email) => {
226
259
  if (!name || !domain)
227
260
  return email;
228
261
  const len = name.length;
229
- let newName = "";
262
+ let newName;
230
263
  if (len <= 3) {
231
264
  newName = `${name}***`;
232
265
  } else {
233
- newName = `${name.substring(0, len - 3)}***`;
266
+ newName = hideTail(name, 3);
234
267
  }
235
268
  return `${newName}@${domain}`;
236
269
  }
@@ -372,12 +405,13 @@ const toThousands = (num) => {
372
405
  return `${integer}.${arr[1]}`;
373
406
  return integer;
374
407
  };
375
- const currencyFmt = (currency, fraction = 0) => {
408
+ const currencyFmt = (currency, maximumFractionDigits = 2) => {
376
409
  if (!isDef(currency))
377
410
  return "";
378
- return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
379
- currency
380
- );
411
+ const num = Number(currency);
412
+ if (Number.isNaN(num))
413
+ return "";
414
+ return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
381
415
  };
382
416
 
383
417
  const resUrl = (url) => {
@@ -427,4 +461,4 @@ const attachFmt = (data) => {
427
461
  return attachList.map(recoverFile);
428
462
  };
429
463
 
430
- export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, 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 };
464
+ export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jhqn/utils-core",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.25",
4
+ "version": "0.0.1-beta.27",
5
5
  "author": "jade-gjz <jiangang.zhang@jaderd.com>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/jaderd-jh/utils/tree/main/packages/core#readme",
@@ -37,7 +37,7 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "dayjs": "^1.11.9",
40
+ "dayjs": "^1.11.10",
41
41
  "detect-browser": "^5.3.0"
42
42
  },
43
43
  "scripts": {