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

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.ts CHANGED
@@ -1,11 +1,11 @@
1
- /// <reference types="dayjs/esm/plugin/localeData" />
2
- /// <reference types="dayjs/esm/plugin/duration" />
3
- /// <reference types="dayjs/esm/plugin/relativeTime" />
4
- /// <reference types="dayjs/esm/plugin/customParseFormat" />
5
- /// <reference types="dayjs/esm/plugin/objectSupport" />
1
+ /// <reference types="dayjs/plugin/localeData" />
2
+ /// <reference types="dayjs/plugin/duration" />
3
+ /// <reference types="dayjs/plugin/relativeTime" />
4
+ /// <reference types="dayjs/plugin/customParseFormat" />
5
+ /// <reference types="dayjs/plugin/objectSupport" />
6
6
  import * as detect_browser from 'detect-browser';
7
- import { ConfigType } from 'dayjs/esm';
8
- export { Dayjs, default as dayjs } from 'dayjs/esm';
7
+ import { ConfigType } from 'dayjs';
8
+ export { Dayjs, default as dayjs } from 'dayjs';
9
9
 
10
10
  /**
11
11
  * snake2Kebab
@@ -221,6 +221,10 @@ declare type Undefinable<T> = T | undefined;
221
221
  * 可 Null 或 Undefined
222
222
  */
223
223
  declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
224
+ /**
225
+ * alias for NullOrUndefinable
226
+ */
227
+ declare type UnDef<T> = NullOrUndefinable<T>;
224
228
  /**
225
229
  * 请求结果
226
230
  */
@@ -233,58 +237,70 @@ declare type PageResData<T = any> = Service.PageResponseData<T>;
233
237
  * 分页请求结果
234
238
  */
235
239
  declare type PageRes<T = any> = Service.PageResponse<T>;
240
+ /**
241
+ * 可能是数组
242
+ */
243
+ declare type MaybeArray<T = any> = T | Array<T>;
236
244
 
237
245
  /**
238
246
  * 隐藏中间部分
239
247
  * @param {string} str 需要隐藏的字符串
240
248
  */
241
- declare const hideMiddle: (str: NullOrUndefinable<string>) => string;
249
+ declare const hideMiddle: (str: UnDef<string>) => string;
242
250
  /**
243
251
  * 隐藏首尾仅保留中间3分之1
244
252
  * @param {string} str 需要隐藏的字符串
245
253
  */
246
- declare const hideThird: (str: NullOrUndefinable<string>) => string;
254
+ declare const hideThird: (str: UnDef<string>) => string;
247
255
  /**
248
256
  * 隐藏首部
249
257
  * @param {string} str 需要隐藏的字符串
258
+ * @param {number} count 隐藏的字符数
250
259
  */
251
- declare const hideHead: (str: NullOrUndefinable<string>) => string;
260
+ declare const hideHead: (str: UnDef<string>, count?: number) => string;
252
261
  /**
253
262
  * 隐藏尾部
254
263
  * @param {string} str 需要隐藏的字符串
264
+ * @param {number} count 隐藏的字符数
255
265
  */
256
- declare const hideTail: (str: NullOrUndefinable<string>) => string;
266
+ declare const hideTail: (str: UnDef<string>, count?: number) => string;
257
267
  /**
258
268
  * 隐藏手机号
259
269
  * @param {string} phone 手机号
260
270
  */
261
- declare const hidePhone: (phone: NullOrUndefinable<string>) => string;
271
+ declare const hidePhone: (phone: UnDef<string>) => string;
262
272
  /**
263
273
  * 隐藏身份证号
264
274
  * @param {string} cardNo 身份证号
275
+ * @param {boolean} strong 是否强化隐藏
265
276
  */
266
- declare const hideCardNo: (cardNo: NullOrUndefinable<string>) => string;
277
+ declare const hideCardNo: (cardNo: UnDef<string>, strong?: boolean) => string;
267
278
  /**
268
279
  * 隐藏姓名第一个字
269
280
  * @param {string} name 姓名
270
281
  * @deprecated 请使用 hideSurname
271
282
  */
272
- declare const hideName: (name: NullOrUndefinable<string>) => string;
283
+ declare const hideName: (name: UnDef<string>) => string;
273
284
  /**
274
285
  * 隐藏姓氏
275
286
  * @param {string} name 姓名
276
287
  */
277
- declare const hideSurname: (name: NullOrUndefinable<string>) => string;
288
+ declare const hideSurname: (name: UnDef<string>) => string;
278
289
  /**
279
290
  * 隐藏名字
280
291
  * @param {string} name 姓名
281
292
  */
282
- declare const hideFirstName: (name: NullOrUndefinable<string>) => string;
293
+ declare const hideFirstName: (name: UnDef<string>) => string;
283
294
  /**
284
295
  * 隐藏邮箱
285
296
  * @param {string} email 邮箱
286
297
  */
287
- declare const hideEmail: (email: NullOrUndefinable<string>) => string;
298
+ declare const hideEmail: (email: UnDef<string>) => string;
299
+ /**
300
+ * 隐藏银行卡号
301
+ * @param {string} bankCard 银行卡号
302
+ */
303
+ declare const hideBankCard: (bankCard: UnDef<string>) => string;
288
304
 
289
305
  /**
290
306
  * 判断是否是浏览器环境
@@ -512,18 +528,131 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
512
528
 
513
529
  /**
514
530
  * 格式化时间
515
- * @param {import('dayjs/esm').ConfigType} date 时间
531
+ * @param {import('dayjs').ConfigType} date 时间
516
532
  * @param {string} format 格式
517
533
  * @returns {string} 格式化后的时间
518
534
  */
519
535
  declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime') => string;
520
536
  /**
521
537
  * 格式化时间间隔
522
- * @param {import('dayjs/esm').ConfigType} start 开始时间
523
- * @param {import('dayjs/esm').ConfigType} end 结束时间
538
+ * @param {import('dayjs').ConfigType} start 开始时间
539
+ * @param {import('dayjs').ConfigType} end 结束时间
524
540
  */
525
541
  declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
526
542
 
543
+ /**
544
+ * 设置文件基本路径
545
+ * @param key
546
+ * @param baseUrl
547
+ */
548
+ declare function setBaseAttachUrl(baseUrl: string): void;
549
+ /**
550
+ * 获取文件基本路径
551
+ */
552
+ declare function getBaseAttachUrl(): string;
553
+
554
+ /**
555
+ * 千位分隔符
556
+ * @param num
557
+ */
558
+ declare const toThousands: (num: number) => string | undefined;
559
+ /**
560
+ * 货币格式化
561
+ * @param currency
562
+ * @param fraction
563
+ */
564
+ declare const currencyFmt: (currency: UnDef<number | bigint>, fraction?: number) => string;
565
+
566
+ type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
567
+ type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
568
+ type ElementPlusUploadFileStatus = 'ready' | 'uploading' | 'success' | 'fail'
569
+
570
+ interface Resource {
571
+ /** origin */
572
+ group: string
573
+ id: string
574
+ name: string
575
+ uri: string
576
+ /** extend */
577
+ url?: string
578
+ size?: number
579
+ uid?: string
580
+ status?: VantUploadFileStatus | AntdUploadFileStatus | ElementPlusUploadFileStatus
581
+ /** vant */
582
+ objectUrl?: string
583
+ content?: string
584
+ isImage?: boolean
585
+ message?: string
586
+ deletable?: boolean
587
+ reupload?: boolean
588
+ /** antd */
589
+ fileName?: string
590
+ percent?: number
591
+ thumbUrl?: string
592
+ /** element-plus */
593
+ percentage?: number
594
+ }
595
+
596
+ /**
597
+ * 获取文件完整地址
598
+ * @param url
599
+ */
600
+ declare const resUrl: (url: Undefinable<string>) => string | undefined;
601
+ /**
602
+ * 统一文件字段内容
603
+ * @param resource
604
+ */
605
+ declare const recoverFile: (resource: Resource) => {
606
+ url: string | undefined;
607
+ content: string | undefined;
608
+ uri: string;
609
+ status: string;
610
+ percent: number;
611
+ group: string;
612
+ id: string;
613
+ name: string;
614
+ size?: number | undefined;
615
+ uid?: string | undefined;
616
+ objectUrl?: string | undefined;
617
+ isImage?: boolean | undefined;
618
+ message?: string | undefined;
619
+ deletable?: boolean | undefined;
620
+ reupload?: boolean | undefined;
621
+ fileName?: string | undefined;
622
+ thumbUrl?: string | undefined; /**
623
+ * 统一文件字段内容
624
+ * @param resource
625
+ */
626
+ percentage?: number | undefined;
627
+ };
628
+ /**
629
+ * 附件格式
630
+ * @param data
631
+ */
632
+ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
633
+ url: string | undefined;
634
+ content: string | undefined;
635
+ uri: string;
636
+ status: string;
637
+ percent: number;
638
+ group: string;
639
+ id: string;
640
+ name: string;
641
+ size?: number | undefined;
642
+ uid?: string | undefined;
643
+ objectUrl?: string | undefined;
644
+ isImage?: boolean | undefined;
645
+ message?: string | undefined;
646
+ deletable?: boolean | undefined;
647
+ reupload?: boolean | undefined;
648
+ fileName?: string | undefined;
649
+ thumbUrl?: string | undefined; /**
650
+ * 统一文件字段内容
651
+ * @param resource
652
+ */
653
+ percentage?: number | undefined;
654
+ }[];
655
+
527
656
  /**
528
657
  * 是否有意义的值
529
658
  * @param val
@@ -539,6 +668,11 @@ declare const isNumeric: (val: Numeric) => val is string;
539
668
  * @param ext
540
669
  */
541
670
  declare const checkImg: (ext?: string) => boolean;
671
+ /**
672
+ * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
673
+ * @param val
674
+ */
675
+ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
542
676
  /**
543
677
  * 判断是否合法JSON字符串
544
678
  * @param str
@@ -566,42 +700,52 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
566
700
  * 是否是中国手机号
567
701
  * @param val
568
702
  */
569
- declare const isPhone: (val: NullOrUndefinable<Numeric>) => boolean;
703
+ declare const isPhone: (val: UnDef<Numeric>) => boolean;
570
704
  /**
571
705
  * 是否是中国座机号
572
706
  * @param val
573
707
  */
574
- declare const isTel: (val: NullOrUndefinable<Numeric>) => boolean;
708
+ declare const isTel: (val: UnDef<Numeric>) => boolean;
575
709
  /**
576
710
  * 是否是邮箱
577
711
  * @param val
578
712
  */
579
- declare const isEmail: (val: NullOrUndefinable<string>) => boolean;
713
+ declare const isEmail: (val: UnDef<string>) => boolean;
580
714
  /**
581
715
  * 是否是身份证
582
- * @param val 身份证号
716
+ * @param {string|null|undefined} val 身份证号
717
+ * @param {boolean} compatible 兼容15位
583
718
  */
584
- declare const isIdCard: (val: NullOrUndefinable<string>) => boolean;
719
+ declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
585
720
  /**
586
721
  * 包含非ASCII字符
587
722
  * @param text
588
723
  */
589
724
  declare const nonASCII: (text: string) => boolean;
725
+ /**
726
+ * 校验接口返回code
727
+ * @param res
728
+ * @param code
729
+ */
730
+ declare const isValidResCode: (res: Res, code?: number) => boolean;
590
731
  /**
591
732
  * 校验接口返回内容
592
733
  * @param res
734
+ * @param code
593
735
  */
594
- declare const isValidRes: (res: Res) => boolean;
736
+ declare const isValidRes: (res: Res, code?: number) => boolean;
595
737
  /**
596
738
  * 校验接口数组返回内容
597
739
  * @param res
740
+ * @param code
598
741
  */
599
- declare const isValidArrRes: (res: Res<any[]>) => boolean;
742
+ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
600
743
  /**
601
744
  * 校验接口分页返回内容
602
745
  * @param res
746
+ * @param code
603
747
  */
604
- declare const isValidPageRes: (res: PageRes) => boolean;
748
+ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
605
749
  /**
606
750
  * 校验文件类型
607
751
  * 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
@@ -610,4 +754,4 @@ declare const isValidPageRes: (res: PageRes) => boolean;
610
754
  */
611
755
  declare const isValidFileType: (file: File, type: string) => boolean;
612
756
 
613
- export { NullOrUndefinable, Nullable, Numeric, PageRes, PageResData, Res, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
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 };
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { detect } from 'detect-browser';
2
- import dayjs from 'dayjs/esm';
3
- export { default as dayjs } from 'dayjs/esm';
4
- import localeData from 'dayjs/esm/plugin/localeData';
5
- import duration from 'dayjs/esm/plugin/duration';
6
- import relativeTime from 'dayjs/esm/plugin/relativeTime';
7
- import customParseFormat from 'dayjs/esm/plugin/customParseFormat';
8
- import objectSupport from 'dayjs/esm/plugin/objectSupport';
9
- import zhCN from 'dayjs/esm/locale/zh-cn';
2
+ import dayjs from 'dayjs';
3
+ export { default as dayjs } from 'dayjs';
4
+ import localeData from 'dayjs/plugin/localeData';
5
+ import duration from 'dayjs/plugin/duration';
6
+ import relativeTime from 'dayjs/plugin/relativeTime';
7
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
8
+ import objectSupport from 'dayjs/plugin/objectSupport';
9
+ import zhCN from 'dayjs/locale/zh-cn';
10
10
 
11
11
  const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
12
12
  const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
@@ -65,6 +65,9 @@ const isNumeric = (val) => typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val
65
65
  const checkImg = (ext) => {
66
66
  return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
67
67
  };
68
+ const isEmpty = (val) => {
69
+ 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
+ };
68
71
  const isJSONStr = (str) => {
69
72
  try {
70
73
  JSON.parse(str);
@@ -97,17 +100,18 @@ const isEmail = (val) => {
97
100
  const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
98
101
  return reg.test(val);
99
102
  };
100
- const isIdCard = (val) => {
103
+ const isIdCard = (val, compatible = true) => {
101
104
  if (!isDef(val))
102
105
  return false;
103
106
  const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
104
107
  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]$/;
105
- return card15.test(val) || card18.test(val);
108
+ return card18.test(val) || (compatible ? card15.test(val) : false);
106
109
  };
107
110
  const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
108
- const isValidRes = (res) => res.code === 200 && isDef(res.data);
109
- const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
110
- const isValidPageRes = (res) => res.code === 200 && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
111
+ const isValidResCode = (res, code = 200) => res.code === code;
112
+ const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
113
+ const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
114
+ const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
111
115
  const isValidFileType = (file, type) => {
112
116
  if (type === "*")
113
117
  return true;
@@ -153,21 +157,23 @@ const hideThird = (str) => {
153
157
  return "**";
154
158
  return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
155
159
  };
156
- const hideHead = (str) => {
160
+ const hideHead = (str, count) => {
157
161
  if (!isDef(str))
158
162
  return "";
159
163
  const len = str.length;
164
+ const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
160
165
  if (len === 1)
161
166
  return "*";
162
- return "*".repeat(len - 1) + str[len - 1];
167
+ return "*".repeat(cnt) + str.substring(cnt);
163
168
  };
164
- const hideTail = (str) => {
169
+ const hideTail = (str, count) => {
165
170
  if (!isDef(str))
166
171
  return "";
167
172
  const len = str.length;
173
+ const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
168
174
  if (len === 1)
169
175
  return "*";
170
- return str[0] + "*".repeat(len - 1);
176
+ return str.substring(0, len - cnt) + "*".repeat(cnt);
171
177
  };
172
178
  const hidePhone = (phone) => {
173
179
  if (phone) {
@@ -181,9 +187,12 @@ const hidePhone = (phone) => {
181
187
  }
182
188
  return "";
183
189
  };
184
- const hideCardNo = (cardNo) => {
190
+ const hideCardNo = (cardNo, strong = true) => {
185
191
  if (cardNo) {
186
- return cardNo.replace(/^(.{4})\d+(.{2})$/, "$1*******$2");
192
+ if (isIdCard(cardNo, false)) {
193
+ return strong ? hideMiddle(cardNo) : cardNo.replace(/^(.)\d{3}(.{8})\d{5}(.)$/, "$1***$2*****$3");
194
+ }
195
+ return cardNo;
187
196
  }
188
197
  return "";
189
198
  };
@@ -202,7 +211,7 @@ const hideName = (name) => {
202
211
  return "";
203
212
  };
204
213
  const hideSurname = (name) => {
205
- return hideHead(name);
214
+ return hideHead(name, 1);
206
215
  };
207
216
  const hideFirstName = (name) => {
208
217
  return hideTail(name);
@@ -210,14 +219,29 @@ const hideFirstName = (name) => {
210
219
  const hideEmail = (email) => {
211
220
  if (email) {
212
221
  if (!email.includes("@"))
213
- return "";
222
+ return email;
214
223
  const arr = email.split("@");
215
224
  const name = arr[0];
216
225
  const domain = arr[1];
217
- const len = name?.length;
218
- if (!len)
226
+ if (!name || !domain)
219
227
  return email;
220
- return `${hideTail(name)}@${domain}`;
228
+ const len = name.length;
229
+ let newName = "";
230
+ if (len <= 3) {
231
+ newName = `${name}***`;
232
+ } else {
233
+ newName = `${name.substring(0, len - 3)}***`;
234
+ }
235
+ return `${newName}@${domain}`;
236
+ }
237
+ return "";
238
+ };
239
+ const hideBankCard = (bankCard) => {
240
+ if (bankCard) {
241
+ const len = bankCard.length;
242
+ if (len <= 10)
243
+ return bankCard;
244
+ return bankCard.substring(0, 6) + "*".repeat(len - 10) + bankCard.substring(len - 4, len);
221
245
  }
222
246
  return "";
223
247
  };
@@ -330,4 +354,77 @@ const dateDuration = (start, end) => {
330
354
  return dd.format(format);
331
355
  };
332
356
 
333
- export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
357
+ let BASE_ATTACH_URL;
358
+ function setBaseAttachUrl(baseUrl) {
359
+ BASE_ATTACH_URL = baseUrl;
360
+ }
361
+ function getBaseAttachUrl() {
362
+ return BASE_ATTACH_URL;
363
+ }
364
+ if (import.meta.env?.VITE_BASE_ATTACH_URL) {
365
+ setBaseAttachUrl(import.meta.env.VITE_BASE_ATTACH_URL);
366
+ }
367
+
368
+ const toThousands = (num) => {
369
+ const arr = num.toString().split(".");
370
+ const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
371
+ if (arr.length > 1)
372
+ return `${integer}.${arr[1]}`;
373
+ return integer;
374
+ };
375
+ const currencyFmt = (currency, fraction = 0) => {
376
+ if (!isDef(currency))
377
+ return "";
378
+ return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
379
+ currency
380
+ );
381
+ };
382
+
383
+ const resUrl = (url) => {
384
+ if (!isDef(url))
385
+ return void 0;
386
+ if (/^https?:\/\//.test(url) || /^blob:/.test(url) || /^data:/.test(url)) {
387
+ return url;
388
+ }
389
+ const baseUrl = getBaseAttachUrl();
390
+ if (!isDef(baseUrl)) {
391
+ throw new Error("\u8BF7\u5148\u8BBE\u7F6E import.meta\u200B.env.VITE_BASE_ATTACH_URL");
392
+ }
393
+ return `${baseUrl}/${url}`.replace(/([^:]\/)\/+/g, "$1");
394
+ };
395
+ const recoverFile = (resource) => {
396
+ const { uri, url, ...item } = resource;
397
+ const validUrl = uri || url;
398
+ return {
399
+ ...item,
400
+ url: resUrl(validUrl),
401
+ content: resUrl(validUrl),
402
+ uri: validUrl || "",
403
+ status: "done",
404
+ percent: 100
405
+ };
406
+ };
407
+ const attachFmt = (data) => {
408
+ let attachList = [];
409
+ const prototype = Object.prototype.toString.call(data);
410
+ if (!data)
411
+ attachList = [];
412
+ else if (Array.isArray(data))
413
+ attachList = data.filter(Boolean);
414
+ else if (typeof data === "string") {
415
+ if (isArrStr(data)) {
416
+ attachList = (parseToJSON(data) || []).filter(Boolean);
417
+ } else {
418
+ const jsonData = parseToJSON(data);
419
+ const prototypeJson = Object.prototype.toString.call(jsonData);
420
+ if (prototypeJson === "[object Object]")
421
+ attachList = [jsonData].filter(Boolean);
422
+ else
423
+ attachList = [{ id: data, name: "name", uri: data, group: "default" }];
424
+ }
425
+ } else if (prototype === "[object Object]")
426
+ attachList = [data];
427
+ return attachList.map(recoverFile);
428
+ };
429
+
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 };
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.23",
4
+ "version": "0.0.1-beta.25",
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",
@@ -20,9 +20,14 @@
20
20
  "sideEffects": false,
21
21
  "exports": {
22
22
  ".": {
23
- "types": "./dist/index.d.ts",
24
- "import": "./dist/index.mjs",
25
- "require": "./dist/index.cjs"
23
+ "import": {
24
+ "types": "./dist/index.d.mts",
25
+ "default": "./dist/index.mjs"
26
+ },
27
+ "require": {
28
+ "types": "./dist/index.d.cts",
29
+ "default": "./dist/index.cjs"
30
+ }
26
31
  }
27
32
  },
28
33
  "main": "dist/index.cjs",
@@ -37,7 +42,6 @@
37
42
  },
38
43
  "scripts": {
39
44
  "test": "vitest",
40
- "//build": "tsup",
41
45
  "build": "unbuild",
42
46
  "publint": "publint"
43
47
  }