@jhqn/utils-core 0.0.3-beta.5 → 0.0.3-beta.7

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
@@ -438,6 +438,23 @@ const attachFmt = (data) => {
438
438
  return attachList.map(recoverFile);
439
439
  };
440
440
 
441
+ const isNumberArray = (arr) => arr.every((item) => typeof item === "number");
442
+ const isStringArray = (arr) => arr.every((item) => typeof item === "string");
443
+ const naturalSort = (arr) => {
444
+ if (isNumberArray(arr))
445
+ return [...arr].sort((a, b) => a - b);
446
+ if (isStringArray(arr)) {
447
+ return [...arr].sort((a, b) => a.localeCompare(b, "zh-CN")).sort((a, b) => a.length - b.length);
448
+ }
449
+ const newArr = [...arr].sort();
450
+ const validArr = newArr.filter((a) => isDef(a));
451
+ const invalidArr = newArr.filter((a) => !isDef(a));
452
+ return naturalSort(validArr).concat(invalidArr);
453
+ };
454
+ const naturalSortBy = (arr, key) => {
455
+ return [...arr].sort((a, b) => naturalSort([a[key], b[key]])[0] === a[key] ? -1 : 1);
456
+ };
457
+
441
458
  const inBrowser = typeof window !== "undefined";
442
459
  const waitTime = (time = 100) => {
443
460
  return new Promise((resolve) => {
@@ -460,6 +477,7 @@ const getHostEnv = () => {
460
477
  const zlb = ua.includes("@zlb");
461
478
  const zyd = ua.includes("saas");
462
479
  const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd") || ua.includes("dingtalk-win");
480
+ const dd = ua.includes("taurusapp");
463
481
  const wx = ua.includes("micromessenger");
464
482
  const zfb = ua.includes("alipay");
465
483
  const mini = ua.includes("miniprogram");
@@ -467,6 +485,7 @@ const getHostEnv = () => {
467
485
  zlb,
468
486
  zyd,
469
487
  zzd,
488
+ dd,
470
489
  wx,
471
490
  zfb,
472
491
  mini
@@ -563,6 +582,8 @@ exports.kebab2Camel = kebab2Camel;
563
582
  exports.kebab2Pascal = kebab2Pascal;
564
583
  exports.kebab2Snake = kebab2Snake;
565
584
  exports.kebab2Title = kebab2Title;
585
+ exports.naturalSort = naturalSort;
586
+ exports.naturalSortBy = naturalSortBy;
566
587
  exports.nonASCII = nonASCII;
567
588
  exports.parseToJSON = parseToJSON;
568
589
  exports.pascal2Camel = pascal2Camel;
package/dist/index.d.cts CHANGED
@@ -220,39 +220,55 @@ declare const jLogOnce: (...args: any[]) => void;
220
220
  /**
221
221
  * 数字或字符串
222
222
  */
223
- declare type Numeric = number | string;
223
+ type Numeric = number | string;
224
224
  /**
225
225
  * 可 Null
226
226
  */
227
- declare type Nullable<T> = T | null;
227
+ type Nullable<T> = T | null;
228
228
  /**
229
229
  * 可 Undefined
230
230
  */
231
- declare type Undefinable<T> = T | undefined;
231
+ type Undefinable<T> = T | undefined;
232
232
  /**
233
233
  * 可 Null 或 Undefined
234
234
  */
235
- declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
235
+ type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
236
236
  /**
237
237
  * alias for NullOrUndefinable
238
238
  */
239
- declare type UnDef<T> = NullOrUndefinable<T>;
239
+ type UnDef<T> = NullOrUndefinable<T>;
240
240
  /**
241
241
  * 请求结果
242
242
  */
243
- declare type Res<T = any> = Service.Response<T>;
243
+ type Res<T = any> = Service.Response<T>;
244
244
  /**
245
245
  * 分页请求结果数据
246
246
  */
247
- declare type PageResData<T = any> = Service.PageResponseData<T>;
247
+ type PageResData<T = any> = Service.PageResponseData<T>;
248
248
  /**
249
249
  * 分页请求结果
250
250
  */
251
- declare type PageRes<T = any> = Service.PageResponse<T>;
251
+ type PageRes<T = any> = Service.PageResponse<T>;
252
+ /**
253
+ * 分页请求参数
254
+ */
255
+ type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
252
256
  /**
253
257
  * 可能是数组
254
258
  */
255
- declare type MaybeArray<T = any> = T | Array<T>;
259
+ type MaybeArray<T = any> = T | Array<T>;
260
+ /**
261
+ * 枚举键值对
262
+ */
263
+ type VK<T = string> = Record<string | number, T>;
264
+ /**
265
+ * 字典
266
+ */
267
+ type Dict<T = string> = Record<string, T>;
268
+ /**
269
+ * 使某键可选
270
+ */
271
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
256
272
 
257
273
  /**
258
274
  * 隐藏中间部分
@@ -327,6 +343,10 @@ interface HostEnv {
327
343
  * 是否是浙政钉
328
344
  */
329
345
  readonly zzd: boolean
346
+ /**
347
+ * 是否是钉钉/专有钉/浙政钉
348
+ */
349
+ readonly dd: boolean
330
350
  /**
331
351
  * 是否是微信
332
352
  */
@@ -368,6 +388,7 @@ declare const userAgent: string;
368
388
  * hostEnv.zlb // 浙里办
369
389
  * hostEnv.zyd // 专有钉
370
390
  * hostEnv.zzd // 浙政钉
391
+ * hostEnv.dd // 钉钉/专有钉/浙政钉
371
392
  * hostEnv.wx // 微信
372
393
  * hostEnv.zfb // 支付宝
373
394
  * hostEnv.mini // 小程序
@@ -535,6 +556,20 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
535
556
  percentage?: number | undefined;
536
557
  }[];
537
558
 
559
+ /**
560
+ * 自然排序
561
+ * @param {UnDef<string>[] | UnDef<number>[]} arr - 数字或字符串数组
562
+ * @returns {UnDef<string>[] | UnDef<number>[]} - 排序后的数组
563
+ */
564
+ declare const naturalSort: (arr: UnDef<string>[] | UnDef<number>[]) => UnDef<string>[] | UnDef<number>[];
565
+ /**
566
+ * 根据 key 自然排序
567
+ * @param arr - 数组
568
+ * @param {string} key - 键名
569
+ * @returns {any[]} - 排序后的数组
570
+ */
571
+ declare const naturalSortBy: <T extends Record<string, UnDef<Numeric>>>(arr: T[], key: keyof T) => T[];
572
+
538
573
  /**
539
574
  * 检测变量类型
540
575
  * @param {any} val 检测的目标
@@ -748,4 +783,4 @@ declare const nonASCII: (text: string) => boolean;
748
783
  */
749
784
  declare const isValidFileType: (file: File, type: string) => boolean;
750
785
 
751
- export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
786
+ export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, 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
@@ -220,39 +220,55 @@ declare const jLogOnce: (...args: any[]) => void;
220
220
  /**
221
221
  * 数字或字符串
222
222
  */
223
- declare type Numeric = number | string;
223
+ type Numeric = number | string;
224
224
  /**
225
225
  * 可 Null
226
226
  */
227
- declare type Nullable<T> = T | null;
227
+ type Nullable<T> = T | null;
228
228
  /**
229
229
  * 可 Undefined
230
230
  */
231
- declare type Undefinable<T> = T | undefined;
231
+ type Undefinable<T> = T | undefined;
232
232
  /**
233
233
  * 可 Null 或 Undefined
234
234
  */
235
- declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
235
+ type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
236
236
  /**
237
237
  * alias for NullOrUndefinable
238
238
  */
239
- declare type UnDef<T> = NullOrUndefinable<T>;
239
+ type UnDef<T> = NullOrUndefinable<T>;
240
240
  /**
241
241
  * 请求结果
242
242
  */
243
- declare type Res<T = any> = Service.Response<T>;
243
+ type Res<T = any> = Service.Response<T>;
244
244
  /**
245
245
  * 分页请求结果数据
246
246
  */
247
- declare type PageResData<T = any> = Service.PageResponseData<T>;
247
+ type PageResData<T = any> = Service.PageResponseData<T>;
248
248
  /**
249
249
  * 分页请求结果
250
250
  */
251
- declare type PageRes<T = any> = Service.PageResponse<T>;
251
+ type PageRes<T = any> = Service.PageResponse<T>;
252
+ /**
253
+ * 分页请求参数
254
+ */
255
+ type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
252
256
  /**
253
257
  * 可能是数组
254
258
  */
255
- declare type MaybeArray<T = any> = T | Array<T>;
259
+ type MaybeArray<T = any> = T | Array<T>;
260
+ /**
261
+ * 枚举键值对
262
+ */
263
+ type VK<T = string> = Record<string | number, T>;
264
+ /**
265
+ * 字典
266
+ */
267
+ type Dict<T = string> = Record<string, T>;
268
+ /**
269
+ * 使某键可选
270
+ */
271
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
256
272
 
257
273
  /**
258
274
  * 隐藏中间部分
@@ -327,6 +343,10 @@ interface HostEnv {
327
343
  * 是否是浙政钉
328
344
  */
329
345
  readonly zzd: boolean
346
+ /**
347
+ * 是否是钉钉/专有钉/浙政钉
348
+ */
349
+ readonly dd: boolean
330
350
  /**
331
351
  * 是否是微信
332
352
  */
@@ -368,6 +388,7 @@ declare const userAgent: string;
368
388
  * hostEnv.zlb // 浙里办
369
389
  * hostEnv.zyd // 专有钉
370
390
  * hostEnv.zzd // 浙政钉
391
+ * hostEnv.dd // 钉钉/专有钉/浙政钉
371
392
  * hostEnv.wx // 微信
372
393
  * hostEnv.zfb // 支付宝
373
394
  * hostEnv.mini // 小程序
@@ -535,6 +556,20 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
535
556
  percentage?: number | undefined;
536
557
  }[];
537
558
 
559
+ /**
560
+ * 自然排序
561
+ * @param {UnDef<string>[] | UnDef<number>[]} arr - 数字或字符串数组
562
+ * @returns {UnDef<string>[] | UnDef<number>[]} - 排序后的数组
563
+ */
564
+ declare const naturalSort: (arr: UnDef<string>[] | UnDef<number>[]) => UnDef<string>[] | UnDef<number>[];
565
+ /**
566
+ * 根据 key 自然排序
567
+ * @param arr - 数组
568
+ * @param {string} key - 键名
569
+ * @returns {any[]} - 排序后的数组
570
+ */
571
+ declare const naturalSortBy: <T extends Record<string, UnDef<Numeric>>>(arr: T[], key: keyof T) => T[];
572
+
538
573
  /**
539
574
  * 检测变量类型
540
575
  * @param {any} val 检测的目标
@@ -748,4 +783,4 @@ declare const nonASCII: (text: string) => boolean;
748
783
  */
749
784
  declare const isValidFileType: (file: File, type: string) => boolean;
750
785
 
751
- export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
786
+ export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, 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
@@ -220,39 +220,55 @@ declare const jLogOnce: (...args: any[]) => void;
220
220
  /**
221
221
  * 数字或字符串
222
222
  */
223
- declare type Numeric = number | string;
223
+ type Numeric = number | string;
224
224
  /**
225
225
  * 可 Null
226
226
  */
227
- declare type Nullable<T> = T | null;
227
+ type Nullable<T> = T | null;
228
228
  /**
229
229
  * 可 Undefined
230
230
  */
231
- declare type Undefinable<T> = T | undefined;
231
+ type Undefinable<T> = T | undefined;
232
232
  /**
233
233
  * 可 Null 或 Undefined
234
234
  */
235
- declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
235
+ type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
236
236
  /**
237
237
  * alias for NullOrUndefinable
238
238
  */
239
- declare type UnDef<T> = NullOrUndefinable<T>;
239
+ type UnDef<T> = NullOrUndefinable<T>;
240
240
  /**
241
241
  * 请求结果
242
242
  */
243
- declare type Res<T = any> = Service.Response<T>;
243
+ type Res<T = any> = Service.Response<T>;
244
244
  /**
245
245
  * 分页请求结果数据
246
246
  */
247
- declare type PageResData<T = any> = Service.PageResponseData<T>;
247
+ type PageResData<T = any> = Service.PageResponseData<T>;
248
248
  /**
249
249
  * 分页请求结果
250
250
  */
251
- declare type PageRes<T = any> = Service.PageResponse<T>;
251
+ type PageRes<T = any> = Service.PageResponse<T>;
252
+ /**
253
+ * 分页请求参数
254
+ */
255
+ type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
252
256
  /**
253
257
  * 可能是数组
254
258
  */
255
- declare type MaybeArray<T = any> = T | Array<T>;
259
+ type MaybeArray<T = any> = T | Array<T>;
260
+ /**
261
+ * 枚举键值对
262
+ */
263
+ type VK<T = string> = Record<string | number, T>;
264
+ /**
265
+ * 字典
266
+ */
267
+ type Dict<T = string> = Record<string, T>;
268
+ /**
269
+ * 使某键可选
270
+ */
271
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
256
272
 
257
273
  /**
258
274
  * 隐藏中间部分
@@ -327,6 +343,10 @@ interface HostEnv {
327
343
  * 是否是浙政钉
328
344
  */
329
345
  readonly zzd: boolean
346
+ /**
347
+ * 是否是钉钉/专有钉/浙政钉
348
+ */
349
+ readonly dd: boolean
330
350
  /**
331
351
  * 是否是微信
332
352
  */
@@ -368,6 +388,7 @@ declare const userAgent: string;
368
388
  * hostEnv.zlb // 浙里办
369
389
  * hostEnv.zyd // 专有钉
370
390
  * hostEnv.zzd // 浙政钉
391
+ * hostEnv.dd // 钉钉/专有钉/浙政钉
371
392
  * hostEnv.wx // 微信
372
393
  * hostEnv.zfb // 支付宝
373
394
  * hostEnv.mini // 小程序
@@ -535,6 +556,20 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
535
556
  percentage?: number | undefined;
536
557
  }[];
537
558
 
559
+ /**
560
+ * 自然排序
561
+ * @param {UnDef<string>[] | UnDef<number>[]} arr - 数字或字符串数组
562
+ * @returns {UnDef<string>[] | UnDef<number>[]} - 排序后的数组
563
+ */
564
+ declare const naturalSort: (arr: UnDef<string>[] | UnDef<number>[]) => UnDef<string>[] | UnDef<number>[];
565
+ /**
566
+ * 根据 key 自然排序
567
+ * @param arr - 数组
568
+ * @param {string} key - 键名
569
+ * @returns {any[]} - 排序后的数组
570
+ */
571
+ declare const naturalSortBy: <T extends Record<string, UnDef<Numeric>>>(arr: T[], key: keyof T) => T[];
572
+
538
573
  /**
539
574
  * 检测变量类型
540
575
  * @param {any} val 检测的目标
@@ -748,4 +783,4 @@ declare const nonASCII: (text: string) => boolean;
748
783
  */
749
784
  declare const isValidFileType: (file: File, type: string) => boolean;
750
785
 
751
- export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
786
+ export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, 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
@@ -427,6 +427,23 @@ const attachFmt = (data) => {
427
427
  return attachList.map(recoverFile);
428
428
  };
429
429
 
430
+ const isNumberArray = (arr) => arr.every((item) => typeof item === "number");
431
+ const isStringArray = (arr) => arr.every((item) => typeof item === "string");
432
+ const naturalSort = (arr) => {
433
+ if (isNumberArray(arr))
434
+ return [...arr].sort((a, b) => a - b);
435
+ if (isStringArray(arr)) {
436
+ return [...arr].sort((a, b) => a.localeCompare(b, "zh-CN")).sort((a, b) => a.length - b.length);
437
+ }
438
+ const newArr = [...arr].sort();
439
+ const validArr = newArr.filter((a) => isDef(a));
440
+ const invalidArr = newArr.filter((a) => !isDef(a));
441
+ return naturalSort(validArr).concat(invalidArr);
442
+ };
443
+ const naturalSortBy = (arr, key) => {
444
+ return [...arr].sort((a, b) => naturalSort([a[key], b[key]])[0] === a[key] ? -1 : 1);
445
+ };
446
+
430
447
  const inBrowser = typeof window !== "undefined";
431
448
  const waitTime = (time = 100) => {
432
449
  return new Promise((resolve) => {
@@ -449,6 +466,7 @@ const getHostEnv = () => {
449
466
  const zlb = ua.includes("@zlb");
450
467
  const zyd = ua.includes("saas");
451
468
  const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd") || ua.includes("dingtalk-win");
469
+ const dd = ua.includes("taurusapp");
452
470
  const wx = ua.includes("micromessenger");
453
471
  const zfb = ua.includes("alipay");
454
472
  const mini = ua.includes("miniprogram");
@@ -456,6 +474,7 @@ const getHostEnv = () => {
456
474
  zlb,
457
475
  zyd,
458
476
  zzd,
477
+ dd,
459
478
  wx,
460
479
  zfb,
461
480
  mini
@@ -468,4 +487,4 @@ const getCodeOfHour = () => getCodeOfTime(`${dateFmt( new Date(), "YYYY-MM-DD HH
468
487
  const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "date"));
469
488
  const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs().endOf("month"), "date"));
470
489
 
471
- export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
490
+ export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, 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.3-beta.5",
4
+ "version": "0.0.3-beta.7",
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",