@base-web-kits/base-tools-ts 0.9.8 → 0.9.10
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/array/index.d.ts +9 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/async/index.d.ts +14 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/base-tools-ts.umd.global.js +25 -25
- package/dist/base-tools-ts.umd.global.js.map +1 -1
- package/dist/bean/EventBus.d.ts +37 -0
- package/dist/bean/EventBus.d.ts.map +1 -0
- package/dist/bean/index.d.ts +2 -0
- package/dist/bean/index.d.ts.map +1 -0
- package/dist/day/index.d.ts +100 -0
- package/dist/day/index.d.ts.map +1 -0
- package/dist/index.cjs +33 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -1215
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/lodash/index.d.ts +8 -0
- package/dist/lodash/index.d.ts.map +1 -0
- package/dist/number/big.d.ts +137 -0
- package/dist/number/big.d.ts.map +1 -0
- package/dist/number/format.d.ts +88 -0
- package/dist/number/format.d.ts.map +1 -0
- package/dist/number/index.d.ts +4 -0
- package/dist/number/index.d.ts.map +1 -0
- package/dist/number/random.d.ts +33 -0
- package/dist/number/random.d.ts.map +1 -0
- package/dist/object/index.d.ts +11 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/string/format.d.ts +33 -0
- package/dist/string/format.d.ts.map +1 -0
- package/dist/string/index.d.ts +4 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/other.d.ts +15 -0
- package/dist/string/other.d.ts.map +1 -0
- package/dist/string/random.d.ts +27 -0
- package/dist/string/random.d.ts.map +1 -0
- package/dist/typing/index.d.ts +134 -0
- package/dist/typing/index.d.ts.map +1 -0
- package/dist/url/file/index.d.ts +22 -0
- package/dist/url/file/index.d.ts.map +1 -0
- package/dist/url/index.d.ts +5 -0
- package/dist/url/index.d.ts.map +1 -0
- package/dist/url/oss/index.d.ts +77 -0
- package/dist/url/oss/index.d.ts.map +1 -0
- package/dist/url/param/index.d.ts +49 -0
- package/dist/url/param/index.d.ts.map +1 -0
- package/dist/url/qn/index.d.ts +58 -0
- package/dist/url/qn/index.d.ts.map +1 -0
- package/dist/validator/index.d.ts +296 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/ts/day/index.ts +2 -2
- package/src/ts/number/big.ts +41 -41
- package/dist/index.d.cts +0 -1216
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type EventType } from 'mitt';
|
|
2
|
+
type Events = Record<EventType, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* 总线式发布订阅
|
|
5
|
+
* @example
|
|
6
|
+
* const emitter = new EventBus(); // 支持链式调用
|
|
7
|
+
* emitter.on('xx', fn); // 订阅事件 xx
|
|
8
|
+
* emitter.once('xx', fn); // 订阅事件 xx 一次
|
|
9
|
+
* emitter.emit('xx', any); // 发布事件 xx,参数任意
|
|
10
|
+
* emitter.off('xx'); // 移除事件 xx 下全部监听
|
|
11
|
+
* emitter.off('xx', fn); // 移除事件 xx 下指定监听
|
|
12
|
+
* emitter.clear(); // 移除所有事件
|
|
13
|
+
*
|
|
14
|
+
* @example 类型约束
|
|
15
|
+
* type T = { a: number; b: string };
|
|
16
|
+
* const emitter = new EventBus<{ xx: T; yy: void }>();
|
|
17
|
+
* const fn = (arg: T) => {}
|
|
18
|
+
* emitter.on('xx', fn);
|
|
19
|
+
* emitter.off('xx', fn);
|
|
20
|
+
* emitter.emit('xx', { a: 123, b: '123' });
|
|
21
|
+
* emitter.emit('yy');
|
|
22
|
+
*/
|
|
23
|
+
export declare class EventBus<T extends Events = Events> {
|
|
24
|
+
private readonly _emitter;
|
|
25
|
+
/** 订阅 */
|
|
26
|
+
on<K extends keyof T>(type: K, fn: (event: T[K]) => void): this;
|
|
27
|
+
/** 订阅一次 */
|
|
28
|
+
once<K extends keyof T>(type: K, fn: (event: T[K]) => void): this;
|
|
29
|
+
/** 发布 */
|
|
30
|
+
emit<K extends keyof T>(type: K, event?: T[K]): this;
|
|
31
|
+
/** 移除 */
|
|
32
|
+
off<K extends keyof T>(type: K, fn?: (event: T[K]) => void): this;
|
|
33
|
+
/** 清空 */
|
|
34
|
+
clear(): this;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=EventBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.d.ts","sourceRoot":"","sources":["../../src/ts/bean/EventBus.ts"],"names":[],"mappings":"AAAA,OAAa,EAAgB,KAAK,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1D,KAAK,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAElD,SAAS;IACT,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAK/D,WAAW;IACX,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IASjE,SAAS;IACT,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAKpD,SAAS;IACT,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAKjE,SAAS;IACT,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/bean/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import 'dayjs/locale/zh-cn';
|
|
3
|
+
type BaseTime = number | string | Date | dayjs.Dayjs | null | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* 创建 dayjs 实例
|
|
6
|
+
* 文档: https://day.js.org/zh-CN/
|
|
7
|
+
* @param t 各种规范或不规范的时间
|
|
8
|
+
* @returns dayjs 实例
|
|
9
|
+
* @example
|
|
10
|
+
* const d = toDayjs('2021-01-01'); // dayjs 实例 (无参,则默认当前时间)
|
|
11
|
+
* d.format('YYYY-MM-DD HH:mm:ss'); // "2025-12-10 11:33:16"
|
|
12
|
+
* d.valueOf(); // 毫秒时间戳,如 1765337596913
|
|
13
|
+
* d.unix(); // 秒时间戳,如 1765337596
|
|
14
|
+
* d.millisecond(); // 毫秒 913
|
|
15
|
+
* d.second(); // 秒 16
|
|
16
|
+
* d.minute(); // 分 33
|
|
17
|
+
* d.hour(); // 时 11
|
|
18
|
+
* d.date(); // 日 10
|
|
19
|
+
* d.day(); // 星期几 5(周日=0)
|
|
20
|
+
* d.month() + 1; // 月 12
|
|
21
|
+
* d.year(); // 年 2025
|
|
22
|
+
* d.startOf('day').valueOf(); // 当日零点
|
|
23
|
+
* d.startOf('month').format('YYYY-MM-DD HH:mm:ss'); // 月初 "2025-12-01 00:00:00"
|
|
24
|
+
* d.endOf('month').format('YYYY-MM-DD HH:mm:ss'); // 月末 "2025-12-31 23:59:59"
|
|
25
|
+
* d.fromNow(); // “刚刚”、“x分钟前/后”、“x小时前/后”、“x天前/后”、“x月前/后”、“x年前/后”
|
|
26
|
+
* d.isSame(t, 'day'); // 是否与t在同一天
|
|
27
|
+
* d.diff(); // 与当前时间相差的毫秒数
|
|
28
|
+
* d.diff(t); // 与t相差的毫秒数
|
|
29
|
+
* d.diff(t, 'second'); // 与t相差的秒数
|
|
30
|
+
* d.diff(t, 'minute'); // 与t相差的分钟数
|
|
31
|
+
* d.diff(t, 'hour'); // 与t相差的小时数
|
|
32
|
+
* d.diff(t, 'day'); // 与t相差的天数
|
|
33
|
+
* d.diff(t, 'week'); // 与t相差的周数
|
|
34
|
+
* d.diff(t, 'month'); // 与t相差的月数
|
|
35
|
+
* d.diff(t, 'quarter'); // 与t相差的季度数
|
|
36
|
+
* d.diff(t, 'year'); // 与t相差的年数
|
|
37
|
+
*/
|
|
38
|
+
export declare function toDayjs(t?: BaseTime, fmt?: dayjs.OptionType): dayjs.Dayjs;
|
|
39
|
+
/**
|
|
40
|
+
* 获取“前几天”的日期范围
|
|
41
|
+
* @param offset 正整数天数
|
|
42
|
+
* @param fmt 日期格式,默认 `YYYY-MM-DD`
|
|
43
|
+
* @returns `[start, end]` 日期字符串数组
|
|
44
|
+
* @example
|
|
45
|
+
* 若今天为 2025-11-19:
|
|
46
|
+
* getDateRangeBefore(1) // ['2025-11-18', '2025-11-19']
|
|
47
|
+
* getDateRangeBefore(1, 'YYYY-MM-DD HH:mm:ss') // ['2025-11-18 00:00:00', '2025-11-19 23:59:59']
|
|
48
|
+
*/
|
|
49
|
+
export declare function getDateRangeBefore(offset: number, fmt?: string): string[];
|
|
50
|
+
/**
|
|
51
|
+
* 获取“后几天”的日期范围
|
|
52
|
+
* - 起点:今天;终点:`offset` 天后
|
|
53
|
+
* - 若 `fmt` 含时间令牌(如 `HH:mm:ss`),则返回整日范围:起点为当日零点,终点为当日末尾
|
|
54
|
+
* @param offset 正整数天数
|
|
55
|
+
* @param fmt 日期格式,默认 `YYYY-MM-DD`
|
|
56
|
+
* @returns `[start, end]` 日期字符串数组
|
|
57
|
+
* @example
|
|
58
|
+
* 若今天为 2025-11-19:
|
|
59
|
+
* getDateRangeAfter(1) // ['2025-11-19', '2025-11-20']
|
|
60
|
+
* getDateRangeAfter(1, 'YYYY-MM-DD HH:mm:ss') // ['2025-11-19 00:00:00', '2025-11-20 23:59:59']
|
|
61
|
+
*/
|
|
62
|
+
export declare function getDateRangeAfter(offset: number, fmt?: string): string[];
|
|
63
|
+
/**
|
|
64
|
+
* 获取倒计时的时间分解(零填充字符串)
|
|
65
|
+
* @param diff 毫秒差值(正数表示剩余时间,负数/0表示已到期)
|
|
66
|
+
* @returns 包含天、时、分、秒、毫秒的零填充对象
|
|
67
|
+
* @example
|
|
68
|
+
* const diff = toDayjs(t).diff(); // 毫秒差值
|
|
69
|
+
* const parts = getCountdownParts(diff); // { d: '01', h: '02', m: '03', s: '04', ms: '567' }
|
|
70
|
+
*/
|
|
71
|
+
export declare function getCountdownParts(diff: number): {
|
|
72
|
+
d: string;
|
|
73
|
+
h: string;
|
|
74
|
+
m: string;
|
|
75
|
+
s: string;
|
|
76
|
+
ms: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 通过出生日期计算年龄
|
|
80
|
+
* @param birthdate 生日日期,支持多种格式(会被自动解析)
|
|
81
|
+
* @returns 年龄对象,包含 `age`(年龄数值)和 `type`(年龄单位,'year' 表示年,'month' 表示月)
|
|
82
|
+
* @example
|
|
83
|
+
* // 假设当前日期为 2025-11-19
|
|
84
|
+
* getAgeByBirthdate('2025-05-10'); // { age: 6, type: 'month' }
|
|
85
|
+
* getAgeByBirthdate('2020-11-19'); // { age: 5, type: 'year' }
|
|
86
|
+
* getAgeByBirthdate('2020-12-01'); // { age: 4, type: 'year' }(生日还没到, 所以年龄是4岁)
|
|
87
|
+
*/
|
|
88
|
+
export declare function getAgeByBirthdate(birthdate: string): {
|
|
89
|
+
age: number;
|
|
90
|
+
type: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* 对外抛出 dayjs 以便全局配置
|
|
94
|
+
* @example
|
|
95
|
+
* 切换语言
|
|
96
|
+
* dayjs.locale('en'); // 切换为英文
|
|
97
|
+
* dayjs.locale('zh-cn'); // 切换为中文 (默认)
|
|
98
|
+
*/
|
|
99
|
+
export { dayjs };
|
|
100
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/day/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,oBAAoB,CAAC;AAU5B,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,UAAU,eAmB3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAe,YASpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAe,YASnE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM;;;;;;EAgB7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM;;;EAqBlD;AAED;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -45,18 +45,19 @@ __export(index_exports, {
|
|
|
45
45
|
attempt: () => attempt_default,
|
|
46
46
|
before: () => before_default,
|
|
47
47
|
big: () => big,
|
|
48
|
-
bigAdd: () => bigAdd,
|
|
49
48
|
bigCompare: () => bigCompare,
|
|
50
49
|
bigDiv: () => bigDiv,
|
|
51
50
|
bigEqual: () => bigEqual,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
bigFixed: () => bigFixed,
|
|
52
|
+
bigGreaterThan: () => bigGreaterThan,
|
|
53
|
+
bigGreaterThanOrEqualTo: () => bigGreaterThanOrEqualTo,
|
|
54
|
+
bigLessThan: () => bigLessThan,
|
|
55
|
+
bigLessThanOrEqual: () => bigLessThanOrEqual,
|
|
56
|
+
bigMinus: () => bigMinus,
|
|
57
|
+
bigPlus: () => bigPlus,
|
|
57
58
|
bigPow: () => bigPow,
|
|
58
59
|
bigRound: () => bigRound,
|
|
59
|
-
|
|
60
|
+
bigTimes: () => bigTimes,
|
|
60
61
|
bind: () => bind_default,
|
|
61
62
|
bindAll: () => bindAll_default,
|
|
62
63
|
bindKey: () => bindKey_default,
|
|
@@ -370,7 +371,6 @@ __export(index_exports, {
|
|
|
370
371
|
toChineseNum: () => toChineseNum,
|
|
371
372
|
toDayjs: () => toDayjs,
|
|
372
373
|
toFinite: () => toFinite_default,
|
|
373
|
-
toFixed: () => toFixed,
|
|
374
374
|
toInteger: () => toInteger_default,
|
|
375
375
|
toIterator: () => toIterator_default,
|
|
376
376
|
toJSON: () => wrapperValue_default,
|
|
@@ -506,24 +506,24 @@ var import_bignumber = __toESM(require("bignumber.js"), 1);
|
|
|
506
506
|
function big(x) {
|
|
507
507
|
return x instanceof import_bignumber.default ? x : new import_bignumber.default(x);
|
|
508
508
|
}
|
|
509
|
-
function
|
|
510
|
-
let acc = big(
|
|
511
|
-
for (const x of rest2) acc = acc.plus(big(x));
|
|
509
|
+
function bigPlus(...rest2) {
|
|
510
|
+
let acc = big(rest2[0]);
|
|
511
|
+
for (const x of rest2.slice(1)) acc = acc.plus(big(x));
|
|
512
512
|
return acc.toNumber();
|
|
513
513
|
}
|
|
514
|
-
function
|
|
515
|
-
let acc = big(
|
|
516
|
-
for (const x of rest2) acc = acc.minus(big(x));
|
|
514
|
+
function bigMinus(...rest2) {
|
|
515
|
+
let acc = big(rest2[0]);
|
|
516
|
+
for (const x of rest2.slice(1)) acc = acc.minus(big(x));
|
|
517
517
|
return acc.toNumber();
|
|
518
518
|
}
|
|
519
|
-
function
|
|
520
|
-
let acc = big(
|
|
521
|
-
for (const x of rest2) acc = acc.times(big(x));
|
|
519
|
+
function bigTimes(...rest2) {
|
|
520
|
+
let acc = big(rest2[0]);
|
|
521
|
+
for (const x of rest2.slice(1)) acc = acc.times(big(x));
|
|
522
522
|
return acc.toNumber();
|
|
523
523
|
}
|
|
524
|
-
function bigDiv(
|
|
525
|
-
let acc = big(
|
|
526
|
-
for (const x of rest2) acc = acc.div(big(x));
|
|
524
|
+
function bigDiv(...rest2) {
|
|
525
|
+
let acc = big(rest2[0]);
|
|
526
|
+
for (const x of rest2.slice(1)) acc = acc.div(big(x));
|
|
527
527
|
return acc.toNumber();
|
|
528
528
|
}
|
|
529
529
|
function bigPow(x, y) {
|
|
@@ -532,7 +532,7 @@ function bigPow(x, y) {
|
|
|
532
532
|
function bigRound(x, dp = 0, rm = import_bignumber.default.ROUND_HALF_UP) {
|
|
533
533
|
return big(x).decimalPlaces(dp, rm).toNumber();
|
|
534
534
|
}
|
|
535
|
-
function
|
|
535
|
+
function bigFixed(x, dp = 2, rm = import_bignumber.default.ROUND_HALF_UP) {
|
|
536
536
|
return big(x).toFixed(dp, rm);
|
|
537
537
|
}
|
|
538
538
|
function bigCompare(a, b) {
|
|
@@ -541,16 +541,16 @@ function bigCompare(a, b) {
|
|
|
541
541
|
function bigEqual(a, b) {
|
|
542
542
|
return big(a).isEqualTo(big(b));
|
|
543
543
|
}
|
|
544
|
-
function
|
|
544
|
+
function bigGreaterThan(a, b) {
|
|
545
545
|
return big(a).isGreaterThan(big(b));
|
|
546
546
|
}
|
|
547
|
-
function
|
|
547
|
+
function bigGreaterThanOrEqualTo(a, b) {
|
|
548
548
|
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
549
549
|
}
|
|
550
|
-
function
|
|
550
|
+
function bigLessThan(a, b) {
|
|
551
551
|
return big(a).isLessThan(big(b));
|
|
552
552
|
}
|
|
553
|
-
function
|
|
553
|
+
function bigLessThanOrEqual(a, b) {
|
|
554
554
|
return big(a).isLessThanOrEqualTo(big(b));
|
|
555
555
|
}
|
|
556
556
|
|
|
@@ -8581,18 +8581,19 @@ function isLongitude(s) {
|
|
|
8581
8581
|
attempt,
|
|
8582
8582
|
before,
|
|
8583
8583
|
big,
|
|
8584
|
-
bigAdd,
|
|
8585
8584
|
bigCompare,
|
|
8586
8585
|
bigDiv,
|
|
8587
8586
|
bigEqual,
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
8592
|
-
|
|
8587
|
+
bigFixed,
|
|
8588
|
+
bigGreaterThan,
|
|
8589
|
+
bigGreaterThanOrEqualTo,
|
|
8590
|
+
bigLessThan,
|
|
8591
|
+
bigLessThanOrEqual,
|
|
8592
|
+
bigMinus,
|
|
8593
|
+
bigPlus,
|
|
8593
8594
|
bigPow,
|
|
8594
8595
|
bigRound,
|
|
8595
|
-
|
|
8596
|
+
bigTimes,
|
|
8596
8597
|
bind,
|
|
8597
8598
|
bindAll,
|
|
8598
8599
|
bindKey,
|
|
@@ -8906,7 +8907,6 @@ function isLongitude(s) {
|
|
|
8906
8907
|
toChineseNum,
|
|
8907
8908
|
toDayjs,
|
|
8908
8909
|
toFinite,
|
|
8909
|
-
toFixed,
|
|
8910
8910
|
toInteger,
|
|
8911
8911
|
toIterator,
|
|
8912
8912
|
toJSON,
|