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
package/dist/lib.js DELETED
@@ -1,405 +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 { libFormatterByte } from "./Formatter/LibFormatterByte";
19
- import { libMaskPhoneNumber } from "./Formatter/LibMaskPhoneNumber";
20
- import { libNumComma } from "./Formatter/LibNumComma";
21
- import { libNumberUnit } from "./Formatter/LibNumberUnit";
22
- import { libCalculateExpression } from "./Math/LibCalculateExpression";
23
- import { libConvertAngle } from "./Math/LibConvertAngle";
24
- import { libCoordsAngle } from "./Math/LibCoordsAngle";
25
- import { libCoordsDistance } from "./Math/LibCoordsDistance";
26
- import { libDecimal } from "./Math/LibDecimal";
27
- import { libRegFormValidate } from "./Misc/LibRegFormValidate";
28
- import { libRetryRequest } from "./Misc/LibRetryRequest";
29
- import { libProbabilityResult } from "./Random/LibProbabilityResult";
30
- import { libRandom } from "./Random/LibRandom";
31
- import { libRandomColor } from "./Random/LibRandomColor";
32
- import { libUniqueRandomNumbers } from "./Random/LibUniqueRandomNumbers";
33
- import { libSameTimeCheck } from "./Time/LibSameTimeCheck";
34
- import { libSecondsFormatterChinese } from "./Time/LibSecondsFormatterChinese";
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
- export const Math = {
235
- /** @description 计算表达式字符串
236
- * @param expression 表达式字符串
237
- * @param point 小数点精度
238
- * @returns 计算结果
239
- *
240
- * @example
241
- * const result = libCalculateExpression("(1+2)-(3*4)/5");
242
- * console.log(result); // 0.6
243
- */
244
- libCalculateExpression,
245
- /**
246
- * @description 角度和弧度互相转换
247
- * @param value 角度值或弧度值
248
- * @param type 角度类型或弧度类型
249
- * @example
250
- * // 角度转弧度
251
- * libConvertAngle(90, "rad"); // 返回 1.5708... (π/2)
252
- *
253
- * // 弧度转角度
254
- * libConvertAngle(Math.PI, "deg"); // 返回 180
255
- */
256
- libConvertAngle,
257
- /** @description 计算两点角度
258
- * @param coord1 起点坐标
259
- * @param coord2 终点坐标
260
- * @example
261
- * libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); // 0
262
- * libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); // 45
263
- * libCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); // 90
264
- */
265
- libCoordsAngle,
266
- /** @description 计算两点距离
267
- * @param coord1 起点坐标
268
- * @param coord2 终点坐标
269
- * @example
270
- * libCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); // 5
271
- * libCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); // 5
272
- * libCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); // 0
273
- */
274
- libCoordsDistance,
275
- /** @description 计算两个数的运算结果,并保留指定位数的小数
276
- * @param num1 第一个数
277
- * @param num2 第二个数
278
- * @param operator 运算符,支持加减乘除
279
- * @example
280
- * // 示例用法
281
- * libDecimal(10, 3, "+"); // 13
282
- * libDecimal(10, 3, "-"); // 7
283
- * libDecimal(10, 3, "/", 2); // 3.33
284
- */
285
- libDecimal,
286
- };
287
- /** @description 杂项相关方法 */
288
- export const Misc = {
289
- /**
290
- * @description 表单验证函数。
291
- * @param form 表单数据对象。
292
- * @param rules 验证规则数组。
293
- * @returns 验证结果数组,包含未通过验证的项。
294
- * @example
295
- * const form = { username: "john", email: "john@example.com" };
296
- * const rules = [
297
- * { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
298
- * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
299
- * ];
300
- * libRegFormValidate(form, rules);
301
- * // 返回结果: []
302
- *
303
- * const invalidForm = { username: "jo", email: "invalid-email" };
304
- * libRegFormValidate(invalidForm, rules);
305
- * // 返回结果: [
306
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
307
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
308
- * // ]
309
- */
310
- libRegFormValidate,
311
- /** @description 请求失败重连
312
- * @param promiseFn 请求函数
313
- * @param maxRetries 最大重试次数
314
- * @param retryDelay 重试间隔时间
315
- * @param params 请求参数
316
- * @example
317
- * const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
318
- * const params = { url: "https://api.example.com/data" };
319
- * libRetryRequest({
320
- * promiseFn: requestFn,
321
- * params,
322
- * maxRetries: 5,
323
- * retryDelay: 1000
324
- * })
325
- * .then(data => console.log(data))
326
- * .catch(err => console.error(err));
327
- */
328
- libRetryRequest,
329
- };
330
- /** @description 随机相关方法 */
331
- export const Random = {
332
- /** @description 百分比概率结果
333
- * @param probability 触发概率,百分比,0-100
334
- * @example
335
- * libProbabilityResult(50); // 50% 概率为 true
336
- * libProbabilityResult(80); // 80% 概率为 true
337
- * libProbabilityResult(100); // 100% 概率为 true
338
- */
339
- libProbabilityResult,
340
- /** @description 随机数
341
- * @param min 最小值
342
- * @param max 最大值
343
- * @param num 保留小数位数
344
- * @example
345
- * libRandom(1, 10); // 1 到 10 之间的随机整数
346
- * libRandom(1, 10, 2); // 1 到 10 之间保留两位小数的随机数
347
- * libRandom(5, 5, 3); // 返回 5.000
348
- */
349
- libRandom,
350
- /** @description 随机 RGBA 颜色
351
- * @param alpha 透明度
352
- * @example
353
- * libRandomColor(); // 生成随机的 RGBA 颜色,默认透明度 1
354
- * libRandomColor(0.5); // 生成随机的 RGBA 颜色,透明度为 0.5
355
- */
356
- libRandomColor,
357
- /** @description 随机生成n个指定范围的随机数数组
358
- * @param min 最小值
359
- * @param max 最大值
360
- * @param count 数组长度
361
- * @example
362
- * libUniqueRandomNumbers(1, 10, 5); // 从 1 到 10 中随机生成 5 个唯一数字
363
- * libUniqueRandomNumbers(1, 100, 10); // 从 1 到 100 中随机生成 10 个唯一数字
364
- */
365
- libUniqueRandomNumbers,
366
- };
367
- /** @description 时间相关方法 */
368
- export const Time = {
369
- /**
370
- * @description 传入时间戳与当前时间判断是否为同一天或同一周
371
- * @param timestamp 毫秒时间戳
372
- * @param unit 判断单位
373
- * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
374
- */
375
- libSameTimeCheck,
376
- /**
377
- * @description 将秒数格式化为中文时间描述,支持扩展到年和月。
378
- * @param seconds 秒数
379
- * @returns 格式化后的中文时间
380
- * @example
381
- * libSecondsFormatterChinese(100000); // "1天3小时46分40秒"
382
- * libSecondsFormatterChinese(31536000); // "1年"
383
- * libSecondsFormatterChinese(3600); // "1小时"
384
- * libSecondsFormatterChinese(90); // "1分30秒"
385
- */
386
- libSecondsFormatterChinese,
387
- /** @description 时间差计算
388
- * @param timestamp 毫秒时间戳
389
- * @example
390
- * libTimeAgotamp(Date.now() - 3600000); // "1 小时前"
391
- * libTimeAgotamp(Date.now() - 86400000); // "1 天前"
392
- * libTimeAgotamp(Date.now() - 31536000000); // "1 年前"
393
- * libTimeAgotamp(Date.now() - 10000); // "刚刚"
394
- */
395
- libTimeAgo,
396
- /**
397
- * @description 根据当前时间返回问候语。
398
- * @param greet 自定义问候语对象。
399
- * @example
400
- * libTimeGreeting(); // 根据当前时间返回默认问候语
401
- * libTimeGreeting({ morning: "早安" }); // 自定义早上问候语
402
- * libTimeGreeting({ afternoon: "午后好" }); // 自定义下午问候语
403
- */
404
- libTimeGreeting,
405
- };
package/test/index.js DELETED
File without changes