lyb-js 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.
Files changed (89) hide show
  1. package/README.md +507 -9
  2. package/package.json +1 -1
  3. package/dist/Base/LibGetDataType/index.d.ts +0 -10
  4. package/dist/Base/LibGetDataType/index.js +0 -15
  5. package/dist/Base/LibJsGetDataType/index.d.ts +0 -7
  6. package/dist/Base/LibJsGetDataType/index.js +0 -11
  7. package/dist/Base/LibPromiseTimeout/index.d.ts +0 -10
  8. package/dist/Base/LibPromiseTimeout/index.js +0 -40
  9. package/dist/Browser/LibColorConsole/index.d.ts +0 -15
  10. package/dist/Browser/LibColorConsole/index.js +0 -38
  11. package/dist/Browser/LibIsMobile/index.d.ts +0 -6
  12. package/dist/Browser/LibIsMobile/index.js +0 -9
  13. package/dist/Browser/LibIsPad/index.d.ts +0 -6
  14. package/dist/Browser/LibIsPad/index.js +0 -15
  15. package/dist/Browser/LibPathParams/index.d.ts +0 -6
  16. package/dist/Browser/LibPathParams/index.js +0 -16
  17. package/dist/Browser/LibSetTitleIcon/index.d.ts +0 -7
  18. package/dist/Browser/LibSetTitleIcon/index.js +0 -14
  19. package/dist/Browser/LibTagTitleTip/index.d.ts +0 -7
  20. package/dist/Browser/LibTagTitleTip/index.js +0 -24
  21. package/dist/Data/LibChunkArray/index.d.ts +0 -9
  22. package/dist/Data/LibChunkArray/index.js +0 -15
  23. package/dist/Data/LibDeepJSONParse/index.d.ts +0 -6
  24. package/dist/Data/LibDeepJSONParse/index.js +0 -32
  25. package/dist/Data/LibGroupArrayByKey/index.d.ts +0 -10
  26. package/dist/Data/LibGroupArrayByKey/index.js +0 -20
  27. package/dist/Data/LibMatchEmail/index.d.ts +0 -10
  28. package/dist/Data/LibMatchEmail/index.js +0 -16
  29. package/dist/Data/LibSearch/index.d.ts +0 -8
  30. package/dist/Data/LibSearch/index.js +0 -45
  31. package/dist/Data/LibShuffleArray/index.d.ts +0 -7
  32. package/dist/Data/LibShuffleArray/index.js +0 -14
  33. package/dist/Data/LibStepArray/index.d.ts +0 -8
  34. package/dist/Data/LibStepArray/index.js +0 -14
  35. package/dist/File/LibDownloadImageLink/index.d.ts +0 -7
  36. package/dist/File/LibDownloadImageLink/index.js +0 -17
  37. package/dist/File/LibFileSize/index.d.ts +0 -5
  38. package/dist/File/LibFileSize/index.js +0 -11
  39. package/dist/File/LibImageOptimizer/index.d.ts +0 -32
  40. package/dist/File/LibImageOptimizer/index.js +0 -83
  41. package/dist/File/LibImageOptimizerOptions/index.d.ts +0 -18
  42. package/dist/File/LibImageOptimizerOptions/index.js +0 -69
  43. package/dist/File/LibSaveExcel/index.d.ts +0 -11
  44. package/dist/File/LibSaveExcel/index.js +0 -17
  45. package/dist/File/LibSaveJson/index.d.ts +0 -8
  46. package/dist/File/LibSaveJson/index.js +0 -16
  47. package/dist/Formatter/LibFormatterByte/index.d.ts +0 -9
  48. package/dist/Formatter/LibFormatterByte/index.js +0 -17
  49. package/dist/Formatter/LibMaskPhoneNumber/index.d.ts +0 -8
  50. package/dist/Formatter/LibMaskPhoneNumber/index.js +0 -11
  51. package/dist/Formatter/LibNumComma/index.d.ts +0 -9
  52. package/dist/Formatter/LibNumComma/index.js +0 -13
  53. package/dist/Formatter/LibNumberUnit/index.d.ts +0 -12
  54. package/dist/Formatter/LibNumberUnit/index.js +0 -23
  55. package/dist/Math/LibCalculateExpression/index.d.ts +0 -10
  56. package/dist/Math/LibCalculateExpression/index.js +0 -108
  57. package/dist/Math/LibConvertAngle/index.d.ts +0 -12
  58. package/dist/Math/LibConvertAngle/index.js +0 -22
  59. package/dist/Math/LibCoordsAngle/index.d.ts +0 -15
  60. package/dist/Math/LibCoordsAngle/index.js +0 -24
  61. package/dist/Math/LibCoordsDistance/index.d.ts +0 -15
  62. package/dist/Math/LibCoordsDistance/index.js +0 -16
  63. package/dist/Math/LibDecimal/index.d.ts +0 -11
  64. package/dist/Math/LibDecimal/index.js +0 -26
  65. package/dist/Misc/LibRegFormValidate/index.d.ts +0 -32
  66. package/dist/Misc/LibRegFormValidate/index.js +0 -34
  67. package/dist/Misc/LibRetryRequest/index.d.ts +0 -24
  68. package/dist/Misc/LibRetryRequest/index.js +0 -37
  69. package/dist/Random/LibProbabilityResult/index.d.ts +0 -8
  70. package/dist/Random/LibProbabilityResult/index.js +0 -8
  71. package/dist/Random/LibRandom/index.d.ts +0 -10
  72. package/dist/Random/LibRandom/index.js +0 -12
  73. package/dist/Random/LibRandomColor/index.d.ts +0 -7
  74. package/dist/Random/LibRandomColor/index.js +0 -12
  75. package/dist/Random/LibUniqueRandomNumbers/index.d.ts +0 -9
  76. package/dist/Random/LibUniqueRandomNumbers/index.js +0 -16
  77. package/dist/Time/LibSameTimeCheck/index.d.ts +0 -8
  78. package/dist/Time/LibSameTimeCheck/index.js +0 -20
  79. package/dist/Time/LibSecondsFormatterChinese/index.d.ts +0 -11
  80. package/dist/Time/LibSecondsFormatterChinese/index.js +0 -42
  81. package/dist/Time/LibTimeAgo/index.d.ts +0 -9
  82. package/dist/Time/LibTimeAgo/index.js +0 -27
  83. package/dist/Time/LibTimeGreeting/index.d.ts +0 -17
  84. package/dist/Time/LibTimeGreeting/index.js +0 -23
  85. package/dist/index.d.ts +0 -1
  86. package/dist/index.js +0 -1
  87. package/dist/lib.d.ts +0 -395
  88. package/dist/lib.js +0 -405
  89. package/test/index.js +0 -0
@@ -1,20 +0,0 @@
1
- import dayjs from "dayjs";
2
- /**
3
- * @description 传入时间戳与当前时间判断是否为同一天或同一周
4
- * @param timestamp 毫秒时间戳
5
- * @param unit 判断单位
6
- * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
7
- */
8
- export const libSameTimeCheck = (timestamp, unit) => {
9
- const inputTime = dayjs(timestamp).startOf(unit);
10
- const currentTime = dayjs().startOf(unit);
11
- if (inputTime.isSame(currentTime)) {
12
- return 0;
13
- }
14
- else if (inputTime.isBefore(currentTime)) {
15
- return 1;
16
- }
17
- else {
18
- return -1;
19
- }
20
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * @description 将秒数格式化为中文时间描述,支持扩展到年和月。
3
- * @param seconds 秒数
4
- * @returns 格式化后的中文时间
5
- * @example
6
- * libSecondsFormatterChinese(100000); // "1天3小时46分40秒"
7
- * libSecondsFormatterChinese(31536000); // "1年"
8
- * libSecondsFormatterChinese(3600); // "1小时"
9
- * libSecondsFormatterChinese(90); // "1分30秒"
10
- */
11
- export declare const libSecondsFormatterChinese: (seconds: number) => string;
@@ -1,42 +0,0 @@
1
- import dayjs from "dayjs";
2
- import duration from "dayjs/plugin/duration";
3
- dayjs.extend(duration);
4
- /**
5
- * @description 将秒数格式化为中文时间描述,支持扩展到年和月。
6
- * @param seconds 秒数
7
- * @returns 格式化后的中文时间
8
- * @example
9
- * libSecondsFormatterChinese(100000); // "1天3小时46分40秒"
10
- * libSecondsFormatterChinese(31536000); // "1年"
11
- * libSecondsFormatterChinese(3600); // "1小时"
12
- * libSecondsFormatterChinese(90); // "1分30秒"
13
- */
14
- export const libSecondsFormatterChinese = (seconds) => {
15
- const duration = dayjs.duration(seconds, "seconds");
16
- const years = Math.floor(duration.asYears());
17
- const months = Math.floor(duration.asMonths() % 12);
18
- const days = Math.floor(duration.asDays() % 30);
19
- const hours = duration.hours();
20
- const minutes = duration.minutes();
21
- const remainingSeconds = duration.seconds();
22
- const timeParts = [];
23
- if (years > 0) {
24
- timeParts.push(`${years}年`);
25
- }
26
- if (months > 0) {
27
- timeParts.push(`${months}月`);
28
- }
29
- if (days > 0) {
30
- timeParts.push(`${days}天`);
31
- }
32
- if (hours > 0) {
33
- timeParts.push(`${hours}小时`);
34
- }
35
- if (minutes > 0) {
36
- timeParts.push(`${minutes}分`);
37
- }
38
- if (timeParts.length === 0 || remainingSeconds > 0) {
39
- timeParts.push(`${remainingSeconds}秒`);
40
- }
41
- return timeParts.join("");
42
- };
@@ -1,9 +0,0 @@
1
- /** @description 时间差计算
2
- * @param timestamp 毫秒时间戳
3
- * @example
4
- * libTimeAgotamp(Date.now() - 3600000); // "1 小时前"
5
- * libTimeAgotamp(Date.now() - 86400000); // "1 天前"
6
- * libTimeAgotamp(Date.now() - 31536000000); // "1 年前"
7
- * libTimeAgotamp(Date.now() - 10000); // "刚刚"
8
- */
9
- export declare const libTimeAgo: (timestamp: number) => string;
@@ -1,27 +0,0 @@
1
- /** @description 时间差计算
2
- * @param timestamp 毫秒时间戳
3
- * @example
4
- * libTimeAgotamp(Date.now() - 3600000); // "1 小时前"
5
- * libTimeAgotamp(Date.now() - 86400000); // "1 天前"
6
- * libTimeAgotamp(Date.now() - 31536000000); // "1 年前"
7
- * libTimeAgotamp(Date.now() - 10000); // "刚刚"
8
- */
9
- export const libTimeAgo = (timestamp) => {
10
- const timeUnits = [
11
- { unit: "年", milliseconds: 365 * 24 * 60 * 60 * 1000 },
12
- { unit: "月", milliseconds: 30 * 24 * 60 * 60 * 1000 },
13
- { unit: "周", milliseconds: 7 * 24 * 60 * 60 * 1000 },
14
- { unit: "天", milliseconds: 24 * 60 * 60 * 1000 },
15
- { unit: "小时", milliseconds: 60 * 60 * 1000 },
16
- { unit: "分钟", milliseconds: 60 * 1000 },
17
- ];
18
- const currentTime = Date.now();
19
- const timeDifference = currentTime - timestamp;
20
- for (const { unit, milliseconds } of timeUnits) {
21
- if (timeDifference >= milliseconds) {
22
- const count = Math.floor(timeDifference / milliseconds);
23
- return `${count} ${unit}前`;
24
- }
25
- }
26
- return "刚刚";
27
- };
@@ -1,17 +0,0 @@
1
- export interface LibTimeGreetingParams {
2
- midnight?: string;
3
- morning?: string;
4
- forenoon?: string;
5
- noon?: string;
6
- afternoon?: string;
7
- evening?: string;
8
- }
9
- /**
10
- * @description 根据当前时间返回问候语。
11
- * @param greet 自定义问候语对象。
12
- * @example
13
- * libTimeGreeting(); // 根据当前时间返回默认问候语
14
- * libTimeGreeting({ morning: "早安" }); // 自定义早上问候语
15
- * libTimeGreeting({ afternoon: "午后好" }); // 自定义下午问候语
16
- */
17
- export declare const libTimeGreeting: (greet?: LibTimeGreetingParams) => string;
@@ -1,23 +0,0 @@
1
- /**
2
- * @description 根据当前时间返回问候语。
3
- * @param greet 自定义问候语对象。
4
- * @example
5
- * libTimeGreeting(); // 根据当前时间返回默认问候语
6
- * libTimeGreeting({ morning: "早安" }); // 自定义早上问候语
7
- * libTimeGreeting({ afternoon: "午后好" }); // 自定义下午问候语
8
- */
9
- export const libTimeGreeting = (greet = {}) => {
10
- const { midnight = "午夜好", morning = "早上好", forenoon = "上午好", noon = "中午好", afternoon = "下午好", evening = "晚上好", } = greet;
11
- const now = new Date().getHours();
12
- return now < 4
13
- ? midnight
14
- : now < 10
15
- ? morning
16
- : now < 12
17
- ? forenoon
18
- : now < 14
19
- ? noon
20
- : now < 18
21
- ? afternoon
22
- : evening;
23
- };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * as Lib from "./lib";
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export * as Lib from "./lib";
package/dist/lib.d.ts DELETED
@@ -1,395 +0,0 @@
1
- /** @description 基础方法 */
2
- export declare const Base: {
3
- /**
4
- * @description 返回数据类型
5
- * @param v 需要判断类型的数据
6
- * @example
7
- * libGetDataType(123); // "number"
8
- * libGetDataType("hello"); // "string"
9
- * libGetDataType([1, 2, 3]); // "array"
10
- */
11
- libGetDataType: (v: any) => import("./Base/LibGetDataType").LibGetDataTypeReturnType;
12
- /**
13
- * @description 延时执行,切换到其他页面会暂停
14
- * @param delay 延时毫秒数
15
- * @param fn 延时执行函数
16
- * @example
17
- * libPromiseTimeout(3000, () => {
18
- * console.log("执行延时函数");
19
- * });
20
- */
21
- libPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
22
- };
23
- /** @description 浏览器相关方法 */
24
- export declare const Browser: {
25
- /** @description console颜色打印
26
- * @param title 标题
27
- * @param color 颜色
28
- * @param logs 信息
29
- * @example
30
- * // 使用红色打印日志
31
- * libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
32
- *
33
- * // 使用蓝色打印简单日志
34
- * libColorConsole("信息", "blue", "操作成功");
35
- */
36
- libColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
37
- label: string;
38
- value: any;
39
- }[] | any) => void;
40
- /** @description 判断是否为移动设备
41
- * @example
42
- * const isMobile = libIsMobile();
43
- * console.log(isMobile); // true 或 false
44
- */
45
- libIsMobile: () => boolean;
46
- /** @description 判断是否为平板
47
- * @example
48
- * const isPad = libIsPad();
49
- * console.log(isPad); // true 或 false
50
- */
51
- libIsPad: () => boolean;
52
- /** @description 获取浏览器地址栏参数
53
- * @example
54
- * const params = libPathParams();
55
- * console.log(params); // { param1: "value1", param2: "value2" }
56
- */
57
- libPathParams: () => Record<string, string>;
58
- /** @description 动态设置网站标题及图标
59
- * @param title 网站标题
60
- * @param url 网站图标地址
61
- * @example
62
- * libSetTitleIcon("我的网站", "https://example.com/favicon.ico");
63
- */
64
- libSetTitleIcon: (title: string, url: string) => void;
65
- /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
66
- * @param backTitle 从其他网页返回时显示的标题
67
- * @param leaveTitle 从当前网页离开时显示的标题
68
- * * @example
69
- * libTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
70
- */
71
- libTagTitleTip: (backTitle: string, leaveTitle: string) => void;
72
- };
73
- /** @description 数据相关方法 */
74
- export declare const Data: {
75
- /**
76
- * @description 将数组拆分成指定数组元素数量的多个数组
77
- * @param arr 需要拆分的数组
78
- * @param chunkSize 每个数组的元素数量
79
- * @example
80
- * const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
81
- * console.log(chunks); // [[1, 2], [3, 4], [5, 6]]
82
- */
83
- libChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
84
- /** @description 递归将JSON字符串深度解析为对象
85
- * @example
86
- * const obj = libDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
87
- * console.log(obj); // { a: 1, b: { c: 2 } }
88
- */
89
- libDeepJSONParse: <T>(data: any) => T;
90
- /**
91
- * @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
92
- * @param arr 要分组的数组。
93
- * @param key 分组的键。
94
- * @returns 分组后的对象。
95
- * @example
96
- * const grouped = libGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
97
- * console.log(grouped); // { 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
98
- */
99
- libGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
100
- /**
101
- * @description 匹配电子邮件,可用于实时输入时,自动补全常用邮箱后缀
102
- * @param str 要匹配的字符串
103
- * @param emailList 电子邮件后缀列表
104
- * @returns 匹配结果数组
105
- * @example
106
- * const emails = libMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
107
- * console.log(emails); // ["user@gmail.com", "user@yahoo.com"]
108
- */
109
- libMatchEmail: (str: string, emailList: string[]) => string[];
110
- /** @description 数组乱序
111
- * @param arr 需要乱序的数组
112
- * @example
113
- * const shuffled = libShuffleArray([1, 2, 3, 4, 5]);
114
- * console.log(shuffled); // [3, 5, 2, 1, 4] (结果每次不同)
115
- */
116
- libShuffleArray: <T>(arr: T[]) => T[];
117
- /** @description 数组元素整体步数移动
118
- * @param arr 移动的数组
119
- * @param step 负数为向后移动,正数为向前移动
120
- * @example
121
- * const moved = libStepArray([1, 2, 3, 4, 5], 2);
122
- * console.log(moved); // [4, 5, 1, 2, 3]
123
- */
124
- libStepArray: <T>(arr: T[], step: number) => T[];
125
- };
126
- /** @description 文件相关方法 */
127
- export declare const File: {
128
- /** @description 下载图片链接
129
- * @param link 图片链接
130
- * @param name 图片名称
131
- * @example
132
- * libDownloadImageLink("https://example.com/image.jpg", "downloaded-image.jpg");
133
- */
134
- libDownloadImageLink: (link: string, name: string) => void;
135
- /** @description 图片压缩
136
- * @param obj 压缩参数
137
- * @example
138
- * // 图片压缩使用示例
139
- * libImageOptimizerOptionsParams({
140
- * file: myFile,
141
- * ratio: 0.8,
142
- * width: 800,
143
- * maxSize: 1024,
144
- * success: (data, file, url) => {
145
- * console.log('压缩成功', data, file, url);
146
- * },
147
- * fail: (error) => {
148
- * console.error('压缩失败', error);
149
- * }
150
- * });
151
- */
152
- libImageOptimizer: (obj: import("./File/LibImageOptimizer").LibImageOptimizerOptionsParams) => void;
153
- /**
154
- * @description 保存文件到本地
155
- * @param data 要保存的数据
156
- * @param name 文件名
157
- * @example
158
- * libSaveJson(JSON.stringify({ key: "value" }), "example.json");
159
- */
160
- libSaveJson: (data: BlobPart, name: string) => void;
161
- };
162
- /** @description 格式化相关方法 */
163
- export declare const Formatter: {
164
- /**
165
- * @description 格式化字节大小
166
- * @param bytes 字节数
167
- * @returns ['大小', '单位', '大小及单位']
168
- * @example
169
- * const [size, unit, formatted] = libFormatterByte(2048);
170
- * console.log(size, unit, formatted); // 2.00 KB 2.00 KB
171
- */
172
- libFormatterByte: (bytes: number) => (string | number)[];
173
- /**
174
- * @description 隐藏手机号码中间的四位数字。
175
- * @param mobile 需要处理的手机号码。
176
- * @example
177
- * const masked = libMaskPhoneNumber("13812345678");
178
- * console.log(masked); // 138****5678
179
- */
180
- libMaskPhoneNumber: (mobile: number | string) => string;
181
- /**
182
- * @description 数字每三位添加逗号
183
- * @param num 需要格式化的数字
184
- * @param reserve 保留小数位数
185
- * @example
186
- * const formatted = libNumComma(1234567.89);
187
- * console.log(formatted); // 1,234,567.89
188
- */
189
- libNumComma: (num: number, reserve?: number) => string;
190
- /** @description 将大于1000的数字使用k为单位
191
- * @param num 数字
192
- * @param units 单位组,key为单位,value为格式化阈值
193
- * @returns [数字, 单位]
194
- * @example
195
- * const [value, unit] = libNumberUnit(1500, { K: 1000, M: 1000000 });
196
- * console.log(value, unit); // 1.50 K
197
- */
198
- libNumberUnit: (num: number, units: import("./Formatter/LibNumberUnit").LibNumberUnitParams) => string[];
199
- };
200
- /** @description 数学相关方法 */
201
- export declare const Math: {
202
- /** @description 计算表达式字符串
203
- * @param expression 表达式字符串
204
- * @param point 小数点精度
205
- * @returns 计算结果
206
- *
207
- * @example
208
- * const result = libCalculateExpression("(1+2)-(3*4)/5");
209
- * console.log(result); // 0.6
210
- */
211
- libCalculateExpression: (expression: string, point?: number) => number;
212
- /**
213
- * @description 角度和弧度互相转换
214
- * @param value 角度值或弧度值
215
- * @param type 角度类型或弧度类型
216
- * @example
217
- * // 角度转弧度
218
- * libConvertAngle(90, "rad"); // 返回 1.5708... (π/2)
219
- *
220
- * // 弧度转角度
221
- * libConvertAngle(Math.PI, "deg"); // 返回 180
222
- */
223
- libConvertAngle: (value: number, type: "rad" | "deg") => number;
224
- /** @description 计算两点角度
225
- * @param coord1 起点坐标
226
- * @param coord2 终点坐标
227
- * @example
228
- * libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); // 0
229
- * libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); // 45
230
- * libCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); // 90
231
- */
232
- libCoordsAngle: (coord1: {
233
- x: number;
234
- y: number;
235
- }, coord2: {
236
- x: number;
237
- y: number;
238
- }) => number;
239
- /** @description 计算两点距离
240
- * @param coord1 起点坐标
241
- * @param coord2 终点坐标
242
- * @example
243
- * libCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5
244
- * libCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); // 5
245
- * libCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); // 0
246
- */
247
- libCoordsDistance: (coord1: {
248
- x: number;
249
- y: number;
250
- }, coord2: {
251
- x: number;
252
- y: number;
253
- }) => number;
254
- /** @description 计算两个数的运算结果,并保留指定位数的小数
255
- * @param num1 第一个数
256
- * @param num2 第二个数
257
- * @param operator 运算符,支持加减乘除
258
- * @example
259
- * // 示例用法
260
- * libDecimal(10, 3, "+"); // 13
261
- * libDecimal(10, 3, "-"); // 7
262
- * libDecimal(10, 3, "/", 2); // 3.33
263
- */
264
- libDecimal: (num1: number, num2: number, operator: "+" | "-" | "*" | "/", point?: number) => number;
265
- };
266
- /** @description 杂项相关方法 */
267
- export declare const Misc: {
268
- /**
269
- * @description 表单验证函数。
270
- * @param form 表单数据对象。
271
- * @param rules 验证规则数组。
272
- * @returns 验证结果数组,包含未通过验证的项。
273
- * @example
274
- * const form = { username: "john", email: "john@example.com" };
275
- * const rules = [
276
- * { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
277
- * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
278
- * ];
279
- * libRegFormValidate(form, rules);
280
- * // 返回结果: []
281
- *
282
- * const invalidForm = { username: "jo", email: "invalid-email" };
283
- * libRegFormValidate(invalidForm, rules);
284
- * // 返回结果: [
285
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
286
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
287
- * // ]
288
- */
289
- libRegFormValidate: (form: Record<string, any>, rules: Array<{
290
- key: string;
291
- verify: RegExp | ((value: any) => boolean);
292
- msg: string;
293
- name: string;
294
- }>) => import("./Misc/LibRegFormValidate").ValidationResult[];
295
- /** @description 请求失败重连
296
- * @param promiseFn 请求函数
297
- * @param maxRetries 最大重试次数
298
- * @param retryDelay 重试间隔时间
299
- * @param params 请求参数
300
- * @example
301
- * const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
302
- * const params = { url: "https://api.example.com/data" };
303
- * libRetryRequest({
304
- * promiseFn: requestFn,
305
- * params,
306
- * maxRetries: 5,
307
- * retryDelay: 1000
308
- * })
309
- * .then(data => console.log(data))
310
- * .catch(err => console.error(err));
311
- */
312
- libRetryRequest: <T>({ promiseFn, maxRetries, retryDelay, params, }: {
313
- promiseFn: (params?: any) => Promise<T>;
314
- params?: any;
315
- maxRetries?: number;
316
- retryDelay?: number;
317
- onRetry?: () => void;
318
- }) => Promise<T>;
319
- };
320
- /** @description 随机相关方法 */
321
- export declare const Random: {
322
- /** @description 百分比概率结果
323
- * @param probability 触发概率,百分比,0-100
324
- * @example
325
- * libProbabilityResult(50); // 50% 概率为 true
326
- * libProbabilityResult(80); // 80% 概率为 true
327
- * libProbabilityResult(100); // 100% 概率为 true
328
- */
329
- libProbabilityResult: (probability: number) => boolean;
330
- /** @description 随机数
331
- * @param min 最小值
332
- * @param max 最大值
333
- * @param num 保留小数位数
334
- * @example
335
- * libRandom(1, 10); // 1 到 10 之间的随机整数
336
- * libRandom(1, 10, 2); // 1 到 10 之间保留两位小数的随机数
337
- * libRandom(5, 5, 3); // 返回 5.000
338
- */
339
- libRandom: (min: number, max: number, num?: number) => number;
340
- /** @description 随机 RGBA 颜色
341
- * @param alpha 透明度
342
- * @example
343
- * libRandomColor(); // 生成随机的 RGBA 颜色,默认透明度 1
344
- * libRandomColor(0.5); // 生成随机的 RGBA 颜色,透明度为 0.5
345
- */
346
- libRandomColor: (alpha?: number) => string;
347
- /** @description 随机生成n个指定范围的随机数数组
348
- * @param min 最小值
349
- * @param max 最大值
350
- * @param count 数组长度
351
- * @example
352
- * libUniqueRandomNumbers(1, 10, 5); // 从 1 到 10 中随机生成 5 个唯一数字
353
- * libUniqueRandomNumbers(1, 100, 10); // 从 1 到 100 中随机生成 10 个唯一数字
354
- */
355
- libUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
356
- };
357
- /** @description 时间相关方法 */
358
- export declare const Time: {
359
- /**
360
- * @description 传入时间戳与当前时间判断是否为同一天或同一周
361
- * @param timestamp 毫秒时间戳
362
- * @param unit 判断单位
363
- * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
364
- */
365
- libSameTimeCheck: (timestamp: number, unit: import("dayjs").OpUnitType) => 0 | 1 | -1;
366
- /**
367
- * @description 将秒数格式化为中文时间描述,支持扩展到年和月。
368
- * @param seconds 秒数
369
- * @returns 格式化后的中文时间
370
- * @example
371
- * libSecondsFormatterChinese(100000); // "1天3小时46分40秒"
372
- * libSecondsFormatterChinese(31536000); // "1年"
373
- * libSecondsFormatterChinese(3600); // "1小时"
374
- * libSecondsFormatterChinese(90); // "1分30秒"
375
- */
376
- libSecondsFormatterChinese: (seconds: number) => string;
377
- /** @description 时间差计算
378
- * @param timestamp 毫秒时间戳
379
- * @example
380
- * libTimeAgotamp(Date.now() - 3600000); // "1 小时前"
381
- * libTimeAgotamp(Date.now() - 86400000); // "1 天前"
382
- * libTimeAgotamp(Date.now() - 31536000000); // "1 年前"
383
- * libTimeAgotamp(Date.now() - 10000); // "刚刚"
384
- */
385
- libTimeAgo: (timestamp: number) => string;
386
- /**
387
- * @description 根据当前时间返回问候语。
388
- * @param greet 自定义问候语对象。
389
- * @example
390
- * libTimeGreeting(); // 根据当前时间返回默认问候语
391
- * libTimeGreeting({ morning: "早安" }); // 自定义早上问候语
392
- * libTimeGreeting({ afternoon: "午后好" }); // 自定义下午问候语
393
- */
394
- libTimeGreeting: (greet?: import("./Time/LibTimeGreeting").LibTimeGreetingParams) => string;
395
- };