@sybz-components/utils 0.0.5 → 0.0.6
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.cjs +33 -14
- package/dist/base.d.cts +555 -1
- package/dist/base.d.mts +555 -1
- package/dist/base.d.ts +555 -1
- package/dist/base.mjs +6 -60
- package/dist/day.cjs +38 -13
- package/dist/day.d.cts +81 -1
- package/dist/day.d.mts +81 -1
- package/dist/day.d.ts +81 -1
- package/dist/day.mjs +28 -21
- package/dist/format.cjs +17 -14
- package/dist/format.d.cts +208 -1
- package/dist/format.d.mts +208 -1
- package/dist/format.d.ts +208 -1
- package/dist/format.mjs +6 -27
- package/dist/index.cjs +75 -14
- package/dist/index.d.cts +10 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +11 -101
- package/dist/is.cjs +63 -13
- package/dist/is.d.cts +248 -1
- package/dist/is.d.mts +248 -1
- package/dist/is.d.ts +248 -1
- package/dist/is.mjs +41 -38
- package/dist/shared/utils.DrwfWQ1C.cjs +957 -0
- package/dist/shared/utils.SMYVKGgi.mjs +923 -0
- package/dist/test.cjs +5 -14
- package/dist/test.d.cts +14 -1
- package/dist/test.d.mts +14 -1
- package/dist/test.d.ts +14 -1
- package/dist/test.mjs +4 -17
- package/dist/ws.cjs +171 -12
- package/dist/ws.d.cts +165 -1
- package/dist/ws.d.mts +165 -1
- package/dist/ws.d.ts +165 -1
- package/dist/ws.mjs +165 -14
- package/package.json +1 -1
package/dist/day.d.cts
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConfigType, QUnitType, OpUnitType } from 'dayjs';
|
|
2
|
+
|
|
3
|
+
type DayUnit = QUnitType | OpUnitType;
|
|
4
|
+
/**
|
|
5
|
+
* 使用 `dayjs` 格式化日期。
|
|
6
|
+
*
|
|
7
|
+
* @param date 要格式化的日期值。为空时默认使用当前时间。
|
|
8
|
+
* @param format 输出格式,默认 `YYYY-MM-DD HH:mm:ss`。
|
|
9
|
+
* @returns 格式化后的日期字符串。
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* formatDate('2026-04-24 12:30:45')
|
|
13
|
+
* // => '2026-04-24 12:30:45'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* formatDate('2026-04-24 12:30:45', 'YYYY/MM/DD')
|
|
17
|
+
* // => '2026/04/24'
|
|
18
|
+
*/
|
|
19
|
+
declare function formatDate(date?: ConfigType, format?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 将日期格式化为 `YYYY-MM-DD`。
|
|
22
|
+
*
|
|
23
|
+
* @param date 要格式化的日期值。
|
|
24
|
+
* @returns 形如 `2026-04-24` 的字符串。
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* formatDateToDay(new Date())
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* formatDateToDay('2026-04-24 12:30:45')
|
|
31
|
+
* // => '2026-04-24'
|
|
32
|
+
*/
|
|
33
|
+
declare const formatDateToDay: (date: ConfigType) => string;
|
|
34
|
+
/**
|
|
35
|
+
* 将日期格式化为 `YYYY-MM-DD HH:mm`。
|
|
36
|
+
*
|
|
37
|
+
* @param date 要格式化的日期值。
|
|
38
|
+
* @returns 形如 `2026-04-24 12:30` 的字符串。
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* formatDateToMinute(new Date())
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* formatDateToMinute('2026-04-24 12:30:45')
|
|
45
|
+
* // => '2026-04-24 12:30'
|
|
46
|
+
*/
|
|
47
|
+
declare const formatDateToMinute: (date: ConfigType) => string;
|
|
48
|
+
/**
|
|
49
|
+
* 计算两个日期之间的差值。
|
|
50
|
+
*
|
|
51
|
+
* @param date1 起始时间。未传时返回 `undefined`。
|
|
52
|
+
* @param date2 对比时间,默认取当前时间。
|
|
53
|
+
* @param format 差值单位,默认 `second`。
|
|
54
|
+
* @returns 两个时间的差值。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* diffDate('2026-04-24 12:00:00', '2026-04-24 11:59:00')
|
|
58
|
+
* // => 60
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* diffDate('2026-04-24 12:00:00', '2026-04-24 11:30:00', 'minute')
|
|
62
|
+
* // => 30
|
|
63
|
+
*/
|
|
64
|
+
declare function diffDate(date1: ConfigType, date2?: ConfigType, format?: DayUnit): number | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* 将秒数转换成“几秒前 / 几分钟前 / 几小时前 / 几天前”这类相对时间文案。
|
|
67
|
+
*
|
|
68
|
+
* @param second 距离当前时间的秒数。
|
|
69
|
+
* @returns 中文相对时间描述。
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* diffDateFromCurrent(45)
|
|
73
|
+
* // => '45秒前'
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* diffDateFromCurrent(3600)
|
|
77
|
+
* // => '1小时前'
|
|
78
|
+
*/
|
|
79
|
+
declare function diffDateFromCurrent(second: number): string;
|
|
80
|
+
|
|
81
|
+
export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute };
|
package/dist/day.d.mts
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConfigType, QUnitType, OpUnitType } from 'dayjs';
|
|
2
|
+
|
|
3
|
+
type DayUnit = QUnitType | OpUnitType;
|
|
4
|
+
/**
|
|
5
|
+
* 使用 `dayjs` 格式化日期。
|
|
6
|
+
*
|
|
7
|
+
* @param date 要格式化的日期值。为空时默认使用当前时间。
|
|
8
|
+
* @param format 输出格式,默认 `YYYY-MM-DD HH:mm:ss`。
|
|
9
|
+
* @returns 格式化后的日期字符串。
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* formatDate('2026-04-24 12:30:45')
|
|
13
|
+
* // => '2026-04-24 12:30:45'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* formatDate('2026-04-24 12:30:45', 'YYYY/MM/DD')
|
|
17
|
+
* // => '2026/04/24'
|
|
18
|
+
*/
|
|
19
|
+
declare function formatDate(date?: ConfigType, format?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 将日期格式化为 `YYYY-MM-DD`。
|
|
22
|
+
*
|
|
23
|
+
* @param date 要格式化的日期值。
|
|
24
|
+
* @returns 形如 `2026-04-24` 的字符串。
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* formatDateToDay(new Date())
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* formatDateToDay('2026-04-24 12:30:45')
|
|
31
|
+
* // => '2026-04-24'
|
|
32
|
+
*/
|
|
33
|
+
declare const formatDateToDay: (date: ConfigType) => string;
|
|
34
|
+
/**
|
|
35
|
+
* 将日期格式化为 `YYYY-MM-DD HH:mm`。
|
|
36
|
+
*
|
|
37
|
+
* @param date 要格式化的日期值。
|
|
38
|
+
* @returns 形如 `2026-04-24 12:30` 的字符串。
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* formatDateToMinute(new Date())
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* formatDateToMinute('2026-04-24 12:30:45')
|
|
45
|
+
* // => '2026-04-24 12:30'
|
|
46
|
+
*/
|
|
47
|
+
declare const formatDateToMinute: (date: ConfigType) => string;
|
|
48
|
+
/**
|
|
49
|
+
* 计算两个日期之间的差值。
|
|
50
|
+
*
|
|
51
|
+
* @param date1 起始时间。未传时返回 `undefined`。
|
|
52
|
+
* @param date2 对比时间,默认取当前时间。
|
|
53
|
+
* @param format 差值单位,默认 `second`。
|
|
54
|
+
* @returns 两个时间的差值。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* diffDate('2026-04-24 12:00:00', '2026-04-24 11:59:00')
|
|
58
|
+
* // => 60
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* diffDate('2026-04-24 12:00:00', '2026-04-24 11:30:00', 'minute')
|
|
62
|
+
* // => 30
|
|
63
|
+
*/
|
|
64
|
+
declare function diffDate(date1: ConfigType, date2?: ConfigType, format?: DayUnit): number | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* 将秒数转换成“几秒前 / 几分钟前 / 几小时前 / 几天前”这类相对时间文案。
|
|
67
|
+
*
|
|
68
|
+
* @param second 距离当前时间的秒数。
|
|
69
|
+
* @returns 中文相对时间描述。
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* diffDateFromCurrent(45)
|
|
73
|
+
* // => '45秒前'
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* diffDateFromCurrent(3600)
|
|
77
|
+
* // => '1小时前'
|
|
78
|
+
*/
|
|
79
|
+
declare function diffDateFromCurrent(second: number): string;
|
|
80
|
+
|
|
81
|
+
export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute };
|
package/dist/day.d.ts
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConfigType, QUnitType, OpUnitType } from 'dayjs';
|
|
2
|
+
|
|
3
|
+
type DayUnit = QUnitType | OpUnitType;
|
|
4
|
+
/**
|
|
5
|
+
* 使用 `dayjs` 格式化日期。
|
|
6
|
+
*
|
|
7
|
+
* @param date 要格式化的日期值。为空时默认使用当前时间。
|
|
8
|
+
* @param format 输出格式,默认 `YYYY-MM-DD HH:mm:ss`。
|
|
9
|
+
* @returns 格式化后的日期字符串。
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* formatDate('2026-04-24 12:30:45')
|
|
13
|
+
* // => '2026-04-24 12:30:45'
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* formatDate('2026-04-24 12:30:45', 'YYYY/MM/DD')
|
|
17
|
+
* // => '2026/04/24'
|
|
18
|
+
*/
|
|
19
|
+
declare function formatDate(date?: ConfigType, format?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 将日期格式化为 `YYYY-MM-DD`。
|
|
22
|
+
*
|
|
23
|
+
* @param date 要格式化的日期值。
|
|
24
|
+
* @returns 形如 `2026-04-24` 的字符串。
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* formatDateToDay(new Date())
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* formatDateToDay('2026-04-24 12:30:45')
|
|
31
|
+
* // => '2026-04-24'
|
|
32
|
+
*/
|
|
33
|
+
declare const formatDateToDay: (date: ConfigType) => string;
|
|
34
|
+
/**
|
|
35
|
+
* 将日期格式化为 `YYYY-MM-DD HH:mm`。
|
|
36
|
+
*
|
|
37
|
+
* @param date 要格式化的日期值。
|
|
38
|
+
* @returns 形如 `2026-04-24 12:30` 的字符串。
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* formatDateToMinute(new Date())
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* formatDateToMinute('2026-04-24 12:30:45')
|
|
45
|
+
* // => '2026-04-24 12:30'
|
|
46
|
+
*/
|
|
47
|
+
declare const formatDateToMinute: (date: ConfigType) => string;
|
|
48
|
+
/**
|
|
49
|
+
* 计算两个日期之间的差值。
|
|
50
|
+
*
|
|
51
|
+
* @param date1 起始时间。未传时返回 `undefined`。
|
|
52
|
+
* @param date2 对比时间,默认取当前时间。
|
|
53
|
+
* @param format 差值单位,默认 `second`。
|
|
54
|
+
* @returns 两个时间的差值。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* diffDate('2026-04-24 12:00:00', '2026-04-24 11:59:00')
|
|
58
|
+
* // => 60
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* diffDate('2026-04-24 12:00:00', '2026-04-24 11:30:00', 'minute')
|
|
62
|
+
* // => 30
|
|
63
|
+
*/
|
|
64
|
+
declare function diffDate(date1: ConfigType, date2?: ConfigType, format?: DayUnit): number | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* 将秒数转换成“几秒前 / 几分钟前 / 几小时前 / 几天前”这类相对时间文案。
|
|
67
|
+
*
|
|
68
|
+
* @param second 距离当前时间的秒数。
|
|
69
|
+
* @returns 中文相对时间描述。
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* diffDateFromCurrent(45)
|
|
73
|
+
* // => '45秒前'
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* diffDateFromCurrent(3600)
|
|
77
|
+
* // => '1小时前'
|
|
78
|
+
*/
|
|
79
|
+
declare function diffDateFromCurrent(second: number): string;
|
|
80
|
+
|
|
81
|
+
export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute };
|
package/dist/day.mjs
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
function formatDate(date, format = "YYYY-MM-DD HH:mm:ss") {
|
|
4
|
+
return dayjs(date || /* @__PURE__ */ new Date()).format(format);
|
|
5
|
+
}
|
|
6
|
+
const formatDateToDay = (date) => formatDate(date, "YYYY-MM-DD");
|
|
7
|
+
const formatDateToMinute = (date) => formatDate(date, "YYYY-MM-DD HH:mm");
|
|
8
|
+
function diffDate(date1, date2 = dayjs(), format = "second") {
|
|
9
|
+
if (!date1) return;
|
|
10
|
+
return dayjs(date1).diff(dayjs(date2), format);
|
|
11
|
+
}
|
|
12
|
+
function diffDateFromCurrent(second) {
|
|
13
|
+
if (second >= 60 * 60 * 24 * 365) {
|
|
14
|
+
return `${parseInt(String(second / (60 * 60 * 24 * 365)))}\u5E74\u524D`;
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
if (second >= 60 * 60 * 24 * 30) {
|
|
17
|
+
return `${parseInt(String(second / (60 * 60 * 24 * 30)))}\u6708\u524D`;
|
|
18
|
+
}
|
|
19
|
+
if (second >= 60 * 60 * 24) {
|
|
20
|
+
return `${parseInt(String(second / (60 * 60 * 24)))}\u5929\u524D`;
|
|
21
|
+
}
|
|
22
|
+
if (second >= 60 * 60) {
|
|
23
|
+
return `${parseInt(String(second / (60 * 60)))}\u5C0F\u65F6\u524D`;
|
|
24
|
+
}
|
|
25
|
+
if (second >= 60) {
|
|
26
|
+
return `${parseInt(String(second / 60))}\u5206\u949F\u524D`;
|
|
27
|
+
}
|
|
28
|
+
return `${parseInt(String(second))}\u79D2\u524D`;
|
|
29
|
+
}
|
|
17
30
|
|
|
18
|
-
export
|
|
19
|
-
export const format = _module.format;
|
|
20
|
-
export const formatDateToDay = _module.formatDateToDay;
|
|
21
|
-
export const formatDateToMinute = _module.formatDateToMinute;
|
|
22
|
-
export const diffDate = _module.diffDate;
|
|
23
|
-
export const date2 = _module.date2;
|
|
24
|
-
export const diffDateFromCurrent = _module.diffDateFromCurrent;
|
|
31
|
+
export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute };
|
package/dist/format.cjs
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"babel": {
|
|
10
|
-
"plugins": []
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
})
|
|
3
|
+
const format = require('./shared/utils.DrwfWQ1C.cjs');
|
|
4
|
+
require('./is.cjs');
|
|
5
|
+
require('@vue/reactivity');
|
|
6
|
+
require('consola');
|
|
7
|
+
require('es-toolkit');
|
|
8
|
+
require('element-plus');
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.formatBytes = format.formatBytes;
|
|
13
|
+
exports.formatBytesConvert = format.formatBytesConvert;
|
|
14
|
+
exports.formatDurationTime = format.formatDurationTime;
|
|
15
|
+
exports.formatImg = format.formatImg;
|
|
16
|
+
exports.formatTextToHtml = format.formatTextToHtml;
|
|
17
|
+
exports.formatThousands = format.formatThousands;
|
|
18
|
+
exports.formatTime = format.formatTime;
|
|
19
|
+
exports.formatToFixed = format.formatToFixed;
|
package/dist/format.d.cts
CHANGED
|
@@ -1 +1,208 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `formatBytes` 的配置项。
|
|
3
|
+
*/
|
|
4
|
+
interface FormatBytesOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 小数位数,默认 `2`。
|
|
7
|
+
*/
|
|
8
|
+
digit?: number;
|
|
9
|
+
/**
|
|
10
|
+
* 是否加千分位,默认 `false`。
|
|
11
|
+
*/
|
|
12
|
+
thousands?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 文本前缀,例如 `$`。
|
|
15
|
+
*/
|
|
16
|
+
prefix?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 文本后缀,例如 `/s`。
|
|
19
|
+
*/
|
|
20
|
+
suffix?: string;
|
|
21
|
+
/**
|
|
22
|
+
* 取整方式,默认 `floor`。
|
|
23
|
+
*/
|
|
24
|
+
roundType?: 'floor' | 'ceil' | 'round';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `formatBytesConvert` 的配置项。
|
|
28
|
+
*/
|
|
29
|
+
interface FormatBytesConvertOptions {
|
|
30
|
+
/**
|
|
31
|
+
* 是否使用千分位输出。
|
|
32
|
+
*/
|
|
33
|
+
thounsands?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 保留小数位数。
|
|
36
|
+
*/
|
|
37
|
+
digit?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `formatImg` 的配置项。
|
|
41
|
+
*/
|
|
42
|
+
interface FormatImgOptions {
|
|
43
|
+
/**
|
|
44
|
+
* 静态资源根目录,默认 `assets/images`。
|
|
45
|
+
*/
|
|
46
|
+
basePath?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `formatToFixed` 的配置项。
|
|
50
|
+
*/
|
|
51
|
+
interface FormatToFixedOptions {
|
|
52
|
+
/**
|
|
53
|
+
* 小数位数,默认 `2`。
|
|
54
|
+
*/
|
|
55
|
+
digit?: number;
|
|
56
|
+
/**
|
|
57
|
+
* 文本前缀,例如 `$`。
|
|
58
|
+
*/
|
|
59
|
+
prefix?: string;
|
|
60
|
+
/**
|
|
61
|
+
* 文本后缀,例如 `%`。
|
|
62
|
+
*/
|
|
63
|
+
suffix?: string;
|
|
64
|
+
/**
|
|
65
|
+
* 是否保留原单位,默认 `true`。
|
|
66
|
+
*/
|
|
67
|
+
unit?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 是否添加千分位,默认 `false`。
|
|
70
|
+
*/
|
|
71
|
+
thousands?: boolean;
|
|
72
|
+
}
|
|
73
|
+
type FormatTimeInput = Date | string | number;
|
|
74
|
+
type FormatTimeFallback = string | ((time: FormatTimeInput) => string);
|
|
75
|
+
/**
|
|
76
|
+
* 将字节数格式化成更易读的单位字符串。
|
|
77
|
+
*
|
|
78
|
+
* @param bytes 字节数,支持数字和数字字符串。
|
|
79
|
+
* @param options 配置项。
|
|
80
|
+
* @returns 格式化后的字节字符串;如果输入不是合法数字,则原样返回。
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* formatBytes(1024)
|
|
84
|
+
* // => '1.00 KB'
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* formatBytes(1040000, {
|
|
88
|
+
* digit: 3,
|
|
89
|
+
* prefix: '$',
|
|
90
|
+
* suffix: '/s',
|
|
91
|
+
* roundType: 'round',
|
|
92
|
+
* thousands: true,
|
|
93
|
+
* })
|
|
94
|
+
* // => '$1,015.625 KB/s'
|
|
95
|
+
*/
|
|
96
|
+
declare function formatBytes(bytes: number | string, options?: FormatBytesOptions): string | number;
|
|
97
|
+
/**
|
|
98
|
+
* 将带单位的字节字符串转换为原始字节数。
|
|
99
|
+
*
|
|
100
|
+
* @param oBytes 字节字符串,例如 `1.5GB`、`1,024 KB`,也支持纯数字。
|
|
101
|
+
* @param options 配置项。
|
|
102
|
+
* @returns 字节数;如启用了 `digit` 或 `thounsands`,返回格式化后的字符串。
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* formatBytesConvert('0.5GB')
|
|
106
|
+
* // => 536870912
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* formatBytesConvert('1,234 GB', { thounsands: true })
|
|
110
|
+
* // => '1,324,997,410,816'
|
|
111
|
+
*/
|
|
112
|
+
declare function formatBytesConvert(oBytes: unknown, options?: FormatBytesConvertOptions): string | number | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* 为数字或数字字符串添加千分位分隔符。
|
|
115
|
+
*
|
|
116
|
+
* @param value 需要格式化的值。
|
|
117
|
+
* @returns 添加千分位后的字符串;如果不符合规则则原样返回。
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* formatThousands(1234567)
|
|
121
|
+
* // => '1,234,567'
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* formatThousands('1234.12MB')
|
|
125
|
+
* // => '1,234.12MB'
|
|
126
|
+
*/
|
|
127
|
+
declare function formatThousands(value: string | number): string | number;
|
|
128
|
+
/**
|
|
129
|
+
* 将时间值格式化为指定模板字符串。
|
|
130
|
+
*
|
|
131
|
+
* 支持 `Date`、毫秒时间戳、秒级时间戳、ISO 字符串和普通日期字符串。
|
|
132
|
+
* 纯日期字符串(如 `2022-03-04`)会按本地时区的 `00:00:00` 解析。
|
|
133
|
+
*
|
|
134
|
+
* @param time 时间值,默认当前时间。
|
|
135
|
+
* @param cFormat 格式模板,默认 `{y}-{m}-{d} {h}:{i}:{s}`。
|
|
136
|
+
* @param fallback 非法日期时的兜底返回值,默认返回原始输入。
|
|
137
|
+
* @returns 格式化后的时间字符串。
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* formatTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* formatTime(1713926400, '{y}/{m}/{d}')
|
|
144
|
+
* // => '2024/04/24'
|
|
145
|
+
*/
|
|
146
|
+
declare function formatTime(time?: FormatTimeInput, cFormat?: string, fallback?: FormatTimeFallback): string;
|
|
147
|
+
/**
|
|
148
|
+
* 将持续时间时间戳格式化为“天 / 时 / 分 / 秒”文本。
|
|
149
|
+
*
|
|
150
|
+
* @param timestamp 持续时间,单位毫秒。
|
|
151
|
+
* @param cFormat 输出模板,默认 `{d}天{h}时{i}分{s}秒`。
|
|
152
|
+
* @returns 格式化后的持续时间文本。
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* formatDurationTime(1162821)
|
|
156
|
+
* // => '19分24秒'
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* formatDurationTime(5 * 60 * 1000, '{i}分{s}秒')
|
|
160
|
+
* // => '05分00秒'
|
|
161
|
+
*/
|
|
162
|
+
declare function formatDurationTime(timestamp: number, cFormat?: string): string;
|
|
163
|
+
/**
|
|
164
|
+
* 获取 `assets` 目录下的静态资源地址。
|
|
165
|
+
*
|
|
166
|
+
* @param photoName 文件名;未带后缀时会自动补 `.png`。
|
|
167
|
+
* @param addPath 额外子目录,例如 `menu`。
|
|
168
|
+
* @param options 配置项。
|
|
169
|
+
* @returns 静态资源的完整 URL;如果本身已是 `http/https` 地址,则原样返回。
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* formatImg('logo')
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* formatImg('avatar.png', 'user')
|
|
176
|
+
*/
|
|
177
|
+
declare function formatImg(photoName: string, addPath?: string, { basePath }?: FormatImgOptions): string;
|
|
178
|
+
/**
|
|
179
|
+
* 按指定小数位格式化数字,并可附带前后缀、单位和千分位。
|
|
180
|
+
*
|
|
181
|
+
* @param value 需要格式化的值。
|
|
182
|
+
* @param options 小数位数或配置项。
|
|
183
|
+
* @returns 格式化后的字符串。
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* formatToFixed('22.1', 2)
|
|
187
|
+
* // => '22.10'
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* formatToFixed('22 TB', { digit: 2, unit: false, prefix: '$' })
|
|
191
|
+
* // => '$22.00'
|
|
192
|
+
*/
|
|
193
|
+
declare function formatToFixed(value: unknown, options?: FormatToFixedOptions | number): string;
|
|
194
|
+
/**
|
|
195
|
+
* 将纯文本中的换行和制表符转换成可直接渲染的 HTML 片段。
|
|
196
|
+
*
|
|
197
|
+
* @param str 需要格式化的文本。
|
|
198
|
+
* @returns 字符串输入会返回转换后的 HTML;非字符串输入会原样返回。
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* formatTextToHtml('第1行\n\t第2行')
|
|
202
|
+
* // => '第1行<br> 第2行'
|
|
203
|
+
*/
|
|
204
|
+
declare function formatTextToHtml(str: string): string;
|
|
205
|
+
declare function formatTextToHtml<T>(str: T): T;
|
|
206
|
+
|
|
207
|
+
export { formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatTextToHtml, formatThousands, formatTime, formatToFixed };
|
|
208
|
+
export type { FormatBytesConvertOptions, FormatBytesOptions, FormatImgOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions };
|