@jhqn/utils-core 0.0.2-beta.2 → 0.0.2-beta.4

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
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const detectBrowser = require('detect-browser');
3
+ const detectBrowserEs = require('detect-browser-es');
4
4
  const dayjs = require('dayjs');
5
5
  const localeData = require('dayjs/plugin/localeData');
6
6
  const duration = require('dayjs/plugin/duration');
@@ -69,8 +69,24 @@ const jTime = (str) => console.time(`[${str}]`);
69
69
  const jTimeEnd = (str) => console.timeEnd(`[${str}]`);
70
70
  const jClear = console.clear.bind(console);
71
71
 
72
- const cnPhoneRE = /^1[3-9]\d{9}$/;
73
- const cnTelRE = /^0\d{9,11}$/;
72
+ let prevValue;
73
+ const jLogDedupe = (...args) => {
74
+ if (args.length === 0)
75
+ return;
76
+ if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue))
77
+ return;
78
+ jLog(...args);
79
+ prevValue = args;
80
+ };
81
+
82
+ let logged = false;
83
+ const jLogOnce = (...args) => {
84
+ if (logged)
85
+ return;
86
+ jLog(...args);
87
+ logged = true;
88
+ };
89
+
74
90
  const getVariableType = (val) => {
75
91
  const value = Object.prototype.toString.call(val);
76
92
  const result = value.match(/\[object (\S*)\]/)?.[1];
@@ -97,17 +113,6 @@ const isBlob = (val) => getVariableType(val) === "blob";
97
113
  const isURL = (val) => getVariableType(val) === "url";
98
114
  const isError = (val) => getVariableType(val) === "error";
99
115
  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
- };
105
- const checkImg = (ext) => {
106
- return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
107
- };
108
- const isEmpty = (val) => {
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;
110
- };
111
116
  const isJSONStr = (str) => {
112
117
  if (isDef(str))
113
118
  try {
@@ -128,6 +133,17 @@ const isArrStr = (str) => {
128
133
  return false;
129
134
  };
130
135
  const isValidKey = (key, object) => key in object;
136
+ const isEmpty = (val) => {
137
+ 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;
138
+ };
139
+
140
+ const isValidResCode = (res, code = 200) => res.code === code;
141
+ const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
142
+ const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
143
+ const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
144
+
145
+ const cnPhoneRE = /^1[3-9]\d{9}$/;
146
+ const cnTelRE = /^0\d{9,11}$/;
131
147
  const isPhone = (val) => {
132
148
  if (!isDef(val))
133
149
  return false;
@@ -151,11 +167,15 @@ const isIdCard = (val, compatible = true) => {
151
167
  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]$/;
152
168
  return card18.test(val) || (compatible ? card15.test(val) : false);
153
169
  };
170
+ const isNumeric = (val) => {
171
+ if (isDef(val))
172
+ return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
173
+ return false;
174
+ };
175
+ const checkImg = (ext) => {
176
+ return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
177
+ };
154
178
  const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
155
- const isValidResCode = (res, code = 200) => res.code === code;
156
- const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
157
- const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
158
- const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
159
179
  const isValidFileType = (file, type) => {
160
180
  if (type === "*")
161
181
  return true;
@@ -309,40 +329,25 @@ const fixiOSInputAutoZoomIn = () => {
309
329
  const userAgent = inBrowser ? window.navigator.userAgent : "";
310
330
  const getHostEnv = () => {
311
331
  const ua = userAgent.toLowerCase();
312
- const baseInfo = detectBrowser.detect();
332
+ const baseInfo = detectBrowserEs.parseUserAgent(ua);
313
333
  const zlb = ua.includes("@zlb");
314
334
  const zyd = ua.includes("saas");
315
335
  const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
316
336
  const wx = ua.includes("micromessenger");
317
337
  const zfb = ua.includes("alipay");
318
338
  const mini = ua.includes("miniprogram");
319
- return {
320
- ...baseInfo,
321
- /**
322
- * 是否是浙里办
323
- */
339
+ const additionalInfo = {
324
340
  zlb,
325
- /**
326
- * 是否是专有钉
327
- */
328
341
  zyd,
329
- /**
330
- * 是否是浙政钉
331
- */
332
342
  zzd,
333
- /**
334
- * 是否是微信
335
- */
336
343
  wx,
337
- /**
338
- * 是否是支付宝
339
- */
340
344
  zfb,
341
- /**
342
- * 是否是小程序
343
- */
344
345
  mini
345
346
  };
347
+ return {
348
+ ...baseInfo,
349
+ ...additionalInfo
350
+ };
346
351
  };
347
352
 
348
353
  const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
@@ -542,6 +547,8 @@ exports.jGroupC = jGroupC;
542
547
  exports.jGroupE = jGroupE;
543
548
  exports.jInfo = jInfo;
544
549
  exports.jLog = jLog;
550
+ exports.jLogDedupe = jLogDedupe;
551
+ exports.jLogOnce = jLogOnce;
545
552
  exports.jTime = jTime;
546
553
  exports.jTimeEnd = jTimeEnd;
547
554
  exports.jWarn = jWarn;
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  /// <reference types="dayjs/plugin/relativeTime" />
4
4
  /// <reference types="dayjs/plugin/customParseFormat" />
5
5
  /// <reference types="dayjs/plugin/objectSupport" />
6
- import * as detect_browser from 'detect-browser';
6
+ import * as detect_browser_es from 'detect-browser-es';
7
7
  import { ConfigType } from 'dayjs';
8
8
  export { Dayjs, default as dayjs } from 'dayjs';
9
9
 
@@ -183,10 +183,7 @@ declare const jGroupC: (...args: any[]) => void;
183
183
  /**
184
184
  * jade console.groupEnd
185
185
  */
186
- declare const jGroupE: {
187
- (): void;
188
- (): void;
189
- };
186
+ declare const jGroupE: () => void;
190
187
  /**
191
188
  * jade console.time
192
189
  * @param str
@@ -200,10 +197,19 @@ declare const jTimeEnd: (str: string) => void;
200
197
  /**
201
198
  * jade console.clear
202
199
  */
203
- declare const jClear: {
204
- (): void;
205
- (): void;
206
- };
200
+ declare const jClear: () => void;
201
+
202
+ /**
203
+ * 不连续打印相同的值
204
+ * @param args
205
+ */
206
+ declare const jLogDedupe: (...args: any[]) => void;
207
+
208
+ /**
209
+ * 只打印一次
210
+ * @param args
211
+ */
212
+ declare const jLogOnce: (...args: any[]) => void;
207
213
 
208
214
  /**
209
215
  * 数字或字符串
@@ -325,177 +331,50 @@ declare const userAgent: string;
325
331
  * 获取宿主环境信息
326
332
  */
327
333
  declare const getHostEnv: () => {
328
- /**
329
- * 是否是浙里办
330
- */
331
334
  zlb: boolean;
332
- /**
333
- * 是否是专有钉
334
- */
335
335
  zyd: boolean;
336
- /**
337
- * 是否是浙政钉
338
- */
339
336
  zzd: boolean;
340
- /**
341
- * 是否是微信
342
- */
343
337
  wx: boolean;
344
- /**
345
- * 是否是支付宝
346
- */
347
338
  zfb: boolean;
348
- /**
349
- * 是否是小程序
350
- */
351
339
  mini: boolean;
352
340
  } | {
353
- /**
354
- * 是否是浙里办
355
- */
356
341
  zlb: boolean;
357
- /**
358
- * 是否是专有钉
359
- */
360
342
  zyd: boolean;
361
- /**
362
- * 是否是浙政钉
363
- */
364
343
  zzd: boolean;
365
- /**
366
- * 是否是微信
367
- */
368
344
  wx: boolean;
369
- /**
370
- * 是否是支付宝
371
- */
372
345
  zfb: boolean;
373
- /**
374
- * 是否是小程序
375
- */
376
346
  mini: boolean;
377
- name: detect_browser.Browser;
347
+ name: detect_browser_es.Browser;
378
348
  version: string;
379
- os: detect_browser.OperatingSystem | null;
349
+ os: detect_browser_es.OperatingSystem | null;
350
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
380
351
  type: "browser";
381
352
  } | {
382
- /**
383
- * 是否是浙里办
384
- */
385
353
  zlb: boolean;
386
- /**
387
- * 是否是专有钉
388
- */
389
354
  zyd: boolean;
390
- /**
391
- * 是否是浙政钉
392
- */
393
355
  zzd: boolean;
394
- /**
395
- * 是否是微信
396
- */
397
356
  wx: boolean;
398
- /**
399
- * 是否是支付宝
400
- */
401
357
  zfb: boolean;
402
- /**
403
- * 是否是小程序
404
- */
405
358
  mini: boolean;
406
- name: detect_browser.Browser;
359
+ name: detect_browser_es.Browser;
407
360
  version: string;
408
- os: detect_browser.OperatingSystem | null;
361
+ os: detect_browser_es.OperatingSystem | null;
409
362
  bot: string;
410
363
  type: "bot-device";
364
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
411
365
  } | {
412
- /**
413
- * 是否是浙里办
414
- */
415
366
  zlb: boolean;
416
- /**
417
- * 是否是专有钉
418
- */
419
367
  zyd: boolean;
420
- /**
421
- * 是否是浙政钉
422
- */
423
368
  zzd: boolean;
424
- /**
425
- * 是否是微信
426
- */
427
369
  wx: boolean;
428
- /**
429
- * 是否是支付宝
430
- */
431
370
  zfb: boolean;
432
- /**
433
- * 是否是小程序
434
- */
435
371
  mini: boolean;
436
372
  type: "bot";
437
373
  bot: true;
438
374
  name: "bot";
439
375
  version: null;
440
376
  os: null;
441
- } | {
442
- /**
443
- * 是否是浙里办
444
- */
445
- zlb: boolean;
446
- /**
447
- * 是否是专有钉
448
- */
449
- zyd: boolean;
450
- /**
451
- * 是否是浙政钉
452
- */
453
- zzd: boolean;
454
- /**
455
- * 是否是微信
456
- */
457
- wx: boolean;
458
- /**
459
- * 是否是支付宝
460
- */
461
- zfb: boolean;
462
- /**
463
- * 是否是小程序
464
- */
465
- mini: boolean;
466
- version: string;
467
- type: "node";
468
- name: "node";
469
- os: NodeJS.Platform;
470
- } | {
471
- /**
472
- * 是否是浙里办
473
- */
474
- zlb: boolean;
475
- /**
476
- * 是否是专有钉
477
- */
478
- zyd: boolean;
479
- /**
480
- * 是否是浙政钉
481
- */
482
- zzd: boolean;
483
- /**
484
- * 是否是微信
485
- */
486
- wx: boolean;
487
- /**
488
- * 是否是支付宝
489
- */
490
- zfb: boolean;
491
- /**
492
- * 是否是小程序
493
- */
494
- mini: boolean;
495
- type: "react-native";
496
- name: "react-native";
497
- version: null;
498
- os: null;
377
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
499
378
  };
500
379
 
501
380
  /**
@@ -763,21 +642,6 @@ declare const isError: (val: any) => val is Error;
763
642
  * @param {any} val 检测的目标
764
643
  */
765
644
  declare const isDef: <T>(val: T) => val is NonNullable<T>;
766
- /**
767
- * 是否是数字或字符
768
- * @param val
769
- */
770
- declare const isNumeric: (val: UnDef<Numeric>) => val is string;
771
- /**
772
- * 是否是需要的图片格式
773
- * @param ext
774
- */
775
- declare const checkImg: (ext?: string) => boolean;
776
- /**
777
- * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
778
- * @param val
779
- */
780
- declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
781
645
  /**
782
646
  * 判断是否合法JSON字符串
783
647
  * @param str
@@ -802,31 +666,11 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
802
666
  */
803
667
  declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
804
668
  /**
805
- * 是否是中国手机号
806
- * @param val
807
- */
808
- declare const isPhone: (val: UnDef<Numeric>) => boolean;
809
- /**
810
- * 是否是中国座机号
811
- * @param val
812
- */
813
- declare const isTel: (val: UnDef<Numeric>) => boolean;
814
- /**
815
- * 是否是邮箱
669
+ * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
816
670
  * @param val
817
671
  */
818
- declare const isEmail: (val: UnDef<string>) => boolean;
819
- /**
820
- * 是否是身份证
821
- * @param {string|null|undefined} val 身份证号
822
- * @param {boolean} compatible 兼容15位
823
- */
824
- declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
825
- /**
826
- * 包含非ASCII字符
827
- * @param text
828
- */
829
- declare const nonASCII: (text: string) => boolean;
672
+ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
673
+
830
674
  /**
831
675
  * 校验接口返回code
832
676
  * @param res
@@ -851,6 +695,43 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
851
695
  * @param code
852
696
  */
853
697
  declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
698
+
699
+ /**
700
+ * 是否是中国手机号
701
+ * @param val
702
+ */
703
+ declare const isPhone: (val: UnDef<Numeric>) => boolean;
704
+ /**
705
+ * 是否是中国座机号
706
+ * @param val
707
+ */
708
+ declare const isTel: (val: UnDef<Numeric>) => boolean;
709
+ /**
710
+ * 是否是邮箱
711
+ * @param val
712
+ */
713
+ declare const isEmail: (val: UnDef<string>) => boolean;
714
+ /**
715
+ * 是否是身份证
716
+ * @param {string|null|undefined} val 身份证号
717
+ * @param {boolean} compatible 兼容15位
718
+ */
719
+ declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
720
+ /**
721
+ * 是否是数字或字符
722
+ * @param val
723
+ */
724
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
725
+ /**
726
+ * 是否是需要的图片格式
727
+ * @param ext
728
+ */
729
+ declare const checkImg: (ext?: string) => boolean;
730
+ /**
731
+ * 包含非ASCII字符
732
+ * @param text
733
+ */
734
+ declare const nonASCII: (text: string) => boolean;
854
735
  /**
855
736
  * 校验文件类型
856
737
  * 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
@@ -859,4 +740,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
859
740
  */
860
741
  declare const isValidFileType: (file: File, type: string) => boolean;
861
742
 
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 };
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, 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, 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 };
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@
3
3
  /// <reference types="dayjs/plugin/relativeTime" />
4
4
  /// <reference types="dayjs/plugin/customParseFormat" />
5
5
  /// <reference types="dayjs/plugin/objectSupport" />
6
- import * as detect_browser from 'detect-browser';
6
+ import * as detect_browser_es from 'detect-browser-es';
7
7
  import { ConfigType } from 'dayjs';
8
8
  export { Dayjs, default as dayjs } from 'dayjs';
9
9
 
@@ -183,10 +183,7 @@ declare const jGroupC: (...args: any[]) => void;
183
183
  /**
184
184
  * jade console.groupEnd
185
185
  */
186
- declare const jGroupE: {
187
- (): void;
188
- (): void;
189
- };
186
+ declare const jGroupE: () => void;
190
187
  /**
191
188
  * jade console.time
192
189
  * @param str
@@ -200,10 +197,19 @@ declare const jTimeEnd: (str: string) => void;
200
197
  /**
201
198
  * jade console.clear
202
199
  */
203
- declare const jClear: {
204
- (): void;
205
- (): void;
206
- };
200
+ declare const jClear: () => void;
201
+
202
+ /**
203
+ * 不连续打印相同的值
204
+ * @param args
205
+ */
206
+ declare const jLogDedupe: (...args: any[]) => void;
207
+
208
+ /**
209
+ * 只打印一次
210
+ * @param args
211
+ */
212
+ declare const jLogOnce: (...args: any[]) => void;
207
213
 
208
214
  /**
209
215
  * 数字或字符串
@@ -325,177 +331,50 @@ declare const userAgent: string;
325
331
  * 获取宿主环境信息
326
332
  */
327
333
  declare const getHostEnv: () => {
328
- /**
329
- * 是否是浙里办
330
- */
331
334
  zlb: boolean;
332
- /**
333
- * 是否是专有钉
334
- */
335
335
  zyd: boolean;
336
- /**
337
- * 是否是浙政钉
338
- */
339
336
  zzd: boolean;
340
- /**
341
- * 是否是微信
342
- */
343
337
  wx: boolean;
344
- /**
345
- * 是否是支付宝
346
- */
347
338
  zfb: boolean;
348
- /**
349
- * 是否是小程序
350
- */
351
339
  mini: boolean;
352
340
  } | {
353
- /**
354
- * 是否是浙里办
355
- */
356
341
  zlb: boolean;
357
- /**
358
- * 是否是专有钉
359
- */
360
342
  zyd: boolean;
361
- /**
362
- * 是否是浙政钉
363
- */
364
343
  zzd: boolean;
365
- /**
366
- * 是否是微信
367
- */
368
344
  wx: boolean;
369
- /**
370
- * 是否是支付宝
371
- */
372
345
  zfb: boolean;
373
- /**
374
- * 是否是小程序
375
- */
376
346
  mini: boolean;
377
- name: detect_browser.Browser;
347
+ name: detect_browser_es.Browser;
378
348
  version: string;
379
- os: detect_browser.OperatingSystem | null;
349
+ os: detect_browser_es.OperatingSystem | null;
350
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
380
351
  type: "browser";
381
352
  } | {
382
- /**
383
- * 是否是浙里办
384
- */
385
353
  zlb: boolean;
386
- /**
387
- * 是否是专有钉
388
- */
389
354
  zyd: boolean;
390
- /**
391
- * 是否是浙政钉
392
- */
393
355
  zzd: boolean;
394
- /**
395
- * 是否是微信
396
- */
397
356
  wx: boolean;
398
- /**
399
- * 是否是支付宝
400
- */
401
357
  zfb: boolean;
402
- /**
403
- * 是否是小程序
404
- */
405
358
  mini: boolean;
406
- name: detect_browser.Browser;
359
+ name: detect_browser_es.Browser;
407
360
  version: string;
408
- os: detect_browser.OperatingSystem | null;
361
+ os: detect_browser_es.OperatingSystem | null;
409
362
  bot: string;
410
363
  type: "bot-device";
364
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
411
365
  } | {
412
- /**
413
- * 是否是浙里办
414
- */
415
366
  zlb: boolean;
416
- /**
417
- * 是否是专有钉
418
- */
419
367
  zyd: boolean;
420
- /**
421
- * 是否是浙政钉
422
- */
423
368
  zzd: boolean;
424
- /**
425
- * 是否是微信
426
- */
427
369
  wx: boolean;
428
- /**
429
- * 是否是支付宝
430
- */
431
370
  zfb: boolean;
432
- /**
433
- * 是否是小程序
434
- */
435
371
  mini: boolean;
436
372
  type: "bot";
437
373
  bot: true;
438
374
  name: "bot";
439
375
  version: null;
440
376
  os: null;
441
- } | {
442
- /**
443
- * 是否是浙里办
444
- */
445
- zlb: boolean;
446
- /**
447
- * 是否是专有钉
448
- */
449
- zyd: boolean;
450
- /**
451
- * 是否是浙政钉
452
- */
453
- zzd: boolean;
454
- /**
455
- * 是否是微信
456
- */
457
- wx: boolean;
458
- /**
459
- * 是否是支付宝
460
- */
461
- zfb: boolean;
462
- /**
463
- * 是否是小程序
464
- */
465
- mini: boolean;
466
- version: string;
467
- type: "node";
468
- name: "node";
469
- os: NodeJS.Platform;
470
- } | {
471
- /**
472
- * 是否是浙里办
473
- */
474
- zlb: boolean;
475
- /**
476
- * 是否是专有钉
477
- */
478
- zyd: boolean;
479
- /**
480
- * 是否是浙政钉
481
- */
482
- zzd: boolean;
483
- /**
484
- * 是否是微信
485
- */
486
- wx: boolean;
487
- /**
488
- * 是否是支付宝
489
- */
490
- zfb: boolean;
491
- /**
492
- * 是否是小程序
493
- */
494
- mini: boolean;
495
- type: "react-native";
496
- name: "react-native";
497
- version: null;
498
- os: null;
377
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
499
378
  };
500
379
 
501
380
  /**
@@ -763,21 +642,6 @@ declare const isError: (val: any) => val is Error;
763
642
  * @param {any} val 检测的目标
764
643
  */
765
644
  declare const isDef: <T>(val: T) => val is NonNullable<T>;
766
- /**
767
- * 是否是数字或字符
768
- * @param val
769
- */
770
- declare const isNumeric: (val: UnDef<Numeric>) => val is string;
771
- /**
772
- * 是否是需要的图片格式
773
- * @param ext
774
- */
775
- declare const checkImg: (ext?: string) => boolean;
776
- /**
777
- * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
778
- * @param val
779
- */
780
- declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
781
645
  /**
782
646
  * 判断是否合法JSON字符串
783
647
  * @param str
@@ -802,31 +666,11 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
802
666
  */
803
667
  declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
804
668
  /**
805
- * 是否是中国手机号
806
- * @param val
807
- */
808
- declare const isPhone: (val: UnDef<Numeric>) => boolean;
809
- /**
810
- * 是否是中国座机号
811
- * @param val
812
- */
813
- declare const isTel: (val: UnDef<Numeric>) => boolean;
814
- /**
815
- * 是否是邮箱
669
+ * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
816
670
  * @param val
817
671
  */
818
- declare const isEmail: (val: UnDef<string>) => boolean;
819
- /**
820
- * 是否是身份证
821
- * @param {string|null|undefined} val 身份证号
822
- * @param {boolean} compatible 兼容15位
823
- */
824
- declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
825
- /**
826
- * 包含非ASCII字符
827
- * @param text
828
- */
829
- declare const nonASCII: (text: string) => boolean;
672
+ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
673
+
830
674
  /**
831
675
  * 校验接口返回code
832
676
  * @param res
@@ -851,6 +695,43 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
851
695
  * @param code
852
696
  */
853
697
  declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
698
+
699
+ /**
700
+ * 是否是中国手机号
701
+ * @param val
702
+ */
703
+ declare const isPhone: (val: UnDef<Numeric>) => boolean;
704
+ /**
705
+ * 是否是中国座机号
706
+ * @param val
707
+ */
708
+ declare const isTel: (val: UnDef<Numeric>) => boolean;
709
+ /**
710
+ * 是否是邮箱
711
+ * @param val
712
+ */
713
+ declare const isEmail: (val: UnDef<string>) => boolean;
714
+ /**
715
+ * 是否是身份证
716
+ * @param {string|null|undefined} val 身份证号
717
+ * @param {boolean} compatible 兼容15位
718
+ */
719
+ declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
720
+ /**
721
+ * 是否是数字或字符
722
+ * @param val
723
+ */
724
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
725
+ /**
726
+ * 是否是需要的图片格式
727
+ * @param ext
728
+ */
729
+ declare const checkImg: (ext?: string) => boolean;
730
+ /**
731
+ * 包含非ASCII字符
732
+ * @param text
733
+ */
734
+ declare const nonASCII: (text: string) => boolean;
854
735
  /**
855
736
  * 校验文件类型
856
737
  * 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
@@ -859,4 +740,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
859
740
  */
860
741
  declare const isValidFileType: (file: File, type: string) => boolean;
861
742
 
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 };
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, 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, 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 };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  /// <reference types="dayjs/plugin/relativeTime" />
4
4
  /// <reference types="dayjs/plugin/customParseFormat" />
5
5
  /// <reference types="dayjs/plugin/objectSupport" />
6
- import * as detect_browser from 'detect-browser';
6
+ import * as detect_browser_es from 'detect-browser-es';
7
7
  import { ConfigType } from 'dayjs';
8
8
  export { Dayjs, default as dayjs } from 'dayjs';
9
9
 
@@ -183,10 +183,7 @@ declare const jGroupC: (...args: any[]) => void;
183
183
  /**
184
184
  * jade console.groupEnd
185
185
  */
186
- declare const jGroupE: {
187
- (): void;
188
- (): void;
189
- };
186
+ declare const jGroupE: () => void;
190
187
  /**
191
188
  * jade console.time
192
189
  * @param str
@@ -200,10 +197,19 @@ declare const jTimeEnd: (str: string) => void;
200
197
  /**
201
198
  * jade console.clear
202
199
  */
203
- declare const jClear: {
204
- (): void;
205
- (): void;
206
- };
200
+ declare const jClear: () => void;
201
+
202
+ /**
203
+ * 不连续打印相同的值
204
+ * @param args
205
+ */
206
+ declare const jLogDedupe: (...args: any[]) => void;
207
+
208
+ /**
209
+ * 只打印一次
210
+ * @param args
211
+ */
212
+ declare const jLogOnce: (...args: any[]) => void;
207
213
 
208
214
  /**
209
215
  * 数字或字符串
@@ -325,177 +331,50 @@ declare const userAgent: string;
325
331
  * 获取宿主环境信息
326
332
  */
327
333
  declare const getHostEnv: () => {
328
- /**
329
- * 是否是浙里办
330
- */
331
334
  zlb: boolean;
332
- /**
333
- * 是否是专有钉
334
- */
335
335
  zyd: boolean;
336
- /**
337
- * 是否是浙政钉
338
- */
339
336
  zzd: boolean;
340
- /**
341
- * 是否是微信
342
- */
343
337
  wx: boolean;
344
- /**
345
- * 是否是支付宝
346
- */
347
338
  zfb: boolean;
348
- /**
349
- * 是否是小程序
350
- */
351
339
  mini: boolean;
352
340
  } | {
353
- /**
354
- * 是否是浙里办
355
- */
356
341
  zlb: boolean;
357
- /**
358
- * 是否是专有钉
359
- */
360
342
  zyd: boolean;
361
- /**
362
- * 是否是浙政钉
363
- */
364
343
  zzd: boolean;
365
- /**
366
- * 是否是微信
367
- */
368
344
  wx: boolean;
369
- /**
370
- * 是否是支付宝
371
- */
372
345
  zfb: boolean;
373
- /**
374
- * 是否是小程序
375
- */
376
346
  mini: boolean;
377
- name: detect_browser.Browser;
347
+ name: detect_browser_es.Browser;
378
348
  version: string;
379
- os: detect_browser.OperatingSystem | null;
349
+ os: detect_browser_es.OperatingSystem | null;
350
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
380
351
  type: "browser";
381
352
  } | {
382
- /**
383
- * 是否是浙里办
384
- */
385
353
  zlb: boolean;
386
- /**
387
- * 是否是专有钉
388
- */
389
354
  zyd: boolean;
390
- /**
391
- * 是否是浙政钉
392
- */
393
355
  zzd: boolean;
394
- /**
395
- * 是否是微信
396
- */
397
356
  wx: boolean;
398
- /**
399
- * 是否是支付宝
400
- */
401
357
  zfb: boolean;
402
- /**
403
- * 是否是小程序
404
- */
405
358
  mini: boolean;
406
- name: detect_browser.Browser;
359
+ name: detect_browser_es.Browser;
407
360
  version: string;
408
- os: detect_browser.OperatingSystem | null;
361
+ os: detect_browser_es.OperatingSystem | null;
409
362
  bot: string;
410
363
  type: "bot-device";
364
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
411
365
  } | {
412
- /**
413
- * 是否是浙里办
414
- */
415
366
  zlb: boolean;
416
- /**
417
- * 是否是专有钉
418
- */
419
367
  zyd: boolean;
420
- /**
421
- * 是否是浙政钉
422
- */
423
368
  zzd: boolean;
424
- /**
425
- * 是否是微信
426
- */
427
369
  wx: boolean;
428
- /**
429
- * 是否是支付宝
430
- */
431
370
  zfb: boolean;
432
- /**
433
- * 是否是小程序
434
- */
435
371
  mini: boolean;
436
372
  type: "bot";
437
373
  bot: true;
438
374
  name: "bot";
439
375
  version: null;
440
376
  os: null;
441
- } | {
442
- /**
443
- * 是否是浙里办
444
- */
445
- zlb: boolean;
446
- /**
447
- * 是否是专有钉
448
- */
449
- zyd: boolean;
450
- /**
451
- * 是否是浙政钉
452
- */
453
- zzd: boolean;
454
- /**
455
- * 是否是微信
456
- */
457
- wx: boolean;
458
- /**
459
- * 是否是支付宝
460
- */
461
- zfb: boolean;
462
- /**
463
- * 是否是小程序
464
- */
465
- mini: boolean;
466
- version: string;
467
- type: "node";
468
- name: "node";
469
- os: NodeJS.Platform;
470
- } | {
471
- /**
472
- * 是否是浙里办
473
- */
474
- zlb: boolean;
475
- /**
476
- * 是否是专有钉
477
- */
478
- zyd: boolean;
479
- /**
480
- * 是否是浙政钉
481
- */
482
- zzd: boolean;
483
- /**
484
- * 是否是微信
485
- */
486
- wx: boolean;
487
- /**
488
- * 是否是支付宝
489
- */
490
- zfb: boolean;
491
- /**
492
- * 是否是小程序
493
- */
494
- mini: boolean;
495
- type: "react-native";
496
- name: "react-native";
497
- version: null;
498
- os: null;
377
+ ua?: detect_browser_es.UserAgentDataInfo | undefined;
499
378
  };
500
379
 
501
380
  /**
@@ -763,21 +642,6 @@ declare const isError: (val: any) => val is Error;
763
642
  * @param {any} val 检测的目标
764
643
  */
765
644
  declare const isDef: <T>(val: T) => val is NonNullable<T>;
766
- /**
767
- * 是否是数字或字符
768
- * @param val
769
- */
770
- declare const isNumeric: (val: UnDef<Numeric>) => val is string;
771
- /**
772
- * 是否是需要的图片格式
773
- * @param ext
774
- */
775
- declare const checkImg: (ext?: string) => boolean;
776
- /**
777
- * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
778
- * @param val
779
- */
780
- declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
781
645
  /**
782
646
  * 判断是否合法JSON字符串
783
647
  * @param str
@@ -802,31 +666,11 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
802
666
  */
803
667
  declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
804
668
  /**
805
- * 是否是中国手机号
806
- * @param val
807
- */
808
- declare const isPhone: (val: UnDef<Numeric>) => boolean;
809
- /**
810
- * 是否是中国座机号
811
- * @param val
812
- */
813
- declare const isTel: (val: UnDef<Numeric>) => boolean;
814
- /**
815
- * 是否是邮箱
669
+ * 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
816
670
  * @param val
817
671
  */
818
- declare const isEmail: (val: UnDef<string>) => boolean;
819
- /**
820
- * 是否是身份证
821
- * @param {string|null|undefined} val 身份证号
822
- * @param {boolean} compatible 兼容15位
823
- */
824
- declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
825
- /**
826
- * 包含非ASCII字符
827
- * @param text
828
- */
829
- declare const nonASCII: (text: string) => boolean;
672
+ declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
673
+
830
674
  /**
831
675
  * 校验接口返回code
832
676
  * @param res
@@ -851,6 +695,43 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
851
695
  * @param code
852
696
  */
853
697
  declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
698
+
699
+ /**
700
+ * 是否是中国手机号
701
+ * @param val
702
+ */
703
+ declare const isPhone: (val: UnDef<Numeric>) => boolean;
704
+ /**
705
+ * 是否是中国座机号
706
+ * @param val
707
+ */
708
+ declare const isTel: (val: UnDef<Numeric>) => boolean;
709
+ /**
710
+ * 是否是邮箱
711
+ * @param val
712
+ */
713
+ declare const isEmail: (val: UnDef<string>) => boolean;
714
+ /**
715
+ * 是否是身份证
716
+ * @param {string|null|undefined} val 身份证号
717
+ * @param {boolean} compatible 兼容15位
718
+ */
719
+ declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
720
+ /**
721
+ * 是否是数字或字符
722
+ * @param val
723
+ */
724
+ declare const isNumeric: (val: UnDef<Numeric>) => val is string;
725
+ /**
726
+ * 是否是需要的图片格式
727
+ * @param ext
728
+ */
729
+ declare const checkImg: (ext?: string) => boolean;
730
+ /**
731
+ * 包含非ASCII字符
732
+ * @param text
733
+ */
734
+ declare const nonASCII: (text: string) => boolean;
854
735
  /**
855
736
  * 校验文件类型
856
737
  * 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
@@ -859,4 +740,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
859
740
  */
860
741
  declare const isValidFileType: (file: File, type: string) => boolean;
861
742
 
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 };
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, 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, 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 };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { detect } from 'detect-browser';
1
+ import { parseUserAgent } from 'detect-browser-es';
2
2
  import dayjs from 'dayjs';
3
3
  export { default as dayjs } from 'dayjs';
4
4
  import localeData from 'dayjs/plugin/localeData';
@@ -58,8 +58,24 @@ const jTime = (str) => console.time(`[${str}]`);
58
58
  const jTimeEnd = (str) => console.timeEnd(`[${str}]`);
59
59
  const jClear = console.clear.bind(console);
60
60
 
61
- const cnPhoneRE = /^1[3-9]\d{9}$/;
62
- const cnTelRE = /^0\d{9,11}$/;
61
+ let prevValue;
62
+ const jLogDedupe = (...args) => {
63
+ if (args.length === 0)
64
+ return;
65
+ if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue))
66
+ return;
67
+ jLog(...args);
68
+ prevValue = args;
69
+ };
70
+
71
+ let logged = false;
72
+ const jLogOnce = (...args) => {
73
+ if (logged)
74
+ return;
75
+ jLog(...args);
76
+ logged = true;
77
+ };
78
+
63
79
  const getVariableType = (val) => {
64
80
  const value = Object.prototype.toString.call(val);
65
81
  const result = value.match(/\[object (\S*)\]/)?.[1];
@@ -86,17 +102,6 @@ const isBlob = (val) => getVariableType(val) === "blob";
86
102
  const isURL = (val) => getVariableType(val) === "url";
87
103
  const isError = (val) => getVariableType(val) === "error";
88
104
  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
- };
94
- const checkImg = (ext) => {
95
- return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
96
- };
97
- const isEmpty = (val) => {
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;
99
- };
100
105
  const isJSONStr = (str) => {
101
106
  if (isDef(str))
102
107
  try {
@@ -117,6 +122,17 @@ const isArrStr = (str) => {
117
122
  return false;
118
123
  };
119
124
  const isValidKey = (key, object) => key in object;
125
+ const isEmpty = (val) => {
126
+ 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;
127
+ };
128
+
129
+ const isValidResCode = (res, code = 200) => res.code === code;
130
+ const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
131
+ const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
132
+ const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
133
+
134
+ const cnPhoneRE = /^1[3-9]\d{9}$/;
135
+ const cnTelRE = /^0\d{9,11}$/;
120
136
  const isPhone = (val) => {
121
137
  if (!isDef(val))
122
138
  return false;
@@ -140,11 +156,15 @@ const isIdCard = (val, compatible = true) => {
140
156
  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]$/;
141
157
  return card18.test(val) || (compatible ? card15.test(val) : false);
142
158
  };
159
+ const isNumeric = (val) => {
160
+ if (isDef(val))
161
+ return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
162
+ return false;
163
+ };
164
+ const checkImg = (ext) => {
165
+ return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
166
+ };
143
167
  const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
144
- const isValidResCode = (res, code = 200) => res.code === code;
145
- const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
146
- const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
147
- const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
148
168
  const isValidFileType = (file, type) => {
149
169
  if (type === "*")
150
170
  return true;
@@ -298,40 +318,25 @@ const fixiOSInputAutoZoomIn = () => {
298
318
  const userAgent = inBrowser ? window.navigator.userAgent : "";
299
319
  const getHostEnv = () => {
300
320
  const ua = userAgent.toLowerCase();
301
- const baseInfo = detect();
321
+ const baseInfo = parseUserAgent(ua);
302
322
  const zlb = ua.includes("@zlb");
303
323
  const zyd = ua.includes("saas");
304
324
  const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
305
325
  const wx = ua.includes("micromessenger");
306
326
  const zfb = ua.includes("alipay");
307
327
  const mini = ua.includes("miniprogram");
308
- return {
309
- ...baseInfo,
310
- /**
311
- * 是否是浙里办
312
- */
328
+ const additionalInfo = {
313
329
  zlb,
314
- /**
315
- * 是否是专有钉
316
- */
317
330
  zyd,
318
- /**
319
- * 是否是浙政钉
320
- */
321
331
  zzd,
322
- /**
323
- * 是否是微信
324
- */
325
332
  wx,
326
- /**
327
- * 是否是支付宝
328
- */
329
333
  zfb,
330
- /**
331
- * 是否是小程序
332
- */
333
334
  mini
334
335
  };
336
+ return {
337
+ ...baseInfo,
338
+ ...additionalInfo
339
+ };
335
340
  };
336
341
 
337
342
  const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
@@ -461,4 +466,4 @@ const attachFmt = (data) => {
461
466
  return attachList.map(recoverFile);
462
467
  };
463
468
 
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 };
469
+ 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, 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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jhqn/utils-core",
3
3
  "type": "module",
4
- "version": "0.0.2-beta.2",
4
+ "version": "0.0.2-beta.4",
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",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "dayjs": "^1.11.10",
41
- "detect-browser": "^5.3.0"
41
+ "detect-browser-es": "^0.1.0"
42
42
  },
43
43
  "scripts": {
44
44
  "test": "vitest",