lyb-js 1.0.2 → 1.0.3

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 (69) hide show
  1. package/README.md +406 -9
  2. package/dist/Base/LibGetDataType/index.d.ts +3 -3
  3. package/dist/Base/LibGetDataType/index.js +3 -3
  4. package/dist/Browser/LibColorConsole/index.d.ts +2 -2
  5. package/dist/Browser/LibColorConsole/index.js +3 -3
  6. package/dist/Browser/LibIsMobile/index.d.ts +1 -1
  7. package/dist/Browser/LibIsMobile/index.js +1 -1
  8. package/dist/Browser/LibIsPad/index.d.ts +1 -1
  9. package/dist/Browser/LibIsPad/index.js +1 -1
  10. package/dist/Browser/LibPathParams/index.d.ts +1 -1
  11. package/dist/Browser/LibPathParams/index.js +1 -1
  12. package/dist/Data/LibChunkArray/index.d.ts +1 -1
  13. package/dist/Data/LibChunkArray/index.js +1 -1
  14. package/dist/Data/LibDeepJSONParse/index.d.ts +1 -1
  15. package/dist/Data/LibDeepJSONParse/index.js +7 -7
  16. package/dist/Data/LibGroupArrayByKey/index.d.ts +4 -4
  17. package/dist/Data/LibGroupArrayByKey/index.js +4 -4
  18. package/dist/Data/LibMatchEmail/index.d.ts +1 -1
  19. package/dist/Data/LibMatchEmail/index.js +1 -1
  20. package/dist/Data/LibShuffleArray/index.d.ts +2 -2
  21. package/dist/Data/LibShuffleArray/index.js +2 -2
  22. package/dist/Data/LibStepArray/index.d.ts +1 -1
  23. package/dist/Data/LibStepArray/index.js +1 -1
  24. package/dist/File/LibDownloadImageLink/index.d.ts +2 -2
  25. package/dist/File/LibDownloadImageLink/index.js +2 -2
  26. package/dist/File/LibImageOptimizer/index.d.ts +5 -5
  27. package/dist/File/LibImageOptimizer/index.js +4 -4
  28. package/dist/File/LibSaveJson/index.d.ts +1 -0
  29. package/dist/File/LibSaveJson/index.js +1 -0
  30. package/dist/Formatter/LibFormatterByte/index.d.ts +1 -1
  31. package/dist/Formatter/LibFormatterByte/index.js +1 -1
  32. package/dist/Formatter/LibMaskPhoneNumber/index.d.ts +3 -3
  33. package/dist/Formatter/LibMaskPhoneNumber/index.js +3 -3
  34. package/dist/Formatter/LibNumComma/index.d.ts +1 -1
  35. package/dist/Formatter/LibNumComma/index.js +1 -1
  36. package/dist/Formatter/LibNumberUnit/index.d.ts +1 -1
  37. package/dist/Formatter/LibNumberUnit/index.js +1 -1
  38. package/dist/Formatter/LibSecondsFormatterChinese/index.d.ts +11 -0
  39. package/dist/Formatter/LibSecondsFormatterChinese/index.js +42 -0
  40. package/dist/Math/LibCalculateExpression/index.d.ts +1 -2
  41. package/dist/Math/LibCalculateExpression/index.js +17 -18
  42. package/dist/Math/LibConvertAngle/index.d.ts +4 -4
  43. package/dist/Math/LibConvertAngle/index.js +4 -4
  44. package/dist/Math/LibCoordsAngle/index.d.ts +3 -3
  45. package/dist/Math/LibCoordsAngle/index.js +8 -8
  46. package/dist/Math/LibCoordsDistance/index.d.ts +3 -3
  47. package/dist/Math/LibCoordsDistance/index.js +5 -5
  48. package/dist/Math/LibDecimal/index.d.ts +3 -4
  49. package/dist/Math/LibDecimal/index.js +3 -4
  50. package/dist/Misc/LibRegFormValidate/index.d.ts +9 -9
  51. package/dist/Misc/LibRegFormValidate/index.js +9 -9
  52. package/dist/Random/LibProbabilityResult/index.d.ts +3 -3
  53. package/dist/Random/LibProbabilityResult/index.js +3 -3
  54. package/dist/Random/LibRandom/index.d.ts +3 -4
  55. package/dist/Random/LibRandom/index.js +3 -4
  56. package/dist/Random/LibRandomColor/index.d.ts +2 -2
  57. package/dist/Random/LibRandomColor/index.js +2 -2
  58. package/dist/Random/LibUniqueRandomNumbers/index.d.ts +3 -3
  59. package/dist/Random/LibUniqueRandomNumbers/index.js +3 -3
  60. package/dist/Time/LibSameTimeCheck/index.d.ts +5 -1
  61. package/dist/Time/LibSameTimeCheck/index.js +5 -1
  62. package/dist/Time/LibTimeAgo/index.d.ts +4 -4
  63. package/dist/Time/LibTimeAgo/index.js +4 -4
  64. package/dist/Time/LibTimeGreeting/index.d.ts +5 -5
  65. package/dist/Time/LibTimeGreeting/index.js +5 -5
  66. package/dist/lib.d.ts +77 -78
  67. package/dist/lib.js +78 -79
  68. package/package.json +1 -1
  69. package/test/index.js +0 -0
package/dist/lib.js CHANGED
@@ -15,6 +15,7 @@ import { libStepArray } from "./Data/LibStepArray";
15
15
  import { libDownloadImageLink } from "./File/LibDownloadImageLink";
16
16
  import { libImageOptimizer } from "./File/LibImageOptimizer";
17
17
  import { libSaveJson } from "./File/LibSaveJson";
18
+ import { libSecondsFormatterChinese } from "./Formatter/LibSecondsFormatterChinese";
18
19
  import { libFormatterByte } from "./Formatter/LibFormatterByte";
19
20
  import { libMaskPhoneNumber } from "./Formatter/LibMaskPhoneNumber";
20
21
  import { libNumComma } from "./Formatter/LibNumComma";
@@ -31,7 +32,6 @@ import { libRandom } from "./Random/LibRandom";
31
32
  import { libRandomColor } from "./Random/LibRandomColor";
32
33
  import { libUniqueRandomNumbers } from "./Random/LibUniqueRandomNumbers";
33
34
  import { libSameTimeCheck } from "./Time/LibSameTimeCheck";
34
- import { libSecondsFormatterChinese } from "./Time/LibSecondsFormatterChinese";
35
35
  import { libTimeAgo } from "./Time/LibTimeAgo";
36
36
  import { libTimeGreeting } from "./Time/LibTimeGreeting";
37
37
  /** @description 基础方法 */
@@ -40,9 +40,9 @@ export const Base = {
40
40
  * @description 返回数据类型
41
41
  * @param v 需要判断类型的数据
42
42
  * @example
43
- * libGetDataType(123); // "number"
44
- * libGetDataType("hello"); // "string"
45
- * libGetDataType([1, 2, 3]); // "array"
43
+ * libGetDataType(123); //"number"
44
+ * libGetDataType("hello"); //"string"
45
+ * libGetDataType([1, 2, 3]); //"array"
46
46
  */
47
47
  libGetDataType,
48
48
  /**
@@ -63,29 +63,29 @@ export const Browser = {
63
63
  * @param color 颜色
64
64
  * @param logs 信息
65
65
  * @example
66
- * // 使用红色打印日志
66
+ * //使用红色打印日志
67
67
  * libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
68
68
  *
69
- * // 使用蓝色打印简单日志
69
+ * //使用蓝色打印简单日志
70
70
  * libColorConsole("信息", "blue", "操作成功");
71
71
  */
72
72
  libColorConsole,
73
73
  /** @description 判断是否为移动设备
74
74
  * @example
75
75
  * const isMobile = libIsMobile();
76
- * console.log(isMobile); // true 或 false
76
+ * console.log(isMobile); //true 或 false
77
77
  */
78
78
  libIsMobile,
79
79
  /** @description 判断是否为平板
80
80
  * @example
81
81
  * const isPad = libIsPad();
82
- * console.log(isPad); // true 或 false
82
+ * console.log(isPad); //true 或 false
83
83
  */
84
84
  libIsPad,
85
85
  /** @description 获取浏览器地址栏参数
86
86
  * @example
87
87
  * const params = libPathParams();
88
- * console.log(params); // { param1: "value1", param2: "value2" }
88
+ * console.log(params); //{ param1: "value1", param2: "value2" }
89
89
  */
90
90
  libPathParams,
91
91
  /** @description 动态设置网站标题及图标
@@ -111,23 +111,23 @@ export const Data = {
111
111
  * @param chunkSize 每个数组的元素数量
112
112
  * @example
113
113
  * const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
114
- * console.log(chunks); // [[1, 2], [3, 4], [5, 6]]
114
+ * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
115
115
  */
116
116
  libChunkArray,
117
117
  /** @description 递归将JSON字符串深度解析为对象
118
118
  * @example
119
119
  * const obj = libDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
120
- * console.log(obj); // { a: 1, b: { c: 2 } }
120
+ * console.log(obj); //{ a: 1, b: { c: 2 } }
121
121
  */
122
122
  libDeepJSONParse,
123
123
  /**
124
124
  * @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
125
- * @param arr 要分组的数组。
126
- * @param key 分组的键。
127
- * @returns 分组后的对象。
125
+ * @param arr 要分组的数组
126
+ * @param key 分组的键
127
+ * @returns 分组后的对象
128
128
  * @example
129
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' }] }
130
+ * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
131
131
  */
132
132
  libGroupArrayByKey,
133
133
  /**
@@ -137,14 +137,14 @@ export const Data = {
137
137
  * @returns 匹配结果数组
138
138
  * @example
139
139
  * const emails = libMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
140
- * console.log(emails); // ["user@gmail.com", "user@yahoo.com"]
140
+ * console.log(emails); //["user@gmail.com", "user@yahoo.com"]
141
141
  */
142
142
  libMatchEmail,
143
143
  /** @description 数组乱序
144
144
  * @param arr 需要乱序的数组
145
145
  * @example
146
146
  * const shuffled = libShuffleArray([1, 2, 3, 4, 5]);
147
- * console.log(shuffled); // [3, 5, 2, 1, 4] (结果每次不同)
147
+ * console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
148
148
  */
149
149
  libShuffleArray,
150
150
  /** @description 数组元素整体步数移动
@@ -152,7 +152,7 @@ export const Data = {
152
152
  * @param step 负数为向后移动,正数为向前移动
153
153
  * @example
154
154
  * const moved = libStepArray([1, 2, 3, 4, 5], 2);
155
- * console.log(moved); // [4, 5, 1, 2, 3]
155
+ * console.log(moved); //[4, 5, 1, 2, 3]
156
156
  */
157
157
  libStepArray,
158
158
  };
@@ -168,7 +168,7 @@ export const File = {
168
168
  /** @description 图片压缩
169
169
  * @param obj 压缩参数
170
170
  * @example
171
- * // 图片压缩使用示例
171
+ * //图片压缩使用示例
172
172
  * libImageOptimizerOptionsParams({
173
173
  * file: myFile,
174
174
  * ratio: 0.8,
@@ -200,15 +200,15 @@ export const Formatter = {
200
200
  * @returns ['大小', '单位', '大小及单位']
201
201
  * @example
202
202
  * const [size, unit, formatted] = libFormatterByte(2048);
203
- * console.log(size, unit, formatted); // 2.00 KB 2.00 KB
203
+ * console.log(size, unit, formatted); //2.00 KB 2.00 KB
204
204
  */
205
205
  libFormatterByte,
206
206
  /**
207
- * @description 隐藏手机号码中间的四位数字。
208
- * @param mobile 需要处理的手机号码。
207
+ * @description 隐藏手机号码中间的四位数字
208
+ * @param mobile 需要处理的手机号码
209
209
  * @example
210
210
  * const masked = libMaskPhoneNumber("13812345678");
211
- * console.log(masked); // 138****5678
211
+ * console.log(masked); //138****5678
212
212
  */
213
213
  libMaskPhoneNumber,
214
214
  /**
@@ -217,7 +217,7 @@ export const Formatter = {
217
217
  * @param reserve 保留小数位数
218
218
  * @example
219
219
  * const formatted = libNumComma(1234567.89);
220
- * console.log(formatted); // 1,234,567.89
220
+ * console.log(formatted); //1,234,567.89
221
221
  */
222
222
  libNumComma,
223
223
  /** @description 将大于1000的数字使用k为单位
@@ -226,9 +226,20 @@ export const Formatter = {
226
226
  * @returns [数字, 单位]
227
227
  * @example
228
228
  * const [value, unit] = libNumberUnit(1500, { K: 1000, M: 1000000 });
229
- * console.log(value, unit); // 1.50 K
229
+ * console.log(value, unit); //1.50 K
230
230
  */
231
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,
232
243
  };
233
244
  /** @description 数学相关方法 */
234
245
  export const Math = {
@@ -239,7 +250,7 @@ export const Math = {
239
250
  *
240
251
  * @example
241
252
  * const result = libCalculateExpression("(1+2)-(3*4)/5");
242
- * console.log(result); // 0.6
253
+ * console.log(result); //0.6
243
254
  */
244
255
  libCalculateExpression,
245
256
  /**
@@ -247,29 +258,29 @@ export const Math = {
247
258
  * @param value 角度值或弧度值
248
259
  * @param type 角度类型或弧度类型
249
260
  * @example
250
- * // 角度转弧度
251
- * libConvertAngle(90, "rad"); // 返回 1.5708... (π/2)
261
+ * //角度转弧度
262
+ * libConvertAngle(90, "rad"); //返回 1.5708... (π/2)
252
263
  *
253
- * // 弧度转角度
254
- * libConvertAngle(Math.PI, "deg"); // 返回 180
264
+ * //弧度转角度
265
+ * libConvertAngle(Math.PI, "deg"); //返回 180
255
266
  */
256
267
  libConvertAngle,
257
268
  /** @description 计算两点角度
258
269
  * @param coord1 起点坐标
259
270
  * @param coord2 终点坐标
260
271
  * @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
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
264
275
  */
265
276
  libCoordsAngle,
266
277
  /** @description 计算两点距离
267
278
  * @param coord1 起点坐标
268
279
  * @param coord2 终点坐标
269
280
  * @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
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
273
284
  */
274
285
  libCoordsDistance,
275
286
  /** @description 计算两个数的运算结果,并保留指定位数的小数
@@ -277,20 +288,19 @@ export const Math = {
277
288
  * @param num2 第二个数
278
289
  * @param operator 运算符,支持加减乘除
279
290
  * @example
280
- * // 示例用法
281
- * libDecimal(10, 3, "+"); // 13
282
- * libDecimal(10, 3, "-"); // 7
283
- * libDecimal(10, 3, "/", 2); // 3.33
291
+ * libDecimal(10, 3, "+"); //13
292
+ * libDecimal(10, 3, "-"); //7
293
+ * libDecimal(10, 3, "/", 2); //3.33
284
294
  */
285
295
  libDecimal,
286
296
  };
287
297
  /** @description 杂项相关方法 */
288
298
  export const Misc = {
289
299
  /**
290
- * @description 表单验证函数。
291
- * @param form 表单数据对象。
292
- * @param rules 验证规则数组。
293
- * @returns 验证结果数组,包含未通过验证的项。
300
+ * @description 表单验证函数
301
+ * @param form 表单数据对象
302
+ * @param rules 验证规则数组
303
+ * @returns 验证结果数组,包含未通过验证的项
294
304
  * @example
295
305
  * const form = { username: "john", email: "john@example.com" };
296
306
  * const rules = [
@@ -298,14 +308,14 @@ export const Misc = {
298
308
  * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
299
309
  * ];
300
310
  * libRegFormValidate(form, rules);
301
- * // 返回结果: []
311
+ * //返回结果: []
302
312
  *
303
313
  * const invalidForm = { username: "jo", email: "invalid-email" };
304
314
  * libRegFormValidate(invalidForm, rules);
305
- * // 返回结果: [
306
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
307
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
308
- * // ]
315
+ * //返回结果: [
316
+ * // { key: "username", msg: "用户名不合法", name: "用户名" },
317
+ * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
318
+ * //]
309
319
  */
310
320
  libRegFormValidate,
311
321
  /** @description 请求失败重连
@@ -332,9 +342,9 @@ export const Random = {
332
342
  /** @description 百分比概率结果
333
343
  * @param probability 触发概率,百分比,0-100
334
344
  * @example
335
- * libProbabilityResult(50); // 50% 概率为 true
336
- * libProbabilityResult(80); // 80% 概率为 true
337
- * libProbabilityResult(100); // 100% 概率为 true
345
+ * libProbabilityResult(50); //50% 概率为 true
346
+ * libProbabilityResult(80); //80% 概率为 true
347
+ * libProbabilityResult(100); //100% 概率为 true
338
348
  */
339
349
  libProbabilityResult,
340
350
  /** @description 随机数
@@ -342,16 +352,16 @@ export const Random = {
342
352
  * @param max 最大值
343
353
  * @param num 保留小数位数
344
354
  * @example
345
- * libRandom(1, 10); // 1 到 10 之间的随机整数
346
- * libRandom(1, 10, 2); // 1 到 10 之间保留两位小数的随机数
347
- * libRandom(5, 5, 3); // 返回 5.000
355
+ * libRandom(1, 10); //1 到 10 之间的随机整数
356
+ * libRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
357
+ * libRandom(5, 5, 3); //返回 5.000
348
358
  */
349
359
  libRandom,
350
360
  /** @description 随机 RGBA 颜色
351
361
  * @param alpha 透明度
352
362
  * @example
353
- * libRandomColor(); // 生成随机的 RGBA 颜色,默认透明度 1
354
- * libRandomColor(0.5); // 生成随机的 RGBA 颜色,透明度为 0.5
363
+ * libRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
364
+ * libRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
355
365
  */
356
366
  libRandomColor,
357
367
  /** @description 随机生成n个指定范围的随机数数组
@@ -359,8 +369,8 @@ export const Random = {
359
369
  * @param max 最大值
360
370
  * @param count 数组长度
361
371
  * @example
362
- * libUniqueRandomNumbers(1, 10, 5); // 1 到 10 中随机生成 5 个唯一数字
363
- * libUniqueRandomNumbers(1, 100, 10); // 1 到 100 中随机生成 10 个唯一数字
372
+ * libUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
373
+ * libUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
364
374
  */
365
375
  libUniqueRandomNumbers,
366
376
  };
@@ -373,33 +383,22 @@ export const Time = {
373
383
  * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
374
384
  */
375
385
  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
386
  /** @description 时间差计算
388
387
  * @param timestamp 毫秒时间戳
389
388
  * @example
390
- * libTimeAgotamp(Date.now() - 3600000); // "1 小时前"
391
- * libTimeAgotamp(Date.now() - 86400000); // "1 天前"
392
- * libTimeAgotamp(Date.now() - 31536000000); // "1 年前"
393
- * libTimeAgotamp(Date.now() - 10000); // "刚刚"
389
+ * libTimeAgotamp(Date.now() - 3600000); //"1 小时前"
390
+ * libTimeAgotamp(Date.now() - 86400000); //"1 天前"
391
+ * libTimeAgotamp(Date.now() - 31536000000); //"1 年前"
392
+ * libTimeAgotamp(Date.now() - 10000); //"刚刚"
394
393
  */
395
394
  libTimeAgo,
396
395
  /**
397
- * @description 根据当前时间返回问候语。
398
- * @param greet 自定义问候语对象。
396
+ * @description 根据当前时间返回问候语
397
+ * @param greet 自定义问候语对象
399
398
  * @example
400
- * libTimeGreeting(); // 根据当前时间返回默认问候语
401
- * libTimeGreeting({ morning: "早安" }); // 自定义早上问候语
402
- * libTimeGreeting({ afternoon: "午后好" }); // 自定义下午问候语
399
+ * libTimeGreeting(); //根据当前时间返回默认问候语
400
+ * libTimeGreeting({ morning: "早安" }); //自定义早上问候语
401
+ * libTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
403
402
  */
404
403
  libTimeGreeting,
405
404
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "author": "冷弋白",
5
5
  "description": "lyb自用JS方法库",
6
6
  "repository": {
package/test/index.js DELETED
File without changes