@base-web-kits/base-tools-ts 0.9.9 → 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/base-tools-ts.umd.global.js +25 -25
- package/dist/base-tools-ts.umd.global.js.map +1 -1
- package/dist/day/index.d.ts +2 -2
- package/dist/day/index.d.ts.map +1 -1
- package/dist/index.cjs +33 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/number/big.d.ts +33 -33
- package/dist/number/big.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ts/day/index.ts +2 -2
- package/src/ts/number/big.ts +41 -41
package/dist/number/big.d.ts
CHANGED
|
@@ -16,27 +16,27 @@ export declare function big(x: NumLike): BigNumber;
|
|
|
16
16
|
/**
|
|
17
17
|
* 高精度加法(支持多个参数连加)。
|
|
18
18
|
* @example
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* bigPlus(0.1, 0.2); // => 0.3
|
|
20
|
+
* bigPlus('0.1', '0.2'); // => 0.3
|
|
21
|
+
* bigPlus(1, 2, 3, 4); // => 10 // 多参数连加: 1+2+3+4
|
|
22
22
|
*/
|
|
23
|
-
export declare function
|
|
23
|
+
export declare function bigPlus(...rest: NumLike[]): number;
|
|
24
24
|
/**
|
|
25
25
|
* 高精度减法(支持多个参数连减)。
|
|
26
26
|
* @example
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* bigMinus(1, 0.9); // => 0.1
|
|
28
|
+
* bigMinus('1.1', '0.2'); // => 0.9
|
|
29
|
+
* bigMinus(10, 1, 2, 3); // => 4 // 多参数连减: 10-1-2-3
|
|
30
30
|
*/
|
|
31
|
-
export declare function
|
|
31
|
+
export declare function bigMinus(...rest: NumLike[]): number;
|
|
32
32
|
/**
|
|
33
33
|
* 高精度乘法(支持多个参数连乘)。
|
|
34
34
|
* @example
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* bigTimes(0.1, 0.2); // => 0.02
|
|
36
|
+
* bigTimes('1.5', '3'); // => 4.5
|
|
37
|
+
* bigTimes(2, 3, 4); // => 24 // 多参数连乘: 2*3*4
|
|
38
38
|
*/
|
|
39
|
-
export declare function
|
|
39
|
+
export declare function bigTimes(...rest: NumLike[]): number;
|
|
40
40
|
/**
|
|
41
41
|
* 高精度除法(支持多个参数连除)。
|
|
42
42
|
* @example
|
|
@@ -44,7 +44,7 @@ export declare function bigMul(a: NumLike, ...rest: NumLike[]): number;
|
|
|
44
44
|
* bigDiv('10', '4'); // => 2.5
|
|
45
45
|
* bigDiv(100, 5, 2); // => 10 // 多参数连除: 100/5/2
|
|
46
46
|
*/
|
|
47
|
-
export declare function bigDiv(
|
|
47
|
+
export declare function bigDiv(...rest: NumLike[]): number;
|
|
48
48
|
/**
|
|
49
49
|
* 指数运算
|
|
50
50
|
* @param x 底数。
|
|
@@ -56,7 +56,7 @@ export declare function bigDiv(a: NumLike, ...rest: NumLike[]): number;
|
|
|
56
56
|
*/
|
|
57
57
|
export declare function bigPow(x: NumLike, y: NumLike): number;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* 四舍五入到指定小数位数
|
|
60
60
|
* @param x 需要舍入的数值。
|
|
61
61
|
* @param dp 保留的小数位数,默认 `0`(取整)。
|
|
62
62
|
* @param rm 舍入模式,默认 `ROUND_HALF_UP`(四舍五入)。
|
|
@@ -75,13 +75,13 @@ export declare function bigRound(x: NumLike, dp?: number, rm?: BigNumber.Roundin
|
|
|
75
75
|
* @param rm 舍入模式,默认 `ROUND_HALF_UP`(四舍五入)。
|
|
76
76
|
* @returns 格式化后的字符串。
|
|
77
77
|
* @example
|
|
78
|
-
*
|
|
79
|
-
* +
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
78
|
+
* bigFixed('1'); // => '1.00'
|
|
79
|
+
* +bigFixed('1'); // => 1
|
|
80
|
+
* bigFixed(1.2345); // => '1.23'
|
|
81
|
+
* bigFixed(1.2345, 3); // => '1.235'
|
|
82
|
+
* bigFixed('1.2345', 0, BigNumber.ROUND_UP); // => '2'
|
|
83
83
|
*/
|
|
84
|
-
export declare function
|
|
84
|
+
export declare function bigFixed(x: NumLike, dp?: number, rm?: BigNumber.RoundingMode): string;
|
|
85
85
|
/**
|
|
86
86
|
* 比较两个数值大小。
|
|
87
87
|
* @example
|
|
@@ -100,32 +100,32 @@ export declare function bigEqual(a: NumLike, b: NumLike): boolean;
|
|
|
100
100
|
/**
|
|
101
101
|
* 判断 a 是否大于 b。
|
|
102
102
|
* @example
|
|
103
|
-
*
|
|
104
|
-
*
|
|
103
|
+
* bigGreaterThan(2, 1); // => true
|
|
104
|
+
* bigGreaterThan(1, 2); // => false
|
|
105
105
|
*/
|
|
106
|
-
export declare function
|
|
106
|
+
export declare function bigGreaterThan(a: NumLike, b: NumLike): boolean;
|
|
107
107
|
/**
|
|
108
108
|
* 判断 a 是否大于等于 b。
|
|
109
109
|
* @example
|
|
110
|
-
*
|
|
111
|
-
*
|
|
110
|
+
* bigGreaterThanOrEqual(2, 2); // => true
|
|
111
|
+
* bigGreaterThanOrEqual(1, 2); // => false
|
|
112
112
|
*/
|
|
113
|
-
export declare function
|
|
113
|
+
export declare function bigGreaterThanOrEqualTo(a: NumLike, b: NumLike): boolean;
|
|
114
114
|
/**
|
|
115
115
|
* 判断 a 是否小于 b。
|
|
116
116
|
* @example
|
|
117
|
-
*
|
|
118
|
-
*
|
|
117
|
+
* bigLessThan(1, 2); // => true
|
|
118
|
+
* bigLessThan(2, 1); // => false
|
|
119
119
|
*/
|
|
120
|
-
export declare function
|
|
120
|
+
export declare function bigLessThan(a: NumLike, b: NumLike): boolean;
|
|
121
121
|
/**
|
|
122
122
|
* 判断 a 是否小于等于 b。
|
|
123
123
|
* @example
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
124
|
+
* bigLessThanOrEqual(2, 2); // => true
|
|
125
|
+
* bigLessThanOrEqual(1, 2); // => true
|
|
126
|
+
* bigLessThanOrEqual(2, 1); // => false
|
|
127
127
|
*/
|
|
128
|
-
export declare function
|
|
128
|
+
export declare function bigLessThanOrEqual(a: NumLike, b: NumLike): boolean;
|
|
129
129
|
/**
|
|
130
130
|
* 导出 BigNumber 类
|
|
131
131
|
* @example
|
package/dist/number/big.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"big.d.ts","sourceRoot":"","sources":["../../src/ts/number/big.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAElD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"big.d.ts","sourceRoot":"","sources":["../../src/ts/number/big.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAElD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,UAIzC;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,UAI1C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,UAI1C;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,UAIxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,UAE5C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,SAAI,EAAE,EAAE,GAAE,SAAS,CAAC,YAAsC,UAEhG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,OAAO,EACV,EAAE,SAAI,EACN,EAAE,GAAE,SAAS,CAAC,YAAsC,GACnD,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAElE;AAED;;;;;;GAMG;AACH,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/ts/day/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ type BaseTime = number | string | Date | dayjs.Dayjs | null | undefined;
|
|
|
22
22
|
* @param t 各种规范或不规范的时间
|
|
23
23
|
* @returns dayjs 实例
|
|
24
24
|
* @example
|
|
25
|
-
* const d = toDayjs('2021-01-01'); // dayjs 实例
|
|
25
|
+
* const d = toDayjs('2021-01-01'); // dayjs 实例 (无参,则默认当前时间)
|
|
26
26
|
* d.format('YYYY-MM-DD HH:mm:ss'); // "2025-12-10 11:33:16"
|
|
27
27
|
* d.valueOf(); // 毫秒时间戳,如 1765337596913
|
|
28
28
|
* d.unix(); // 秒时间戳,如 1765337596
|
|
@@ -50,7 +50,7 @@ type BaseTime = number | string | Date | dayjs.Dayjs | null | undefined;
|
|
|
50
50
|
* d.diff(t, 'quarter'); // 与t相差的季度数
|
|
51
51
|
* d.diff(t, 'year'); // 与t相差的年数
|
|
52
52
|
*/
|
|
53
|
-
export function toDayjs(t
|
|
53
|
+
export function toDayjs(t?: BaseTime, fmt?: dayjs.OptionType) {
|
|
54
54
|
if (t === null || t === undefined) return dayjs();
|
|
55
55
|
if (typeof t === 'number') {
|
|
56
56
|
const s = String(Math.trunc(t));
|
package/src/ts/number/big.ts
CHANGED
|
@@ -21,39 +21,39 @@ export function big(x: NumLike): BigNumber {
|
|
|
21
21
|
/**
|
|
22
22
|
* 高精度加法(支持多个参数连加)。
|
|
23
23
|
* @example
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* bigPlus(0.1, 0.2); // => 0.3
|
|
25
|
+
* bigPlus('0.1', '0.2'); // => 0.3
|
|
26
|
+
* bigPlus(1, 2, 3, 4); // => 10 // 多参数连加: 1+2+3+4
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
29
|
-
let acc = big(
|
|
30
|
-
for (const x of rest) acc = acc.plus(big(x));
|
|
28
|
+
export function bigPlus(...rest: NumLike[]) {
|
|
29
|
+
let acc = big(rest[0]);
|
|
30
|
+
for (const x of rest.slice(1)) acc = acc.plus(big(x));
|
|
31
31
|
return acc.toNumber();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* 高精度减法(支持多个参数连减)。
|
|
36
36
|
* @example
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* bigMinus(1, 0.9); // => 0.1
|
|
38
|
+
* bigMinus('1.1', '0.2'); // => 0.9
|
|
39
|
+
* bigMinus(10, 1, 2, 3); // => 4 // 多参数连减: 10-1-2-3
|
|
40
40
|
*/
|
|
41
|
-
export function
|
|
42
|
-
let acc = big(
|
|
43
|
-
for (const x of rest) acc = acc.minus(big(x));
|
|
41
|
+
export function bigMinus(...rest: NumLike[]) {
|
|
42
|
+
let acc = big(rest[0]);
|
|
43
|
+
for (const x of rest.slice(1)) acc = acc.minus(big(x));
|
|
44
44
|
return acc.toNumber();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* 高精度乘法(支持多个参数连乘)。
|
|
49
49
|
* @example
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* bigTimes(0.1, 0.2); // => 0.02
|
|
51
|
+
* bigTimes('1.5', '3'); // => 4.5
|
|
52
|
+
* bigTimes(2, 3, 4); // => 24 // 多参数连乘: 2*3*4
|
|
53
53
|
*/
|
|
54
|
-
export function
|
|
55
|
-
let acc = big(
|
|
56
|
-
for (const x of rest) acc = acc.times(big(x));
|
|
54
|
+
export function bigTimes(...rest: NumLike[]) {
|
|
55
|
+
let acc = big(rest[0]);
|
|
56
|
+
for (const x of rest.slice(1)) acc = acc.times(big(x));
|
|
57
57
|
return acc.toNumber();
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -64,9 +64,9 @@ export function bigMul(a: NumLike, ...rest: NumLike[]) {
|
|
|
64
64
|
* bigDiv('10', '4'); // => 2.5
|
|
65
65
|
* bigDiv(100, 5, 2); // => 10 // 多参数连除: 100/5/2
|
|
66
66
|
*/
|
|
67
|
-
export function bigDiv(
|
|
68
|
-
let acc = big(
|
|
69
|
-
for (const x of rest) acc = acc.div(big(x));
|
|
67
|
+
export function bigDiv(...rest: NumLike[]) {
|
|
68
|
+
let acc = big(rest[0]);
|
|
69
|
+
for (const x of rest.slice(1)) acc = acc.div(big(x));
|
|
70
70
|
return acc.toNumber();
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -84,7 +84,7 @@ export function bigPow(x: NumLike, y: NumLike) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* 四舍五入到指定小数位数
|
|
88
88
|
* @param x 需要舍入的数值。
|
|
89
89
|
* @param dp 保留的小数位数,默认 `0`(取整)。
|
|
90
90
|
* @param rm 舍入模式,默认 `ROUND_HALF_UP`(四舍五入)。
|
|
@@ -106,13 +106,13 @@ export function bigRound(x: NumLike, dp = 0, rm: BigNumber.RoundingMode = BigNum
|
|
|
106
106
|
* @param rm 舍入模式,默认 `ROUND_HALF_UP`(四舍五入)。
|
|
107
107
|
* @returns 格式化后的字符串。
|
|
108
108
|
* @example
|
|
109
|
-
*
|
|
110
|
-
* +
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
109
|
+
* bigFixed('1'); // => '1.00'
|
|
110
|
+
* +bigFixed('1'); // => 1
|
|
111
|
+
* bigFixed(1.2345); // => '1.23'
|
|
112
|
+
* bigFixed(1.2345, 3); // => '1.235'
|
|
113
|
+
* bigFixed('1.2345', 0, BigNumber.ROUND_UP); // => '2'
|
|
114
114
|
*/
|
|
115
|
-
export function
|
|
115
|
+
export function bigFixed(
|
|
116
116
|
x: NumLike,
|
|
117
117
|
dp = 2,
|
|
118
118
|
rm: BigNumber.RoundingMode = BigNumber.ROUND_HALF_UP,
|
|
@@ -144,41 +144,41 @@ export function bigEqual(a: NumLike, b: NumLike): boolean {
|
|
|
144
144
|
/**
|
|
145
145
|
* 判断 a 是否大于 b。
|
|
146
146
|
* @example
|
|
147
|
-
*
|
|
148
|
-
*
|
|
147
|
+
* bigGreaterThan(2, 1); // => true
|
|
148
|
+
* bigGreaterThan(1, 2); // => false
|
|
149
149
|
*/
|
|
150
|
-
export function
|
|
150
|
+
export function bigGreaterThan(a: NumLike, b: NumLike): boolean {
|
|
151
151
|
return big(a).isGreaterThan(big(b));
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* 判断 a 是否大于等于 b。
|
|
156
156
|
* @example
|
|
157
|
-
*
|
|
158
|
-
*
|
|
157
|
+
* bigGreaterThanOrEqual(2, 2); // => true
|
|
158
|
+
* bigGreaterThanOrEqual(1, 2); // => false
|
|
159
159
|
*/
|
|
160
|
-
export function
|
|
160
|
+
export function bigGreaterThanOrEqualTo(a: NumLike, b: NumLike): boolean {
|
|
161
161
|
return big(a).isGreaterThanOrEqualTo(big(b));
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
165
165
|
* 判断 a 是否小于 b。
|
|
166
166
|
* @example
|
|
167
|
-
*
|
|
168
|
-
*
|
|
167
|
+
* bigLessThan(1, 2); // => true
|
|
168
|
+
* bigLessThan(2, 1); // => false
|
|
169
169
|
*/
|
|
170
|
-
export function
|
|
170
|
+
export function bigLessThan(a: NumLike, b: NumLike): boolean {
|
|
171
171
|
return big(a).isLessThan(big(b));
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
175
|
* 判断 a 是否小于等于 b。
|
|
176
176
|
* @example
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
177
|
+
* bigLessThanOrEqual(2, 2); // => true
|
|
178
|
+
* bigLessThanOrEqual(1, 2); // => true
|
|
179
|
+
* bigLessThanOrEqual(2, 1); // => false
|
|
180
180
|
*/
|
|
181
|
-
export function
|
|
181
|
+
export function bigLessThanOrEqual(a: NumLike, b: NumLike): boolean {
|
|
182
182
|
return big(a).isLessThanOrEqualTo(big(b));
|
|
183
183
|
}
|
|
184
184
|
|