lyb-js 1.1.0 → 1.1.2

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 (83) hide show
  1. package/README.md +47 -4
  2. package/dist/Base/LibJsGetDataType/index.d.ts +1 -0
  3. package/dist/Base/LibJsGetDataType/index.js +1 -0
  4. package/dist/Base/LibJsPromiseTimeout/index.d.ts +1 -0
  5. package/dist/Base/LibJsPromiseTimeout/index.js +1 -0
  6. package/dist/Browser/LibJsColorConsole/index.d.ts +1 -0
  7. package/dist/Browser/LibJsColorConsole/index.js +1 -0
  8. package/dist/Browser/LibJsIsMobile/index.d.ts +1 -0
  9. package/dist/Browser/LibJsIsMobile/index.js +1 -0
  10. package/dist/Browser/LibJsIsPad/index.d.ts +1 -0
  11. package/dist/Browser/LibJsIsPad/index.js +1 -0
  12. package/dist/Browser/LibJsObjToUrlParams/index.d.ts +8 -0
  13. package/dist/Browser/LibJsObjToUrlParams/index.js +12 -0
  14. package/dist/Browser/LibJsPathParams/index.d.ts +1 -0
  15. package/dist/Browser/LibJsPathParams/index.js +1 -0
  16. package/dist/Browser/LibJsSetTitleIcon/index.d.ts +1 -0
  17. package/dist/Browser/LibJsSetTitleIcon/index.js +1 -0
  18. package/dist/Browser/LibJsTagTitleTip/index.d.ts +1 -0
  19. package/dist/Browser/LibJsTagTitleTip/index.js +1 -0
  20. package/dist/Data/LibJsChunkArray/index.d.ts +1 -0
  21. package/dist/Data/LibJsChunkArray/index.js +1 -0
  22. package/dist/Data/LibJsDeepJSONParse/index.d.ts +1 -0
  23. package/dist/Data/LibJsDeepJSONParse/index.js +1 -0
  24. package/dist/Data/LibJsGroupArrayByKey/index.d.ts +1 -0
  25. package/dist/Data/LibJsGroupArrayByKey/index.js +1 -0
  26. package/dist/Data/LibJsMatchEmail/index.d.ts +1 -0
  27. package/dist/Data/LibJsMatchEmail/index.js +1 -0
  28. package/dist/Data/LibJsShuffleArray/index.d.ts +1 -0
  29. package/dist/Data/LibJsShuffleArray/index.js +1 -0
  30. package/dist/Data/LibJsStepArray/index.d.ts +2 -1
  31. package/dist/Data/LibJsStepArray/index.js +2 -1
  32. package/dist/Data/LibReverseArrayFromIndex/index.d.ts +9 -0
  33. package/dist/Data/LibReverseArrayFromIndex/index.js +15 -0
  34. package/dist/File/LibJsDownloadImageLink/index.d.ts +1 -0
  35. package/dist/File/LibJsDownloadImageLink/index.js +1 -0
  36. package/dist/File/LibJsImageOptimizer/index.d.ts +1 -0
  37. package/dist/File/LibJsImageOptimizer/index.js +1 -0
  38. package/dist/File/LibJsSaveJson/index.d.ts +5 -4
  39. package/dist/File/LibJsSaveJson/index.js +5 -4
  40. package/dist/Formatter/LibJsFormatterByte/index.d.ts +1 -0
  41. package/dist/Formatter/LibJsFormatterByte/index.js +1 -0
  42. package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +2 -1
  43. package/dist/Formatter/LibJsMaskPhoneNumber/index.js +2 -1
  44. package/dist/Formatter/LibJsNumComma/index.d.ts +1 -0
  45. package/dist/Formatter/LibJsNumComma/index.js +1 -0
  46. package/dist/Formatter/LibJsNumberUnit/index.d.ts +1 -0
  47. package/dist/Formatter/LibJsNumberUnit/index.js +1 -0
  48. package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +1 -0
  49. package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +1 -0
  50. package/dist/Math/LibJsCalculateExpression/index.d.ts +1 -0
  51. package/dist/Math/LibJsCalculateExpression/index.js +1 -0
  52. package/dist/Math/LibJsConvertAngle/index.d.ts +1 -0
  53. package/dist/Math/LibJsConvertAngle/index.js +1 -0
  54. package/dist/Math/LibJsCoordsAngle/index.d.ts +1 -0
  55. package/dist/Math/LibJsCoordsAngle/index.js +1 -0
  56. package/dist/Math/LibJsCoordsDistance/index.d.ts +1 -0
  57. package/dist/Math/LibJsCoordsDistance/index.js +1 -0
  58. package/dist/Math/LibJsDecimal/index.d.ts +1 -0
  59. package/dist/Math/LibJsDecimal/index.js +1 -0
  60. package/dist/Misc/LibJsRegFormValidate/index.d.ts +1 -0
  61. package/dist/Misc/LibJsRegFormValidate/index.js +1 -0
  62. package/dist/Misc/LibJsRetryRequest/index.d.ts +1 -0
  63. package/dist/Misc/LibJsRetryRequest/index.js +1 -0
  64. package/dist/Misc/LibNumerStepper/index.d.ts +35 -0
  65. package/dist/Misc/LibNumerStepper/index.js +70 -0
  66. package/dist/Random/LibJsProbabilityResult/index.d.ts +1 -0
  67. package/dist/Random/LibJsProbabilityResult/index.js +1 -0
  68. package/dist/Random/LibJsRandom/index.d.ts +2 -1
  69. package/dist/Random/LibJsRandom/index.js +2 -1
  70. package/dist/Random/LibJsRandomColor/index.d.ts +1 -0
  71. package/dist/Random/LibJsRandomColor/index.js +1 -0
  72. package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +1 -0
  73. package/dist/Random/LibJsUniqueRandomNumbers/index.js +1 -0
  74. package/dist/Time/LibJsSameTimeCheck/index.d.ts +1 -0
  75. package/dist/Time/LibJsSameTimeCheck/index.js +1 -0
  76. package/dist/Time/LibJsTimeAgo/index.d.ts +1 -0
  77. package/dist/Time/LibJsTimeAgo/index.js +1 -0
  78. package/dist/Time/LibJsTimeGreeting/index.d.ts +1 -0
  79. package/dist/Time/LibJsTimeGreeting/index.js +1 -0
  80. package/dist/libJs.d.ts +65 -3
  81. package/dist/libJs.js +66 -2
  82. package/package.json +8 -5
  83. package/umd/lib.js +8 -0
package/README.md CHANGED
@@ -8,7 +8,15 @@
8
8
 
9
9
  ## 起步
10
10
 
11
- > 完整使用
11
+ **通过 `CDN ` 使用 `LibJs`**
12
+
13
+ > 你可以借助 script 标签直接通过 CDN 来使用 LibJs:
14
+
15
+ ```ts
16
+ <script src="https://unpkg.com/lyb-js@1.1.1/dist/Lib.js"></script>
17
+ ```
18
+
19
+
12
20
 
13
21
  ```ts
14
22
  import { LibJs } from "lib-js-utils";
@@ -61,6 +69,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
61
69
 
62
70
  \- [LibJsTagTitleTip-网站标题交互](#LibJsTagTitleTip-网站标题交互)
63
71
 
72
+ \- [LibJsObjToUrlParams-对象转Url参数](#LibJsObjToUrlParams-对象转Url参数)
73
+
64
74
 
65
75
  ### Data-数据
66
76
 
@@ -76,6 +86,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
76
86
 
77
87
  \- [LibJsStepArray-数组偏移](#LibJsStepArray-数组偏移)
78
88
 
89
+ \- [LibReverseArrayFromIndex-数组定位翻转](#LibReverseArrayFromIndex-数组定位翻转)
90
+
79
91
 
80
92
  ### File-文件
81
93
 
@@ -117,6 +129,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
117
129
 
118
130
  \- [LibJsRetryRequest-请求重连](#LibJsRetryRequest-请求重连)
119
131
 
132
+ \- [LibNumerStepper-数字步进器](#LibNumerStepper-数字步进器)
133
+
120
134
 
121
135
  ### Random-随机
122
136
 
@@ -217,6 +231,15 @@ libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
217
231
  libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
218
232
  ```
219
233
 
234
+ ### LibJsObjToUrlParams-对象转Url参数
235
+
236
+ > 将对象转为地址栏参数
237
+
238
+ ```js
239
+ libJsObjToParams({ name: "John", age: 30, active: true });
240
+ // "name=John&age=30&active=true"
241
+ ```
242
+
220
243
  ## Data-数据
221
244
 
222
245
  ### LibJsChunkArray-数组拆分
@@ -273,6 +296,15 @@ const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
273
296
  console.log(moved); //[4, 5, 1, 2, 3]
274
297
  ```
275
298
 
299
+ ### LibReverseArrayFromIndex-数组定位翻转
300
+
301
+ > 翻转指定索引后面的数组
302
+
303
+ ```ts
304
+ libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
305
+ // [1, 2, 5, 4, 3]
306
+ ```
307
+
276
308
  ## File-文件
277
309
 
278
310
  ### LibJsDownloadImageLink-图片下载
@@ -308,8 +340,8 @@ libJsImageOptimizerOptionsParams({
308
340
  > 保存`JSON`文件到本地,也支持保存纯文本的`txt`文件
309
341
 
310
342
  ```ts
311
- libJsSaveJson(JSON.stringify({ key: "value" }), "example.json");、
312
- libJsSaveJson("Hellow World!", "example.txt");
343
+ libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
344
+ libJsSaveJson("example.txt", "Hellow World!");
313
345
  ```
314
346
 
315
347
  ## Formatter-格式化
@@ -417,7 +449,7 @@ libJsDecimal(10, 3, "-"); //7
417
449
  libJsDecimal(10, 3, "/", 2); //3.33
418
450
  ```
419
451
 
420
- ## Misc
452
+ ## Misc-杂项
421
453
 
422
454
  ### LibJsRegFormValidate-表单验证
423
455
 
@@ -457,6 +489,17 @@ libJsRetryRequest({
457
489
  .catch(err => console.error(err));
458
490
  ```
459
491
 
492
+ ### LibNumerStepper-数字步进器
493
+
494
+ > 通过调用方法来增加和减少数字索引
495
+
496
+ ```ts
497
+ const stepper = new libNumerStepper(10, (index) => console.log(index));
498
+ stepper.down("add"); // 索引加1
499
+ stepper.updateIndex(5); // 更新索引为5
500
+ stepper.down("sub"); // 索引减1
501
+ ```
502
+
460
503
  ## Random-随机
461
504
 
462
505
  ### LibJsProbabilityResult-概率触发
@@ -2,6 +2,7 @@ export type LibJsGetDataTypeReturnType = "string" | "number" | "boolean" | "arra
2
2
  /**
3
3
  * @description 返回数据类型
4
4
  * @param v 需要判断类型的数据
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * libJsGetDataType(123); //"number"
7
8
  * libJsGetDataType("hello"); //"string"
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @description 返回数据类型
3
3
  * @param v 需要判断类型的数据
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsGetDataType(123); //"number"
6
7
  * libJsGetDataType("hello"); //"string"
@@ -2,6 +2,7 @@
2
2
  * @description 延时执行,切换到其他页面会暂停
3
3
  * @param delay 延时毫秒数
4
4
  * @param fn 延时执行函数
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * libJsPromiseTimeout(3000, () => {
7
8
  * console.log("执行延时函数");
@@ -2,6 +2,7 @@
2
2
  * @description 延时执行,切换到其他页面会暂停
3
3
  * @param delay 延时毫秒数
4
4
  * @param fn 延时执行函数
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * libJsPromiseTimeout(3000, () => {
7
8
  * console.log("执行延时函数");
@@ -2,6 +2,7 @@
2
2
  * @param title 标题
3
3
  * @param color 颜色
4
4
  * @param logs 信息
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * //使用红色打印日志
7
8
  * libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
@@ -2,6 +2,7 @@
2
2
  * @param title 标题
3
3
  * @param color 颜色
4
4
  * @param logs 信息
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * //使用红色打印日志
7
8
  * libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
@@ -1,4 +1,5 @@
1
1
  /** @description 判断是否为移动设备
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const isMobile = libIsMobile();
4
5
  * console.log(isMobile); //true 或 false
@@ -1,4 +1,5 @@
1
1
  /** @description 判断是否为移动设备
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const isMobile = libIsMobile();
4
5
  * console.log(isMobile); //true 或 false
@@ -1,4 +1,5 @@
1
1
  /** @description 判断是否为平板
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const isPad = libJsIsPad();
4
5
  * console.log(isPad); //true 或 false
@@ -1,4 +1,5 @@
1
1
  /** @description 判断是否为平板
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const isPad = libJsIsPad();
4
5
  * console.log(isPad); //true 或 false
@@ -0,0 +1,8 @@
1
+ /** @description 将对象转为地址栏参数
2
+ * @param params 对象参数
3
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
+ * @example
5
+ * libJsObjToUrlParams({ name: "John", age: 30, active: true });
6
+ * // "name=John&age=30&active=true"
7
+ */
8
+ export declare const libJsObjToUrlParams: (params: Record<string, string | number | boolean>) => string;
@@ -0,0 +1,12 @@
1
+ /** @description 将对象转为地址栏参数
2
+ * @param params 对象参数
3
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
+ * @example
5
+ * libJsObjToUrlParams({ name: "John", age: 30, active: true });
6
+ * // "name=John&age=30&active=true"
7
+ */
8
+ export const libJsObjToUrlParams = (params) => {
9
+ return Object.entries(params)
10
+ .map(([key, value]) => `${key}=${value}`)
11
+ .join("&");
12
+ };
@@ -1,4 +1,5 @@
1
1
  /** @description 获取浏览器地址栏参数
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const params = libJsPathParams();
4
5
  * console.log(params); //{ param1: "value1", param2: "value2" }
@@ -1,4 +1,5 @@
1
1
  /** @description 获取浏览器地址栏参数
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const params = libJsPathParams();
4
5
  * console.log(params); //{ param1: "value1", param2: "value2" }
@@ -1,6 +1,7 @@
1
1
  /** @description 动态设置网站标题及图标
2
2
  * @param title 网站标题
3
3
  * @param url 网站图标地址
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
7
  */
@@ -1,6 +1,7 @@
1
1
  /** @description 动态设置网站标题及图标
2
2
  * @param title 网站标题
3
3
  * @param url 网站图标地址
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
7
  */
@@ -1,6 +1,7 @@
1
1
  /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
2
  * @param backTitle 从其他网页返回时显示的标题
3
3
  * @param leaveTitle 从当前网页离开时显示的标题
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
7
  */
@@ -1,6 +1,7 @@
1
1
  /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
2
  * @param backTitle 从其他网页返回时显示的标题
3
3
  * @param leaveTitle 从当前网页离开时显示的标题
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
7
  */
@@ -2,6 +2,7 @@
2
2
  * @description 将数组拆分成指定数组元素数量的多个数组
3
3
  * @param arr 需要拆分的数组
4
4
  * @param chunkSize 每个数组的元素数量
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
7
8
  * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
@@ -2,6 +2,7 @@
2
2
  * @description 将数组拆分成指定数组元素数量的多个数组
3
3
  * @param arr 需要拆分的数组
4
4
  * @param chunkSize 每个数组的元素数量
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
7
8
  * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
@@ -1,4 +1,5 @@
1
1
  /** @description 递归将JSON字符串深度解析为对象
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
4
5
  * console.log(obj); //{ a: 1, b: { c: 2 } }
@@ -1,4 +1,5 @@
1
1
  /** @description 递归将JSON字符串深度解析为对象
2
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
2
3
  * @example
3
4
  * const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
4
5
  * console.log(obj); //{ a: 1, b: { c: 2 } }
@@ -3,6 +3,7 @@
3
3
  * @param arr 要分组的数组
4
4
  * @param key 分组的键
5
5
  * @returns 分组后的对象
6
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
7
  * @example
7
8
  * const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
8
9
  * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
@@ -3,6 +3,7 @@
3
3
  * @param arr 要分组的数组
4
4
  * @param key 分组的键
5
5
  * @returns 分组后的对象
6
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
7
  * @example
7
8
  * const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
8
9
  * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
@@ -3,6 +3,7 @@
3
3
  * @param str 要匹配的字符串
4
4
  * @param emailList 电子邮件后缀列表
5
5
  * @returns 匹配结果数组
6
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
7
  * @example
7
8
  * const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
8
9
  * console.log(emails); //["user@gmail.com", "user@yahoo.com"]
@@ -3,6 +3,7 @@
3
3
  * @param str 要匹配的字符串
4
4
  * @param emailList 电子邮件后缀列表
5
5
  * @returns 匹配结果数组
6
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
7
  * @example
7
8
  * const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
8
9
  * console.log(emails); //["user@gmail.com", "user@yahoo.com"]
@@ -1,5 +1,6 @@
1
1
  /** @description 将数组打乱顺序
2
2
  * @param arr 需要乱序的数组
3
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
3
4
  * @example
4
5
  * const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
5
6
  * console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
@@ -1,5 +1,6 @@
1
1
  /** @description 将数组打乱顺序
2
2
  * @param arr 需要乱序的数组
3
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
3
4
  * @example
4
5
  * const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
5
6
  * console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
@@ -1,7 +1,8 @@
1
1
  /** @description 数组元素整体步数移动
2
2
  * @param arr 移动的数组
3
3
  * @param step 负数为向后移动,正数为向前移动
4
- * @example
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
+ * @example
5
6
  * const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
6
7
  * console.log(moved); //[4, 5, 1, 2, 3]
7
8
  */
@@ -1,7 +1,8 @@
1
1
  /** @description 数组元素整体步数移动
2
2
  * @param arr 移动的数组
3
3
  * @param step 负数为向后移动,正数为向前移动
4
- * @example
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
+ * @example
5
6
  * const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
6
7
  * console.log(moved); //[4, 5, 1, 2, 3]
7
8
  */
@@ -0,0 +1,9 @@
1
+ /** @description 翻转指定索引后面的数组
2
+ * @param arr 数组
3
+ * @param index 开始索引
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
+ * @example
6
+ * libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
7
+ * // [1, 2, 5, 4, 3]
8
+ */
9
+ export declare const libReverseArrayFromIndex: <T>(arr: T[], index: number) => T[];
@@ -0,0 +1,15 @@
1
+ /** @description 翻转指定索引后面的数组
2
+ * @param arr 数组
3
+ * @param index 开始索引
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
+ * @example
6
+ * libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
7
+ * // [1, 2, 5, 4, 3]
8
+ */
9
+ export const libReverseArrayFromIndex = (arr, index) => {
10
+ if (index < 0 || index >= arr.length) {
11
+ throw new Error("Index out of bounds");
12
+ }
13
+ const subArray = arr.slice(index + 1).reverse();
14
+ return [...arr.slice(0, index + 1), ...subArray];
15
+ };
@@ -1,6 +1,7 @@
1
1
  /** @description 将链接图片下载到本地
2
2
  * @param link 图片链接
3
3
  * @param name 图片名称
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsDownloadImageLink("https://example.com/image.jpg", "图片.jpg");
6
7
  */
@@ -1,6 +1,7 @@
1
1
  /** @description 将链接图片下载到本地
2
2
  * @param link 图片链接
3
3
  * @param name 图片名称
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsDownloadImageLink("https://example.com/image.jpg", "图片.jpg");
6
7
  */
@@ -14,6 +14,7 @@ export type LibJsImageOptimizerOptionsParams = {
14
14
  };
15
15
  /** @description 图片压缩,支持png压缩,保留透明背景
16
16
  * @param obj 压缩参数
17
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
17
18
  * @example
18
19
  * libJsImageOptimizerOptionsParams({
19
20
  * file: myFile,
@@ -1,5 +1,6 @@
1
1
  /** @description 图片压缩,支持png压缩,保留透明背景
2
2
  * @param obj 压缩参数
3
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
3
4
  * @example
4
5
  * libJsImageOptimizerOptionsParams({
5
6
  * file: myFile,
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * @description 保存文件到本地
3
- * @param data 要保存的数据
4
3
  * @param name 文件名
4
+ * @param data 要保存的数据
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
- * libJsSaveJson(JSON.stringify({ key: "value" }), "example.json");
7
- * libJsSaveJson("Hellow World!", "example.txt");
7
+ * libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
8
+ * libJsSaveJson("example.txt", "Hellow World!");
8
9
  */
9
- export declare const libJsSaveJson: (data: BlobPart, name: string) => void;
10
+ export declare const libJsSaveJson: (name: string, data: BlobPart) => void;
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * @description 保存文件到本地
3
- * @param data 要保存的数据
4
3
  * @param name 文件名
4
+ * @param data 要保存的数据
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
- * libJsSaveJson(JSON.stringify({ key: "value" }), "example.json");
7
- * libJsSaveJson("Hellow World!", "example.txt");
7
+ * libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
8
+ * libJsSaveJson("example.txt", "Hellow World!");
8
9
  */
9
- export const libJsSaveJson = (data, name) => {
10
+ export const libJsSaveJson = (name, data) => {
10
11
  const urlObject = window.URL || window.webkitURL;
11
12
  const exportBlob = new Blob([data]);
12
13
  const saveLink = document.createElement("a");
@@ -2,6 +2,7 @@
2
2
  * @description 格式化字节大小
3
3
  * @param bytes 字节数
4
4
  * @returns ['大小', '单位', '大小及单位']
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const [size, unit, formatted] = libJsFormatterByte(2048);
7
8
  * console.log(size, unit, formatted); //2.00 KB 2.00 KB
@@ -2,6 +2,7 @@
2
2
  * @description 格式化字节大小
3
3
  * @param bytes 字节数
4
4
  * @returns ['大小', '单位', '大小及单位']
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const [size, unit, formatted] = libJsFormatterByte(2048);
7
8
  * console.log(size, unit, formatted); //2.00 KB 2.00 KB
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @description 隐藏手机号码中间的四位数字
3
3
  * @param mobile 需要处理的手机号码
4
- * @example
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
+ * @example
5
6
  * const masked = libJsMaskPhoneNumber("13812345678");
6
7
  * console.log(masked); //138****5678
7
8
  */
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @description 隐藏手机号码中间的四位数字
3
3
  * @param mobile 需要处理的手机号码
4
- * @example
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
+ * @example
5
6
  * const masked = libJsMaskPhoneNumber("13812345678");
6
7
  * console.log(masked); //138****5678
7
8
  */
@@ -2,6 +2,7 @@
2
2
  * @description 数字每三位添加逗号
3
3
  * @param num 需要格式化的数字
4
4
  * @param reserve 保留小数位数
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const formatted = libJsNumComma(1234567.89);
7
8
  * console.log(formatted); //1,234,567.89
@@ -2,6 +2,7 @@
2
2
  * @description 数字每三位添加逗号
3
3
  * @param num 需要格式化的数字
4
4
  * @param reserve 保留小数位数
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const formatted = libJsNumComma(1234567.89);
7
8
  * console.log(formatted); //1,234,567.89
@@ -5,6 +5,7 @@ export interface LibJsNumberUnitParams {
5
5
  * @param num 数字
6
6
  * @param units 单位组,key为单位,value为格式化阈值
7
7
  * @returns [数字, 单位]
8
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
8
9
  * @example
9
10
  * const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
10
11
  * console.log(value, unit); //1.50 K
@@ -3,6 +3,7 @@ import Decimal from "decimal.js";
3
3
  * @param num 数字
4
4
  * @param units 单位组,key为单位,value为格式化阈值
5
5
  * @returns [数字, 单位]
6
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
7
  * @example
7
8
  * const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
8
9
  * console.log(value, unit); //1.50 K
@@ -2,6 +2,7 @@
2
2
  * @description 将秒数格式化为中文时间描述,支持扩展到年
3
3
  * @param seconds 秒数
4
4
  * @returns 格式化后的中文时间
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
7
8
  * libJsSecondsFormatterChinese(31536000); //"1年"
@@ -5,6 +5,7 @@ dayjs.extend(duration);
5
5
  * @description 将秒数格式化为中文时间描述,支持扩展到年
6
6
  * @param seconds 秒数
7
7
  * @returns 格式化后的中文时间
8
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
8
9
  * @example
9
10
  * libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
10
11
  * libJsSecondsFormatterChinese(31536000); //"1年"
@@ -2,6 +2,7 @@
2
2
  * @param expression 表达式字符串
3
3
  * @param point 小数点精度
4
4
  * @returns 计算结果
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * const result = libJsCalculateExpression("(1+2)-(3*4)/5");
7
8
  * console.log(result); //0.6
@@ -3,6 +3,7 @@ import Decimal from 'decimal.js';
3
3
  * @param expression 表达式字符串
4
4
  * @param point 小数点精度
5
5
  * @returns 计算结果
6
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
7
  * @example
7
8
  * const result = libJsCalculateExpression("(1+2)-(3*4)/5");
8
9
  * console.log(result); //0.6
@@ -2,6 +2,7 @@
2
2
  * @description 角度和弧度互相转换
3
3
  * @param value 角度值或弧度值
4
4
  * @param type 角度类型或弧度类型
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * //角度转弧度
7
8
  * libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
@@ -2,6 +2,7 @@
2
2
  * @description 角度和弧度互相转换
3
3
  * @param value 角度值或弧度值
4
4
  * @param type 角度类型或弧度类型
5
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
6
  * @example
6
7
  * //角度转弧度
7
8
  * libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
@@ -1,6 +1,7 @@
1
1
  /** @description 计算两点角度
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
6
7
  * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
@@ -1,6 +1,7 @@
1
1
  /** @description 计算两点角度
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
6
7
  * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
@@ -1,6 +1,7 @@
1
1
  /** @description 计算两点距离
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
+ * @link 了解更多:https://www.npmjs.com/package/lyb-js
4
5
  * @example
5
6
  * libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
6
7
  * libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5