a2bei4-utils 1.0.2 → 1.0.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/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/a2bei4.utils.cjs.js +2080 -1846
- package/dist/a2bei4.utils.cjs.js.map +1 -1
- package/dist/a2bei4.utils.cjs.min.js +1 -1
- package/dist/a2bei4.utils.cjs.min.js.map +1 -1
- package/dist/a2bei4.utils.esm.js +2073 -1843
- package/dist/a2bei4.utils.esm.js.map +1 -1
- package/dist/a2bei4.utils.esm.min.js +1 -1
- package/dist/a2bei4.utils.esm.min.js.map +1 -1
- package/dist/a2bei4.utils.umd.js +2080 -1846
- package/dist/a2bei4.utils.umd.js.map +1 -1
- package/dist/a2bei4.utils.umd.min.js +1 -1
- package/dist/a2bei4.utils.umd.min.js.map +1 -1
- package/dist/arr.cjs +27 -27
- package/dist/arr.cjs.map +1 -1
- package/dist/arr.js +27 -27
- package/dist/arr.js.map +1 -1
- package/dist/audio.cjs +274 -274
- package/dist/audio.cjs.map +1 -1
- package/dist/audio.js +274 -274
- package/dist/audio.js.map +1 -1
- package/dist/browser.cjs +52 -52
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +52 -52
- package/dist/browser.js.map +1 -1
- package/dist/common.cjs +369 -369
- package/dist/common.cjs.map +1 -1
- package/dist/common.js +369 -369
- package/dist/common.js.map +1 -1
- package/dist/date.cjs +421 -188
- package/dist/date.cjs.map +1 -1
- package/dist/date.js +414 -185
- package/dist/date.js.map +1 -1
- package/dist/download.cjs +102 -102
- package/dist/download.cjs.map +1 -1
- package/dist/download.js +102 -102
- package/dist/download.js.map +1 -1
- package/dist/evt.cjs +148 -148
- package/dist/evt.cjs.map +1 -1
- package/dist/evt.js +148 -148
- package/dist/evt.js.map +1 -1
- package/dist/id.cjs +68 -68
- package/dist/id.cjs.map +1 -1
- package/dist/id.js +68 -68
- package/dist/id.js.map +1 -1
- package/dist/timer.cjs +51 -50
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.js +51 -50
- package/dist/timer.js.map +1 -1
- package/dist/tree.cjs +165 -165
- package/dist/tree.cjs.map +1 -1
- package/dist/tree.js +165 -165
- package/dist/tree.js.map +1 -1
- package/dist/webSocket.cjs +403 -403
- package/dist/webSocket.cjs.map +1 -1
- package/dist/webSocket.js +403 -403
- package/dist/webSocket.js.map +1 -1
- package/package.json +1 -1
- package/readme.txt +21 -11
- package/types/date.d.ts +243 -45
- package/types/index.d.ts +244 -47
package/types/index.d.ts
CHANGED
|
@@ -464,60 +464,257 @@ declare function toDate(val: any): Date | null;
|
|
|
464
464
|
*/
|
|
465
465
|
declare function randomDateInRange(date1: Date, date2: Date): Date;
|
|
466
466
|
/**
|
|
467
|
-
*
|
|
467
|
+
* 时间持续对象(完整版本,包含年月日时分秒毫秒)
|
|
468
|
+
* @typedef {Object} DurationObject
|
|
469
|
+
* @property {number} years - 年数
|
|
470
|
+
* @property {number} months - 月数(0-11)
|
|
471
|
+
* @property {number} days - 天数(0-29,取决于 monthDays)
|
|
472
|
+
* @property {number} hours - 小时数(0-23)
|
|
473
|
+
* @property {number} minutes - 分钟数(0-59)
|
|
474
|
+
* @property {number} seconds - 秒数(0-59)
|
|
475
|
+
* @property {number} milliseconds - 毫秒数(0-999)
|
|
476
|
+
*/
|
|
477
|
+
/**
|
|
478
|
+
* 时间持续对象(最大单位为天)
|
|
479
|
+
* @typedef {Object} DurationMaxDayObject
|
|
480
|
+
* @property {number} days - 天数
|
|
481
|
+
* @property {number} hours - 小时数(0-23)
|
|
482
|
+
* @property {number} minutes - 分钟数(0-59)
|
|
483
|
+
* @property {number} seconds - 秒数(0-59)
|
|
484
|
+
* @property {number} milliseconds - 毫秒数(0-999)
|
|
485
|
+
*/
|
|
486
|
+
/**
|
|
487
|
+
* 时间持续对象(最大单位为小时)
|
|
488
|
+
* @typedef {Object} DurationMaxHourObject
|
|
489
|
+
* @property {number} hours - 小时数
|
|
490
|
+
* @property {number} minutes - 分钟数(0-59)
|
|
491
|
+
* @property {number} seconds - 秒数(0-59)
|
|
492
|
+
* @property {number} milliseconds - 毫秒数(0-999)
|
|
493
|
+
*/
|
|
494
|
+
/**
|
|
495
|
+
* 将毫秒转换为时间持续对象。
|
|
496
|
+
*
|
|
497
|
+
* @param {number} milliseconds - 毫秒数(非负整数)
|
|
498
|
+
* @param {Object} [options] - 选项对象。
|
|
499
|
+
* @param {number} [options.yearDays=365] - 一年的天数。
|
|
500
|
+
* @param {number} [options.monthDays=30] - 一月的天数。
|
|
501
|
+
* @returns {DurationObject} 时间持续对象
|
|
502
|
+
* @throws {TypeError} 当 milliseconds 不是有效数字
|
|
503
|
+
* @throws {RangeError} 当 milliseconds 为负数
|
|
504
|
+
* @throws {RangeError} 当 yearDays 或 monthDays 不是正整数
|
|
468
505
|
*
|
|
469
|
-
* @
|
|
470
|
-
*
|
|
471
|
-
*
|
|
506
|
+
* @example
|
|
507
|
+
* // 基本用法
|
|
508
|
+
* millisecond2Duration(42070000500);
|
|
509
|
+
* // 返回: { years: 1, months: 4, days: 1, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
|
|
510
|
+
*/
|
|
511
|
+
declare function millisecond2Duration(milliseconds: number, options?: {
|
|
512
|
+
yearDays?: number | undefined;
|
|
513
|
+
monthDays?: number | undefined;
|
|
514
|
+
}): DurationObject;
|
|
515
|
+
/**
|
|
516
|
+
* 将毫秒转换为时间持续对象(最大单位为天)。
|
|
517
|
+
* @param {number} milliseconds - 毫秒数(非负整数)
|
|
518
|
+
* @returns {DurationMaxDayObject} 包含天、小时、分钟、秒、毫秒的时间持续对象
|
|
519
|
+
* @throws {TypeError} 当 milliseconds 不是有效数字时抛出
|
|
520
|
+
* @throws {RangeError} 当 milliseconds 为负数时抛出
|
|
521
|
+
* @example
|
|
522
|
+
* // 返回 { days: 486, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
|
|
523
|
+
* millisecond2DurationMaxDay(42070000500);
|
|
472
524
|
*/
|
|
473
|
-
declare function
|
|
474
|
-
days: number;
|
|
475
|
-
hours: string;
|
|
476
|
-
minutes: string;
|
|
477
|
-
seconds: string;
|
|
478
|
-
};
|
|
525
|
+
declare function millisecond2DurationMaxDay(milliseconds: number): DurationMaxDayObject;
|
|
479
526
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* @
|
|
484
|
-
* @
|
|
485
|
-
* @
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
* @throws {TypeError} 当 totalSeconds 为非数字或负数时抛出
|
|
491
|
-
*/
|
|
492
|
-
declare function formatDuration(totalSeconds: number, options?: {
|
|
493
|
-
labels?: Partial<{
|
|
494
|
-
year: string;
|
|
495
|
-
month: string;
|
|
496
|
-
day: string;
|
|
497
|
-
hour: string;
|
|
498
|
-
minute: string;
|
|
499
|
-
second: string;
|
|
500
|
-
}> | undefined;
|
|
501
|
-
maxUnit?: "year" | "month" | "day" | "hour" | "minute" | "second" | undefined;
|
|
502
|
-
minUnit?: "year" | "month" | "day" | "hour" | "minute" | "second" | undefined;
|
|
503
|
-
showZero?: boolean | undefined;
|
|
504
|
-
}): string;
|
|
527
|
+
* 将毫秒转换为时间持续对象(最大单位为小时)。
|
|
528
|
+
* @param {number} milliseconds - 毫秒数(非负整数)
|
|
529
|
+
* @returns {DurationMaxHourObject} 包含小时、分钟、秒、毫秒的时间持续对象
|
|
530
|
+
* @throws {TypeError} 当 milliseconds 不是有效数字时抛出
|
|
531
|
+
* @throws {RangeError} 当 milliseconds 为负数时抛出
|
|
532
|
+
* @example
|
|
533
|
+
* // 返回 { hours: 11686, minutes: 6, seconds: 40, milliseconds: 500 }
|
|
534
|
+
* millisecond2DurationMaxHour(42070000500);
|
|
535
|
+
*/
|
|
536
|
+
declare function millisecond2DurationMaxHour(milliseconds: number): DurationMaxHourObject;
|
|
505
537
|
/**
|
|
506
|
-
*
|
|
538
|
+
* 将秒转换为时间持续对象。
|
|
507
539
|
*
|
|
508
|
-
* @param {number}
|
|
509
|
-
* @param {
|
|
510
|
-
* @
|
|
540
|
+
* @param {number} seconds - 秒数(非负整数)
|
|
541
|
+
* @param {Object} [options] - 选项对象。
|
|
542
|
+
* @param {number} [options.yearDays=365] - 一年的天数。
|
|
543
|
+
* @param {number} [options.monthDays=30] - 一月的天数。
|
|
544
|
+
* @returns {DurationObject} 时间持续对象
|
|
545
|
+
* @throws {TypeError} 当 seconds 不是有效数字
|
|
546
|
+
* @throws {RangeError} 当 seconds 为负数
|
|
547
|
+
* @throws {RangeError} 当 yearDays 或 monthDays 不是正整数
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* // 基本用法
|
|
551
|
+
* second2Duration(42070000.5);
|
|
552
|
+
* // 返回: { years: 1, months: 4, days: 1, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
|
|
553
|
+
*/
|
|
554
|
+
declare function second2Duration(seconds: number, options?: {
|
|
555
|
+
yearDays?: number | undefined;
|
|
556
|
+
monthDays?: number | undefined;
|
|
557
|
+
}): DurationObject;
|
|
558
|
+
/**
|
|
559
|
+
* 将秒转换为时间持续对象(最大单位为天)。
|
|
560
|
+
* @param {number} seconds - 秒数(非负整数)
|
|
561
|
+
* @returns {DurationMaxDayObject} 包含天、小时、分钟、秒、毫秒的时间持续对象
|
|
562
|
+
* @throws {TypeError} 当 seconds 不是有效数字时抛出
|
|
563
|
+
* @throws {RangeError} 当 seconds 为负数时抛出
|
|
564
|
+
* @example
|
|
565
|
+
* // 返回 { days: 486, hours: 22, minutes: 6, seconds: 40, milliseconds: 500 }
|
|
566
|
+
* second2DurationMaxDay(42070000.5);
|
|
511
567
|
*/
|
|
512
|
-
declare function
|
|
568
|
+
declare function second2DurationMaxDay(seconds: number): DurationMaxDayObject;
|
|
513
569
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
* @
|
|
517
|
-
* @
|
|
518
|
-
* @
|
|
570
|
+
* 将秒转换为时间持续对象(最大单位为小时)。
|
|
571
|
+
* @param {number} seconds - 秒数(非负整数)
|
|
572
|
+
* @returns {DurationMaxHourObject} 包含小时、分钟、秒、毫秒的时间持续对象
|
|
573
|
+
* @throws {TypeError} 当 seconds 不是有效数字时抛出
|
|
574
|
+
* @throws {RangeError} 当 seconds 为负数时抛出
|
|
575
|
+
* @example
|
|
576
|
+
* // 返回 { hours: 11686, minutes: 6, seconds: 40, milliseconds: 500 }
|
|
577
|
+
* second2DurationMaxHour(42070000.5);
|
|
578
|
+
*/
|
|
579
|
+
declare function second2DurationMaxHour(seconds: number): DurationMaxHourObject;
|
|
580
|
+
/**
|
|
581
|
+
* 根据小时数返回对应的时间段名称。
|
|
582
|
+
*
|
|
583
|
+
* @param {number} hour - 24 小时制的小时(0-23)
|
|
584
|
+
* @param {object} [locales] - 自定义时段文案
|
|
585
|
+
* @param {string} [locales.earlyMorning="凌晨"] - 00-05
|
|
586
|
+
* @param {string} [locales.morning="上午"] - 06-11
|
|
587
|
+
* @param {string} [locales.noon="中午"] - 12-13
|
|
588
|
+
* @param {string} [locales.afternoon="下午"] - 14-17
|
|
589
|
+
* @param {string} [locales.evening="晚上"] - 18-23
|
|
590
|
+
* @returns {string} 时段名称
|
|
591
|
+
* @throws {RangeError} 当 hour 不在 0-23 范围时抛出
|
|
592
|
+
*/
|
|
593
|
+
declare function getTimePeriodName(hour: number, locales?: {
|
|
594
|
+
earlyMorning?: string | undefined;
|
|
595
|
+
morning?: string | undefined;
|
|
596
|
+
noon?: string | undefined;
|
|
597
|
+
afternoon?: string | undefined;
|
|
598
|
+
evening?: string | undefined;
|
|
599
|
+
}): string;
|
|
600
|
+
/**
|
|
601
|
+
* 格式化时间戳为本地化的时间字符串。
|
|
602
|
+
*
|
|
603
|
+
* @param {number} timestamp - 要格式化的时间戳(毫秒)。
|
|
604
|
+
* @param {Object} [locales] - 本地化配置对象,包含时间相关的本地化字符串。
|
|
605
|
+
* @param {string} [locales.justNow='刚刚'] - 表示刚刚过去的时间。
|
|
606
|
+
* @param {string} [locales.today='今天'] - 表示今天。
|
|
607
|
+
* @param {string} [locales.yesterday='昨天'] - 表示昨天。
|
|
608
|
+
* @param {string} [locales.beforeYesterday='前天'] - 表示前天。
|
|
609
|
+
* @param {string} [locales.year='年'] - 年的单位。
|
|
610
|
+
* @param {string} [locales.month='月'] - 月的单位。
|
|
611
|
+
* @param {string} [locales.day='日'] - 日的单位。
|
|
612
|
+
* @param {Object} [locales.timePeriod] - 一天中不同时间段的本地化字符串。
|
|
613
|
+
* @param {string} [locales.timePeriod.earlyMorning='凌晨'] - 凌晨。
|
|
614
|
+
* @param {string} [locales.timePeriod.morning='上午'] - 上午。
|
|
615
|
+
* @param {string} [locales.timePeriod.noon='中午'] - 中午。
|
|
616
|
+
* @param {string} [locales.timePeriod.afternoon='下午'] - 下午。
|
|
617
|
+
* @param {string} [locales.timePeriod.evening='晚上'] - 晚上。
|
|
618
|
+
* @param {Array<string>} [locales.weekDays=['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']] - 星期几的本地化字符串数组。
|
|
619
|
+
*
|
|
620
|
+
* @returns {string} - 格式化后的时间字符串。
|
|
621
|
+
*/
|
|
622
|
+
declare function formatTimeForLocale(timestamp: number, locales?: {
|
|
623
|
+
justNow?: string | undefined;
|
|
624
|
+
today?: string | undefined;
|
|
625
|
+
yesterday?: string | undefined;
|
|
626
|
+
beforeYesterday?: string | undefined;
|
|
627
|
+
year?: string | undefined;
|
|
628
|
+
month?: string | undefined;
|
|
629
|
+
day?: string | undefined;
|
|
630
|
+
timePeriod?: {
|
|
631
|
+
earlyMorning?: string | undefined;
|
|
632
|
+
morning?: string | undefined;
|
|
633
|
+
noon?: string | undefined;
|
|
634
|
+
afternoon?: string | undefined;
|
|
635
|
+
evening?: string | undefined;
|
|
636
|
+
} | undefined;
|
|
637
|
+
weekDays?: string[] | undefined;
|
|
638
|
+
}): string;
|
|
639
|
+
/**
|
|
640
|
+
* 时间持续对象(完整版本,包含年月日时分秒毫秒)
|
|
519
641
|
*/
|
|
520
|
-
|
|
642
|
+
type DurationObject = {
|
|
643
|
+
/**
|
|
644
|
+
* - 年数
|
|
645
|
+
*/
|
|
646
|
+
years: number;
|
|
647
|
+
/**
|
|
648
|
+
* - 月数(0-11)
|
|
649
|
+
*/
|
|
650
|
+
months: number;
|
|
651
|
+
/**
|
|
652
|
+
* - 天数(0-29,取决于 monthDays)
|
|
653
|
+
*/
|
|
654
|
+
days: number;
|
|
655
|
+
/**
|
|
656
|
+
* - 小时数(0-23)
|
|
657
|
+
*/
|
|
658
|
+
hours: number;
|
|
659
|
+
/**
|
|
660
|
+
* - 分钟数(0-59)
|
|
661
|
+
*/
|
|
662
|
+
minutes: number;
|
|
663
|
+
/**
|
|
664
|
+
* - 秒数(0-59)
|
|
665
|
+
*/
|
|
666
|
+
seconds: number;
|
|
667
|
+
/**
|
|
668
|
+
* - 毫秒数(0-999)
|
|
669
|
+
*/
|
|
670
|
+
milliseconds: number;
|
|
671
|
+
};
|
|
672
|
+
/**
|
|
673
|
+
* 时间持续对象(最大单位为天)
|
|
674
|
+
*/
|
|
675
|
+
type DurationMaxDayObject = {
|
|
676
|
+
/**
|
|
677
|
+
* - 天数
|
|
678
|
+
*/
|
|
679
|
+
days: number;
|
|
680
|
+
/**
|
|
681
|
+
* - 小时数(0-23)
|
|
682
|
+
*/
|
|
683
|
+
hours: number;
|
|
684
|
+
/**
|
|
685
|
+
* - 分钟数(0-59)
|
|
686
|
+
*/
|
|
687
|
+
minutes: number;
|
|
688
|
+
/**
|
|
689
|
+
* - 秒数(0-59)
|
|
690
|
+
*/
|
|
691
|
+
seconds: number;
|
|
692
|
+
/**
|
|
693
|
+
* - 毫秒数(0-999)
|
|
694
|
+
*/
|
|
695
|
+
milliseconds: number;
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* 时间持续对象(最大单位为小时)
|
|
699
|
+
*/
|
|
700
|
+
type DurationMaxHourObject = {
|
|
701
|
+
/**
|
|
702
|
+
* - 小时数
|
|
703
|
+
*/
|
|
704
|
+
hours: number;
|
|
705
|
+
/**
|
|
706
|
+
* - 分钟数(0-59)
|
|
707
|
+
*/
|
|
708
|
+
minutes: number;
|
|
709
|
+
/**
|
|
710
|
+
* - 秒数(0-59)
|
|
711
|
+
*/
|
|
712
|
+
seconds: number;
|
|
713
|
+
/**
|
|
714
|
+
* - 毫秒数(0-999)
|
|
715
|
+
*/
|
|
716
|
+
milliseconds: number;
|
|
717
|
+
};
|
|
521
718
|
|
|
522
719
|
/**
|
|
523
720
|
* 通过动态创建 `<a>` 标签触发浏览器下载。
|
|
@@ -702,4 +899,4 @@ declare function extractFullyCheckedKeys(treeData: any[], selectedKeys: any[], i
|
|
|
702
899
|
};
|
|
703
900
|
declare function findObjAttrValueById<T>(id: string | number, arr: T[], resultKey?: string, idKey?: string, childrenKey?: string): any;
|
|
704
901
|
|
|
705
|
-
export { AudioStreamResampler, IntervalTimer, MyEvent, MyEvent_CrossPagePlugin, MyId, WebSocketManager, assignExisting,
|
|
902
|
+
export { AudioStreamResampler, IntervalTimer, MyEvent, MyEvent_CrossPagePlugin, MyId, WebSocketManager, assignExisting, debounce, deepCloneByJSON, downloadByBlob, downloadByData, downloadByUrl, downloadExcel, downloadJSON, extractFullyCheckedKeys, fetchOrDownloadByUrl, findObjAttrValueById, flatCompleteTree2NestedTree, formatTimeForLocale, getAllSearchParams, getDataType, getFunctionArgNames, getGUID, getSearchParam, getTimePeriodName, getViewportSize, isBlob, isDate, isFunction, isNonEmptyString, isPlainObject, isPromise, millisecond2Duration, millisecond2DurationMaxDay, millisecond2DurationMaxHour, moveItem, nestedTree2IdMap, pcmToWavBlob, randomDateInRange, randomEnLetter, randomHan, randomHanOrEn, randomIntInRange, readBlobAsText, second2Duration, second2DurationMaxDay, second2DurationMaxHour, shuffle, throttle, toDate };
|