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

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
@@ -72,7 +72,11 @@ const jClear = console.clear.bind(console);
72
72
  const cnPhoneRE = /^1[3-9]\d{9}$/;
73
73
  const cnTelRE = /^0\d{9,11}$/;
74
74
  const isDef = (val) => val !== void 0 && val !== null;
75
- const isNumeric = (val) => typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
75
+ const isNumeric = (val) => {
76
+ if (isDef(val))
77
+ return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
78
+ return false;
79
+ };
76
80
  const checkImg = (ext) => {
77
81
  return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
78
82
  };
@@ -80,19 +84,23 @@ const isEmpty = (val) => {
80
84
  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
85
  };
82
86
  const isJSONStr = (str) => {
83
- try {
84
- JSON.parse(str);
85
- return true;
86
- } catch (e) {
87
- return false;
88
- }
87
+ if (isDef(str))
88
+ try {
89
+ JSON.parse(str);
90
+ return true;
91
+ } catch (e) {
92
+ return false;
93
+ }
94
+ return false;
89
95
  };
90
96
  const isArrStr = (str) => {
91
- try {
92
- return Array.isArray(JSON.parse(str));
93
- } catch (e) {
94
- return false;
95
- }
97
+ if (isDef(str))
98
+ try {
99
+ return Array.isArray(JSON.parse(str));
100
+ } catch (e) {
101
+ return false;
102
+ }
103
+ return false;
96
104
  };
97
105
  const isValidKey = (key, object) => key in object;
98
106
  const isPhone = (val) => {
@@ -237,11 +245,11 @@ const hideEmail = (email) => {
237
245
  if (!name || !domain)
238
246
  return email;
239
247
  const len = name.length;
240
- let newName = "";
248
+ let newName;
241
249
  if (len <= 3) {
242
250
  newName = `${name}***`;
243
251
  } else {
244
- newName = `${name.substring(0, len - 3)}***`;
252
+ newName = hideTail(name, 3);
245
253
  }
246
254
  return `${newName}@${domain}`;
247
255
  }
@@ -386,8 +394,11 @@ const toThousands = (num) => {
386
394
  const currencyFmt = (currency, fraction = 0) => {
387
395
  if (!isDef(currency))
388
396
  return "";
397
+ const num = Number(currency);
398
+ if (Number.isNaN(num))
399
+ return "";
389
400
  return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
390
- currency
401
+ num
391
402
  );
392
403
  };
393
404
 
package/dist/index.d.cts CHANGED
@@ -561,7 +561,7 @@ declare const toThousands: (num: number) => string | undefined;
561
561
  * @param currency
562
562
  * @param fraction
563
563
  */
564
- declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
564
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, fraction?: number) => string;
565
565
 
566
566
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
567
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
@@ -662,7 +662,7 @@ declare const isDef: <T>(val: T) => val is NonNullable<T>;
662
662
  * 是否是数字或字符
663
663
  * @param val
664
664
  */
665
- declare const isNumeric: (val: Numeric) => val is string;
665
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
666
666
  /**
667
667
  * 是否是需要的图片格式
668
668
  * @param ext
@@ -677,12 +677,12 @@ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<
677
677
  * 判断是否合法JSON字符串
678
678
  * @param str
679
679
  */
680
- declare const isJSONStr: (str: string) => boolean;
680
+ declare const isJSONStr: (str: UnDef<string>) => boolean;
681
681
  /**
682
682
  * 判断是否合法JSON数组字符串
683
683
  * @param str
684
684
  */
685
- declare const isArrStr: (str: string) => boolean;
685
+ declare const isArrStr: (str: UnDef<string>) => boolean;
686
686
  /**
687
687
  * 判断是否有效的key
688
688
  * @param {string | number | symbol} key 键名
package/dist/index.d.mts CHANGED
@@ -561,7 +561,7 @@ declare const toThousands: (num: number) => string | undefined;
561
561
  * @param currency
562
562
  * @param fraction
563
563
  */
564
- declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
564
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, fraction?: number) => string;
565
565
 
566
566
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
567
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
@@ -662,7 +662,7 @@ declare const isDef: <T>(val: T) => val is NonNullable<T>;
662
662
  * 是否是数字或字符
663
663
  * @param val
664
664
  */
665
- declare const isNumeric: (val: Numeric) => val is string;
665
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
666
666
  /**
667
667
  * 是否是需要的图片格式
668
668
  * @param ext
@@ -677,12 +677,12 @@ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<
677
677
  * 判断是否合法JSON字符串
678
678
  * @param str
679
679
  */
680
- declare const isJSONStr: (str: string) => boolean;
680
+ declare const isJSONStr: (str: UnDef<string>) => boolean;
681
681
  /**
682
682
  * 判断是否合法JSON数组字符串
683
683
  * @param str
684
684
  */
685
- declare const isArrStr: (str: string) => boolean;
685
+ declare const isArrStr: (str: UnDef<string>) => boolean;
686
686
  /**
687
687
  * 判断是否有效的key
688
688
  * @param {string | number | symbol} key 键名
package/dist/index.d.ts CHANGED
@@ -561,7 +561,7 @@ declare const toThousands: (num: number) => string | undefined;
561
561
  * @param currency
562
562
  * @param fraction
563
563
  */
564
- declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
564
+ declare const currencyFmt: (currency: UnDef<Numeric | bigint>, fraction?: number) => string;
565
565
 
566
566
  type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
567
  type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
@@ -662,7 +662,7 @@ declare const isDef: <T>(val: T) => val is NonNullable<T>;
662
662
  * 是否是数字或字符
663
663
  * @param val
664
664
  */
665
- declare const isNumeric: (val: Numeric) => val is string;
665
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
666
666
  /**
667
667
  * 是否是需要的图片格式
668
668
  * @param ext
@@ -677,12 +677,12 @@ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<
677
677
  * 判断是否合法JSON字符串
678
678
  * @param str
679
679
  */
680
- declare const isJSONStr: (str: string) => boolean;
680
+ declare const isJSONStr: (str: UnDef<string>) => boolean;
681
681
  /**
682
682
  * 判断是否合法JSON数组字符串
683
683
  * @param str
684
684
  */
685
- declare const isArrStr: (str: string) => boolean;
685
+ declare const isArrStr: (str: UnDef<string>) => boolean;
686
686
  /**
687
687
  * 判断是否有效的key
688
688
  * @param {string | number | symbol} key 键名
package/dist/index.mjs CHANGED
@@ -61,7 +61,11 @@ const jClear = console.clear.bind(console);
61
61
  const cnPhoneRE = /^1[3-9]\d{9}$/;
62
62
  const cnTelRE = /^0\d{9,11}$/;
63
63
  const isDef = (val) => val !== void 0 && val !== null;
64
- const isNumeric = (val) => typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
64
+ const isNumeric = (val) => {
65
+ if (isDef(val))
66
+ return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
67
+ return false;
68
+ };
65
69
  const checkImg = (ext) => {
66
70
  return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
67
71
  };
@@ -69,19 +73,23 @@ const isEmpty = (val) => {
69
73
  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
74
  };
71
75
  const isJSONStr = (str) => {
72
- try {
73
- JSON.parse(str);
74
- return true;
75
- } catch (e) {
76
- return false;
77
- }
76
+ if (isDef(str))
77
+ try {
78
+ JSON.parse(str);
79
+ return true;
80
+ } catch (e) {
81
+ return false;
82
+ }
83
+ return false;
78
84
  };
79
85
  const isArrStr = (str) => {
80
- try {
81
- return Array.isArray(JSON.parse(str));
82
- } catch (e) {
83
- return false;
84
- }
86
+ if (isDef(str))
87
+ try {
88
+ return Array.isArray(JSON.parse(str));
89
+ } catch (e) {
90
+ return false;
91
+ }
92
+ return false;
85
93
  };
86
94
  const isValidKey = (key, object) => key in object;
87
95
  const isPhone = (val) => {
@@ -226,11 +234,11 @@ const hideEmail = (email) => {
226
234
  if (!name || !domain)
227
235
  return email;
228
236
  const len = name.length;
229
- let newName = "";
237
+ let newName;
230
238
  if (len <= 3) {
231
239
  newName = `${name}***`;
232
240
  } else {
233
- newName = `${name.substring(0, len - 3)}***`;
241
+ newName = hideTail(name, 3);
234
242
  }
235
243
  return `${newName}@${domain}`;
236
244
  }
@@ -375,8 +383,11 @@ const toThousands = (num) => {
375
383
  const currencyFmt = (currency, fraction = 0) => {
376
384
  if (!isDef(currency))
377
385
  return "";
386
+ const num = Number(currency);
387
+ if (Number.isNaN(num))
388
+ return "";
378
389
  return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
379
- currency
390
+ num
380
391
  );
381
392
  };
382
393
 
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.26",
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",