lyb-js 1.0.8 → 1.1.0

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