lyb-js 1.0.7 → 1.0.9

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 (96) hide show
  1. package/README.md +143 -144
  2. package/dist/Base/LibJsGetDataType/index.d.ts +10 -0
  3. package/dist/Base/{LibGetDataType → LibJsGetDataType}/index.js +4 -4
  4. package/dist/Base/{LibPromiseTimeout → LibJsPromiseTimeout}/index.d.ts +2 -2
  5. package/dist/Base/{LibPromiseTimeout → LibJsPromiseTimeout}/index.js +2 -2
  6. package/dist/Browser/LibJsColorConsole/index.d.ts +15 -0
  7. package/dist/Browser/{LibColorConsole → LibJsColorConsole}/index.js +3 -3
  8. package/dist/Browser/{LibIsMobile → LibJsIsMobile}/index.d.ts +1 -1
  9. package/dist/Browser/{LibIsMobile → LibJsIsMobile}/index.js +1 -1
  10. package/dist/Browser/{LibIsPad → LibJsIsPad}/index.d.ts +2 -2
  11. package/dist/Browser/{LibIsPad → LibJsIsPad}/index.js +2 -2
  12. package/dist/Browser/{LibPathParams → LibJsPathParams}/index.d.ts +2 -2
  13. package/dist/Browser/{LibPathParams → LibJsPathParams}/index.js +2 -2
  14. package/dist/Browser/LibJsSetTitleIcon/index.d.ts +7 -0
  15. package/dist/Browser/{LibSetTitleIcon → LibJsSetTitleIcon}/index.js +2 -2
  16. package/dist/Browser/{LibTagTitleTip → LibJsTagTitleTip}/index.d.ts +3 -3
  17. package/dist/Browser/{LibTagTitleTip → LibJsTagTitleTip}/index.js +3 -3
  18. package/dist/Data/{LibChunkArray → LibJsChunkArray}/index.d.ts +2 -2
  19. package/dist/Data/{LibChunkArray → LibJsChunkArray}/index.js +2 -2
  20. package/dist/Data/LibJsDeepJSONParse/index.d.ts +6 -0
  21. package/dist/Data/{LibDeepJSONParse → LibJsDeepJSONParse}/index.js +5 -5
  22. package/dist/Data/{LibGroupArrayByKey → LibJsGroupArrayByKey}/index.d.ts +2 -2
  23. package/dist/Data/{LibGroupArrayByKey → LibJsGroupArrayByKey}/index.js +2 -2
  24. package/dist/Data/{LibMatchEmail → LibJsMatchEmail}/index.d.ts +2 -2
  25. package/dist/Data/{LibMatchEmail → LibJsMatchEmail}/index.js +2 -2
  26. package/dist/Data/{LibShuffleArray → LibJsShuffleArray}/index.d.ts +2 -2
  27. package/dist/Data/{LibShuffleArray → LibJsShuffleArray}/index.js +2 -2
  28. package/dist/Data/{LibStepArray → LibJsStepArray}/index.d.ts +2 -2
  29. package/dist/Data/{LibStepArray → LibJsStepArray}/index.js +2 -2
  30. package/dist/File/LibJsDownloadImageLink/index.d.ts +7 -0
  31. package/dist/File/{LibDownloadImageLink → LibJsDownloadImageLink}/index.js +2 -2
  32. package/dist/File/{LibImageOptimizer → LibJsImageOptimizer}/index.d.ts +3 -4
  33. package/dist/File/{LibImageOptimizer → LibJsImageOptimizer}/index.js +2 -3
  34. package/dist/File/LibJsSaveJson/index.d.ts +9 -0
  35. package/dist/File/{LibSaveJson → LibJsSaveJson}/index.js +3 -3
  36. package/dist/Formatter/{LibFormatterByte → LibJsFormatterByte}/index.d.ts +2 -2
  37. package/dist/Formatter/{LibFormatterByte → LibJsFormatterByte}/index.js +2 -2
  38. package/dist/Formatter/{LibMaskPhoneNumber → LibJsMaskPhoneNumber}/index.d.ts +2 -2
  39. package/dist/Formatter/{LibMaskPhoneNumber → LibJsMaskPhoneNumber}/index.js +2 -2
  40. package/dist/Formatter/{LibNumComma → LibJsNumComma}/index.d.ts +2 -2
  41. package/dist/Formatter/{LibNumComma → LibJsNumComma}/index.js +2 -2
  42. package/dist/Formatter/{LibNumberUnit → LibJsNumberUnit}/index.d.ts +3 -3
  43. package/dist/Formatter/{LibNumberUnit → LibJsNumberUnit}/index.js +2 -2
  44. package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +11 -0
  45. package/dist/Formatter/{LibSecondsFormatterChinese → LibJsSecondsFormatterChinese}/index.js +5 -5
  46. package/dist/Math/{LibCalculateExpression → LibJsCalculateExpression}/index.d.ts +2 -2
  47. package/dist/Math/{LibCalculateExpression → LibJsCalculateExpression}/index.js +2 -2
  48. package/dist/Math/LibJsConvertAngle/index.d.ts +12 -0
  49. package/dist/Math/{LibConvertAngle → LibJsConvertAngle}/index.js +3 -3
  50. package/dist/Math/LibJsCoordsAngle/index.d.ts +15 -0
  51. package/dist/Math/{LibCoordsAngle → LibJsCoordsAngle}/index.js +4 -4
  52. package/dist/Math/LibJsCoordsDistance/index.d.ts +15 -0
  53. package/dist/Math/{LibCoordsDistance → LibJsCoordsDistance}/index.js +4 -4
  54. package/dist/Math/LibJsDecimal/index.d.ts +10 -0
  55. package/dist/Math/{LibDecimal → LibJsDecimal}/index.js +4 -4
  56. package/dist/Misc/{LibRegFormValidate → LibJsRegFormValidate}/index.d.ts +3 -3
  57. package/dist/Misc/{LibRegFormValidate → LibJsRegFormValidate}/index.js +3 -3
  58. package/dist/Misc/{LibRetryRequest → LibJsRetryRequest}/index.d.ts +2 -2
  59. package/dist/Misc/{LibRetryRequest → LibJsRetryRequest}/index.js +2 -2
  60. package/dist/Random/LibJsProbabilityResult/index.d.ts +8 -0
  61. package/dist/Random/LibJsProbabilityResult/index.js +8 -0
  62. package/dist/Random/LibJsRandom/index.d.ts +9 -0
  63. package/dist/Random/{LibRandom → LibJsRandom}/index.js +3 -3
  64. package/dist/Random/LibJsRandomColor/index.d.ts +7 -0
  65. package/dist/Random/{LibRandomColor → LibJsRandomColor}/index.js +3 -3
  66. package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +9 -0
  67. package/dist/Random/{LibUniqueRandomNumbers → LibJsUniqueRandomNumbers}/index.js +3 -3
  68. package/dist/Time/{LibSameTimeCheck → LibJsSameTimeCheck}/index.d.ts +1 -1
  69. package/dist/Time/{LibSameTimeCheck → LibJsSameTimeCheck}/index.js +1 -1
  70. package/dist/Time/LibJsTimeAgo/index.d.ts +9 -0
  71. package/dist/Time/{LibTimeAgo → LibJsTimeAgo}/index.js +5 -5
  72. package/dist/Time/LibJsTimeGreeting/index.d.ts +17 -0
  73. package/dist/Time/{LibTimeGreeting → LibJsTimeGreeting}/index.js +4 -4
  74. package/dist/index.d.ts +1 -1
  75. package/dist/index.js +1 -1
  76. package/dist/{lib.d.ts → libJs.d.ts} +97 -97
  77. package/dist/{lib.js → libJs.js} +132 -132
  78. package/package.json +1 -1
  79. package/dist/Base/LibGetDataType/index.d.ts +0 -10
  80. package/dist/Browser/LibColorConsole/index.d.ts +0 -15
  81. package/dist/Browser/LibSetTitleIcon/index.d.ts +0 -7
  82. package/dist/Data/LibDeepJSONParse/index.d.ts +0 -6
  83. package/dist/File/LibDownloadImageLink/index.d.ts +0 -7
  84. package/dist/File/LibSaveJson/index.d.ts +0 -9
  85. package/dist/Formatter/LibSecondsFormatterChinese/index.d.ts +0 -11
  86. package/dist/Math/LibConvertAngle/index.d.ts +0 -12
  87. package/dist/Math/LibCoordsAngle/index.d.ts +0 -15
  88. package/dist/Math/LibCoordsDistance/index.d.ts +0 -15
  89. package/dist/Math/LibDecimal/index.d.ts +0 -10
  90. package/dist/Random/LibProbabilityResult/index.d.ts +0 -8
  91. package/dist/Random/LibProbabilityResult/index.js +0 -8
  92. package/dist/Random/LibRandom/index.d.ts +0 -9
  93. package/dist/Random/LibRandomColor/index.d.ts +0 -7
  94. package/dist/Random/LibUniqueRandomNumbers/index.d.ts +0 -9
  95. package/dist/Time/LibTimeAgo/index.d.ts +0 -9
  96. package/dist/Time/LibTimeGreeting/index.d.ts +0 -17
@@ -2,11 +2,11 @@
2
2
  * @description 返回数据类型
3
3
  * @param v 需要判断类型的数据
4
4
  * @example
5
- * libGetDataType(123); //"number"
6
- * libGetDataType("hello"); //"string"
7
- * libGetDataType([1, 2, 3]); //"array"
5
+ * libJsGetDataType(123); //"number"
6
+ * libJsGetDataType("hello"); //"string"
7
+ * libJsGetDataType([1, 2, 3]); //"array"
8
8
  */
9
- export const libGetDataType = (v) => {
9
+ export const libJsGetDataType = (v) => {
10
10
  return Object.prototype.toString
11
11
  .call(v)
12
12
  .substring(8)
@@ -3,8 +3,8 @@
3
3
  * @param delay 延时毫秒数
4
4
  * @param fn 延时执行函数
5
5
  * @example
6
- * libPromiseTimeout(3000, () => {
6
+ * libJsPromiseTimeout(3000, () => {
7
7
  * console.log("执行延时函数");
8
8
  * });
9
9
  */
10
- export declare const libPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
10
+ export declare const libJsPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
@@ -3,11 +3,11 @@
3
3
  * @param delay 延时毫秒数
4
4
  * @param fn 延时执行函数
5
5
  * @example
6
- * libPromiseTimeout(3000, () => {
6
+ * libJsPromiseTimeout(3000, () => {
7
7
  * console.log("执行延时函数");
8
8
  * });
9
9
  */
10
- export const libPromiseTimeout = (delay = 1, fn) => {
10
+ export const libJsPromiseTimeout = (delay = 1, fn) => {
11
11
  let timeoutId;
12
12
  let remainingTime = delay;
13
13
  let startTime = Date.now();
@@ -0,0 +1,15 @@
1
+ /** @description console颜色打印
2
+ * @param title 标题
3
+ * @param color 颜色
4
+ * @param logs 信息
5
+ * @example
6
+ * //使用红色打印日志
7
+ * libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
8
+ *
9
+ * //使用蓝色打印简单日志
10
+ * libJsColorConsole("信息", "blue", "操作成功");
11
+ */
12
+ export declare const libJsColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
13
+ label: string;
14
+ value: any;
15
+ }[] | any) => void;
@@ -4,12 +4,12 @@
4
4
  * @param logs 信息
5
5
  * @example
6
6
  * //使用红色打印日志
7
- * libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
7
+ * libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
8
8
  *
9
9
  * //使用蓝色打印简单日志
10
- * libColorConsole("信息", "blue", "操作成功");
10
+ * libJsColorConsole("信息", "blue", "操作成功");
11
11
  */
12
- export const libColorConsole = (title, color, logs = []) => {
12
+ export const libJsColorConsole = (title, color, logs = []) => {
13
13
  const colors = {
14
14
  red: "#c0392b",
15
15
  orange: "#d35400",
@@ -3,4 +3,4 @@
3
3
  * const isMobile = libIsMobile();
4
4
  * console.log(isMobile); //true 或 false
5
5
  */
6
- export declare const libIsMobile: () => boolean;
6
+ export declare const libJsIsMobile: () => boolean;
@@ -3,7 +3,7 @@
3
3
  * const isMobile = libIsMobile();
4
4
  * console.log(isMobile); //true 或 false
5
5
  */
6
- export const libIsMobile = () => {
6
+ export const libJsIsMobile = () => {
7
7
  const ua = navigator.userAgent.toLowerCase();
8
8
  return /mobile|android|iphone|ipod/.test(ua);
9
9
  };
@@ -1,6 +1,6 @@
1
1
  /** @description 判断是否为平板
2
2
  * @example
3
- * const isPad = libIsPad();
3
+ * const isPad = libJsIsPad();
4
4
  * console.log(isPad); //true 或 false
5
5
  */
6
- export declare const libIsPad: () => boolean;
6
+ export declare const libJsIsPad: () => boolean;
@@ -1,9 +1,9 @@
1
1
  /** @description 判断是否为平板
2
2
  * @example
3
- * const isPad = libIsPad();
3
+ * const isPad = libJsIsPad();
4
4
  * console.log(isPad); //true 或 false
5
5
  */
6
- export const libIsPad = () => {
6
+ export const libJsIsPad = () => {
7
7
  const ua = navigator.userAgent.toLowerCase();
8
8
  const width = Math.max(window.screen.width, window.screen.height);
9
9
  const height = Math.min(window.screen.width, window.screen.height);
@@ -1,6 +1,6 @@
1
1
  /** @description 获取浏览器地址栏参数
2
2
  * @example
3
- * const params = libPathParams();
3
+ * const params = libJsPathParams();
4
4
  * console.log(params); //{ param1: "value1", param2: "value2" }
5
5
  */
6
- export declare const libPathParams: () => Record<string, string>;
6
+ export declare const libJsPathParams: () => Record<string, string>;
@@ -1,9 +1,9 @@
1
1
  /** @description 获取浏览器地址栏参数
2
2
  * @example
3
- * const params = libPathParams();
3
+ * const params = libJsPathParams();
4
4
  * console.log(params); //{ param1: "value1", param2: "value2" }
5
5
  */
6
- export const libPathParams = () => {
6
+ export const libJsPathParams = () => {
7
7
  const v = location.href;
8
8
  const url = v.split("?")[1];
9
9
  if (!url)
@@ -0,0 +1,7 @@
1
+ /** @description 动态设置网站标题及图标
2
+ * @param title 网站标题
3
+ * @param url 网站图标地址
4
+ * @example
5
+ * libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
+ */
7
+ export declare const libJsSetTitleIcon: (title: string, url: string) => void;
@@ -2,9 +2,9 @@
2
2
  * @param title 网站标题
3
3
  * @param url 网站图标地址
4
4
  * @example
5
- * libSetTitleIcon("我的网站", "https://example.com/favicon.ico");
5
+ * libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
6
  */
7
- export const libSetTitleIcon = (title, url) => {
7
+ export const libJsSetTitleIcon = (title, url) => {
8
8
  document.title = title;
9
9
  const link = document.createElement("link");
10
10
  link.setAttribute("rel", "icon");
@@ -1,7 +1,7 @@
1
1
  /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
2
  * @param backTitle 从其他网页返回时显示的标题
3
3
  * @param leaveTitle 从当前网页离开时显示的标题
4
- * * @example
5
- * libTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
4
+ * @example
5
+ * libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
6
  */
7
- export declare const libTagTitleTip: (backTitle: string, leaveTitle: string) => void;
7
+ export declare const libJsTagTitleTip: (backTitle: string, leaveTitle: string) => void;
@@ -1,10 +1,10 @@
1
1
  /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
2
  * @param backTitle 从其他网页返回时显示的标题
3
3
  * @param leaveTitle 从当前网页离开时显示的标题
4
- * * @example
5
- * libTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
4
+ * @example
5
+ * libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
6
  */
7
- export const libTagTitleTip = (backTitle, leaveTitle) => {
7
+ export const libJsTagTitleTip = (backTitle, leaveTitle) => {
8
8
  let document_title = "";
9
9
  let timer;
10
10
  window.addEventListener("visibilitychange", () => {
@@ -3,7 +3,7 @@
3
3
  * @param arr 需要拆分的数组
4
4
  * @param chunkSize 每个数组的元素数量
5
5
  * @example
6
- * const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
6
+ * const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
7
7
  * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
8
8
  */
9
- export declare const libChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
9
+ export declare const libJsChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
@@ -3,10 +3,10 @@
3
3
  * @param arr 需要拆分的数组
4
4
  * @param chunkSize 每个数组的元素数量
5
5
  * @example
6
- * const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
6
+ * const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
7
7
  * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
8
8
  */
9
- export const libChunkArray = (arr, chunkSize) => {
9
+ export const libJsChunkArray = (arr, chunkSize) => {
10
10
  const result = [];
11
11
  for (let i = 0; i < arr.length; i += chunkSize) {
12
12
  result.push(arr.slice(i, i + chunkSize));
@@ -0,0 +1,6 @@
1
+ /** @description 递归将JSON字符串深度解析为对象
2
+ * @example
3
+ * const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
4
+ * console.log(obj); //{ a: 1, b: { c: 2 } }
5
+ */
6
+ export declare const libJsDeepJSONParse: <T>(data: any) => T;
@@ -1,15 +1,15 @@
1
1
  /** @description 递归将JSON字符串深度解析为对象
2
2
  * @example
3
- * const obj = libDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
3
+ * const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
4
4
  * console.log(obj); //{ a: 1, b: { c: 2 } }
5
5
  */
6
- export const libDeepJSONParse = (data) => {
6
+ export const libJsDeepJSONParse = (data) => {
7
7
  //检查是否为字符串并尝试解析
8
8
  if (typeof data === "string") {
9
9
  try {
10
10
  const parsed = JSON.parse(data);
11
11
  //递归解析解析后的结果
12
- return libDeepJSONParse(parsed);
12
+ return libJsDeepJSONParse(parsed);
13
13
  }
14
14
  catch {
15
15
  //如果解析失败,返回原始字符串
@@ -18,12 +18,12 @@ export const libDeepJSONParse = (data) => {
18
18
  }
19
19
  //如果是数组,递归处理每个元素
20
20
  if (Array.isArray(data)) {
21
- return data.map((item) => libDeepJSONParse(item));
21
+ return data.map((item) => libJsDeepJSONParse(item));
22
22
  }
23
23
  //如果是对象,递归处理每个属性值
24
24
  if (data !== null && typeof data === "object") {
25
25
  return Object.keys(data).reduce((acc, key) => {
26
- acc[key] = libDeepJSONParse(data[key]);
26
+ acc[key] = libJsDeepJSONParse(data[key]);
27
27
  return acc;
28
28
  }, {});
29
29
  }
@@ -4,7 +4,7 @@
4
4
  * @param key 分组的键
5
5
  * @returns 分组后的对象
6
6
  * @example
7
- * const grouped = libGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
7
+ * const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
8
8
  * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
9
9
  */
10
- export declare const libGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
10
+ export declare const libJsGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
@@ -4,10 +4,10 @@
4
4
  * @param key 分组的键
5
5
  * @returns 分组后的对象
6
6
  * @example
7
- * const grouped = libGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
7
+ * const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
8
8
  * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
9
9
  */
10
- export const libGroupArrayByKey = (arr = [], key) => {
10
+ export const libJsGroupArrayByKey = (arr = [], key) => {
11
11
  return key
12
12
  ? arr.reduce((t, v) => {
13
13
  if (!t[v[key]]) {
@@ -4,7 +4,7 @@
4
4
  * @param emailList 电子邮件后缀列表
5
5
  * @returns 匹配结果数组
6
6
  * @example
7
- * const emails = libMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
7
+ * const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
8
8
  * console.log(emails); //["user@gmail.com", "user@yahoo.com"]
9
9
  */
10
- export declare const libMatchEmail: (str: string, emailList: string[]) => string[];
10
+ export declare const libJsMatchEmail: (str: string, emailList: string[]) => string[];
@@ -4,10 +4,10 @@
4
4
  * @param emailList 电子邮件后缀列表
5
5
  * @returns 匹配结果数组
6
6
  * @example
7
- * const emails = libMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
7
+ * const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
8
8
  * console.log(emails); //["user@gmail.com", "user@yahoo.com"]
9
9
  */
10
- export const libMatchEmail = (str, emailList) => {
10
+ export const libJsMatchEmail = (str, emailList) => {
11
11
  return str.includes("@")
12
12
  ? emailList
13
13
  .filter((item) => item.includes(str.slice(str.indexOf("@"))))
@@ -1,7 +1,7 @@
1
1
  /** @description 将数组打乱顺序
2
2
  * @param arr 需要乱序的数组
3
3
  * @example
4
- * const shuffled = libShuffleArray([1, 2, 3, 4, 5]);
4
+ * const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
5
5
  * console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
6
6
  */
7
- export declare const libShuffleArray: <T>(arr: T[]) => T[];
7
+ export declare const libJsShuffleArray: <T>(arr: T[]) => T[];
@@ -1,10 +1,10 @@
1
1
  /** @description 将数组打乱顺序
2
2
  * @param arr 需要乱序的数组
3
3
  * @example
4
- * const shuffled = libShuffleArray([1, 2, 3, 4, 5]);
4
+ * const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
5
5
  * console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
6
6
  */
7
- export const libShuffleArray = (arr) => {
7
+ export const libJsShuffleArray = (arr) => {
8
8
  const newArr = [...arr];
9
9
  for (let i = newArr.length - 1; i > 0; i--) {
10
10
  const j = Math.floor(Math.random() * (i + 1));
@@ -2,7 +2,7 @@
2
2
  * @param arr 移动的数组
3
3
  * @param step 负数为向后移动,正数为向前移动
4
4
  * @example
5
- * const moved = libStepArray([1, 2, 3, 4, 5], 2);
5
+ * const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
6
6
  * console.log(moved); //[4, 5, 1, 2, 3]
7
7
  */
8
- export declare const libStepArray: <T>(arr: T[], step: number) => T[];
8
+ export declare const libJsStepArray: <T>(arr: T[], step: number) => T[];
@@ -2,10 +2,10 @@
2
2
  * @param arr 移动的数组
3
3
  * @param step 负数为向后移动,正数为向前移动
4
4
  * @example
5
- * const moved = libStepArray([1, 2, 3, 4, 5], 2);
5
+ * const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
6
6
  * console.log(moved); //[4, 5, 1, 2, 3]
7
7
  */
8
- export const libStepArray = (arr, step) => {
8
+ export const libJsStepArray = (arr, step) => {
9
9
  const length = arr.length;
10
10
  if (length === 0 || step % length === 0)
11
11
  return arr;
@@ -0,0 +1,7 @@
1
+ /** @description 将链接图片下载到本地
2
+ * @param link 图片链接
3
+ * @param name 图片名称
4
+ * @example
5
+ * libJsDownloadImageLink("https://example.com/image.jpg", "图片.jpg");
6
+ */
7
+ export declare const libJsDownloadImageLink: (link: string, name: string) => void;
@@ -2,9 +2,9 @@
2
2
  * @param link 图片链接
3
3
  * @param name 图片名称
4
4
  * @example
5
- * libDownloadImageLink("https://example.com/image.jpg", "图片.jpg");
5
+ * libJsDownloadImageLink("https://example.com/image.jpg", "图片.jpg");
6
6
  */
7
- export const libDownloadImageLink = (link, name) => {
7
+ export const libJsDownloadImageLink = (link, name) => {
8
8
  fetch(link)
9
9
  .then((res) => res.blob())
10
10
  .then((blob) => {
@@ -1,5 +1,5 @@
1
1
  /** @description 图片压缩参数 */
2
- export type LibImageOptimizerOptionsParams = {
2
+ export type LibJsImageOptimizerOptionsParams = {
3
3
  file?: File;
4
4
  /** 压缩尺寸 */
5
5
  width?: number;
@@ -15,8 +15,7 @@ export type LibImageOptimizerOptionsParams = {
15
15
  /** @description 图片压缩,支持png压缩,保留透明背景
16
16
  * @param obj 压缩参数
17
17
  * @example
18
- * //图片压缩使用示例
19
- * libImageOptimizerOptionsParams({
18
+ * libJsImageOptimizerOptionsParams({
20
19
  * file: myFile,
21
20
  * ratio: 0.8,
22
21
  * width: 800,
@@ -29,4 +28,4 @@ export type LibImageOptimizerOptionsParams = {
29
28
  * }
30
29
  * });
31
30
  */
32
- export declare const libImageOptimizer: (obj: LibImageOptimizerOptionsParams) => void;
31
+ export declare const libJsImageOptimizer: (obj: LibJsImageOptimizerOptionsParams) => void;
@@ -1,8 +1,7 @@
1
1
  /** @description 图片压缩,支持png压缩,保留透明背景
2
2
  * @param obj 压缩参数
3
3
  * @example
4
- * //图片压缩使用示例
5
- * libImageOptimizerOptionsParams({
4
+ * libJsImageOptimizerOptionsParams({
6
5
  * file: myFile,
7
6
  * ratio: 0.8,
8
7
  * width: 800,
@@ -15,7 +14,7 @@
15
14
  * }
16
15
  * });
17
16
  */
18
- export const libImageOptimizer = (obj) => {
17
+ export const libJsImageOptimizer = (obj) => {
19
18
  const canvas = document.createElement("canvas");
20
19
  canvas.classList.add("imageOptimizer");
21
20
  document.body.appendChild(canvas);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description 保存文件到本地
3
+ * @param data 要保存的数据
4
+ * @param name 文件名
5
+ * @example
6
+ * libJsSaveJson(JSON.stringify({ key: "value" }), "example.json");
7
+ * libJsSaveJson("Hellow World!", "example.txt");
8
+ */
9
+ export declare const libJsSaveJson: (data: BlobPart, name: string) => void;
@@ -3,10 +3,10 @@
3
3
  * @param data 要保存的数据
4
4
  * @param name 文件名
5
5
  * @example
6
- * libSaveJson(JSON.stringify({ key: "value" }), "example.json");
7
- * libSaveJson("Hellow World!", "example.txt");
6
+ * libJsSaveJson(JSON.stringify({ key: "value" }), "example.json");
7
+ * libJsSaveJson("Hellow World!", "example.txt");
8
8
  */
9
- export const libSaveJson = (data, name) => {
9
+ export const libJsSaveJson = (data, name) => {
10
10
  const urlObject = window.URL || window.webkitURL;
11
11
  const exportBlob = new Blob([data]);
12
12
  const saveLink = document.createElement("a");
@@ -3,7 +3,7 @@
3
3
  * @param bytes 字节数
4
4
  * @returns ['大小', '单位', '大小及单位']
5
5
  * @example
6
- * const [size, unit, formatted] = libFormatterByte(2048);
6
+ * const [size, unit, formatted] = libJsFormatterByte(2048);
7
7
  * console.log(size, unit, formatted); //2.00 KB 2.00 KB
8
8
  */
9
- export declare const libFormatterByte: (bytes: number) => (string | number)[];
9
+ export declare const libJsFormatterByte: (bytes: number) => (string | number)[];
@@ -3,10 +3,10 @@
3
3
  * @param bytes 字节数
4
4
  * @returns ['大小', '单位', '大小及单位']
5
5
  * @example
6
- * const [size, unit, formatted] = libFormatterByte(2048);
6
+ * const [size, unit, formatted] = libJsFormatterByte(2048);
7
7
  * console.log(size, unit, formatted); //2.00 KB 2.00 KB
8
8
  */
9
- export const libFormatterByte = (bytes) => {
9
+ export const libJsFormatterByte = (bytes) => {
10
10
  if (bytes <= 0)
11
11
  return [0, "B", "0 B"];
12
12
  const k = 1024;
@@ -2,7 +2,7 @@
2
2
  * @description 隐藏手机号码中间的四位数字
3
3
  * @param mobile 需要处理的手机号码
4
4
  * @example
5
- * const masked = libMaskPhoneNumber("13812345678");
5
+ * const masked = libJsMaskPhoneNumber("13812345678");
6
6
  * console.log(masked); //138****5678
7
7
  */
8
- export declare const libMaskPhoneNumber: (mobile: number | string) => string;
8
+ export declare const libJsMaskPhoneNumber: (mobile: number | string) => string;
@@ -2,10 +2,10 @@
2
2
  * @description 隐藏手机号码中间的四位数字
3
3
  * @param mobile 需要处理的手机号码
4
4
  * @example
5
- * const masked = libMaskPhoneNumber("13812345678");
5
+ * const masked = libJsMaskPhoneNumber("13812345678");
6
6
  * console.log(masked); //138****5678
7
7
  */
8
- export const libMaskPhoneNumber = (mobile) => {
8
+ export const libJsMaskPhoneNumber = (mobile) => {
9
9
  const m = mobile.toString();
10
10
  return m.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
11
11
  };
@@ -3,7 +3,7 @@
3
3
  * @param num 需要格式化的数字
4
4
  * @param reserve 保留小数位数
5
5
  * @example
6
- * const formatted = libNumComma(1234567.89);
6
+ * const formatted = libJsNumComma(1234567.89);
7
7
  * console.log(formatted); //1,234,567.89
8
8
  */
9
- export declare const libNumComma: (num: number, reserve?: number) => string;
9
+ export declare const libJsNumComma: (num: number, reserve?: number) => string;
@@ -3,10 +3,10 @@
3
3
  * @param num 需要格式化的数字
4
4
  * @param reserve 保留小数位数
5
5
  * @example
6
- * const formatted = libNumComma(1234567.89);
6
+ * const formatted = libJsNumComma(1234567.89);
7
7
  * console.log(formatted); //1,234,567.89
8
8
  */
9
- export const libNumComma = (num, reserve = 2) => {
9
+ export const libJsNumComma = (num, reserve = 2) => {
10
10
  const str = num.toFixed(reserve).toString();
11
11
  const reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
12
12
  return str.replace(reg, "$1,");
@@ -1,4 +1,4 @@
1
- export interface LibNumberUnitParams {
1
+ export interface LibJsNumberUnitParams {
2
2
  [unit: string]: number;
3
3
  }
4
4
  /** @description 将大于1000的数字使用k为单位
@@ -6,7 +6,7 @@ export interface LibNumberUnitParams {
6
6
  * @param units 单位组,key为单位,value为格式化阈值
7
7
  * @returns [数字, 单位]
8
8
  * @example
9
- * const [value, unit] = libNumberUnit(1500, { K: 1000, M: 1000000 });
9
+ * const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
10
10
  * console.log(value, unit); //1.50 K
11
11
  */
12
- export declare const libNumberUnit: (num: number, units: LibNumberUnitParams) => string[];
12
+ export declare const libJsNumberUnit: (num: number, units: LibJsNumberUnitParams) => string[];
@@ -4,10 +4,10 @@ import Decimal from "decimal.js";
4
4
  * @param units 单位组,key为单位,value为格式化阈值
5
5
  * @returns [数字, 单位]
6
6
  * @example
7
- * const [value, unit] = libNumberUnit(1500, { K: 1000, M: 1000000 });
7
+ * const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
8
8
  * console.log(value, unit); //1.50 K
9
9
  */
10
- export const libNumberUnit = (num, units) => {
10
+ export const libJsNumberUnit = (num, units) => {
11
11
  const decimalValue = new Decimal(num);
12
12
  const sortedUnits = Object.entries(units).sort(([, a], [, b]) => b - a);
13
13
  for (const [unit, threshold] of sortedUnits) {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @description 将秒数格式化为中文时间描述,支持扩展到年
3
+ * @param seconds 秒数
4
+ * @returns 格式化后的中文时间
5
+ * @example
6
+ * libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
7
+ * libJsSecondsFormatterChinese(31536000); //"1年"
8
+ * libJsSecondsFormatterChinese(3600); //"1小时"
9
+ * libJsSecondsFormatterChinese(90); //"1分30秒"
10
+ */
11
+ export declare const libJsSecondsFormatterChinese: (seconds: number) => string;
@@ -6,12 +6,12 @@ dayjs.extend(duration);
6
6
  * @param seconds 秒数
7
7
  * @returns 格式化后的中文时间
8
8
  * @example
9
- * libSecondsFormatterChinese(100000); //"1天3小时46分40秒"
10
- * libSecondsFormatterChinese(31536000); //"1年"
11
- * libSecondsFormatterChinese(3600); //"1小时"
12
- * libSecondsFormatterChinese(90); //"1分30秒"
9
+ * libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
10
+ * libJsSecondsFormatterChinese(31536000); //"1年"
11
+ * libJsSecondsFormatterChinese(3600); //"1小时"
12
+ * libJsSecondsFormatterChinese(90); //"1分30秒"
13
13
  */
14
- export const libSecondsFormatterChinese = (seconds) => {
14
+ export const libJsSecondsFormatterChinese = (seconds) => {
15
15
  const duration = dayjs.duration(seconds, "seconds");
16
16
  const years = Math.floor(duration.asYears());
17
17
  const months = Math.floor(duration.asMonths() % 12);
@@ -3,7 +3,7 @@
3
3
  * @param point 小数点精度
4
4
  * @returns 计算结果
5
5
  * @example
6
- * const result = libCalculateExpression("(1+2)-(3*4)/5");
6
+ * const result = libJsCalculateExpression("(1+2)-(3*4)/5");
7
7
  * console.log(result); //0.6
8
8
  */
9
- export declare const libCalculateExpression: (expression: string, point?: number) => number;
9
+ export declare const libJsCalculateExpression: (expression: string, point?: number) => number;
@@ -4,10 +4,10 @@ import Decimal from 'decimal.js';
4
4
  * @param point 小数点精度
5
5
  * @returns 计算结果
6
6
  * @example
7
- * const result = libCalculateExpression("(1+2)-(3*4)/5");
7
+ * const result = libJsCalculateExpression("(1+2)-(3*4)/5");
8
8
  * console.log(result); //0.6
9
9
  */
10
- export const libCalculateExpression = (expression, point = 2) => {
10
+ export const libJsCalculateExpression = (expression, point = 2) => {
11
11
  //清除所有空格
12
12
  expression = expression.replace(/\s+/g, '');
13
13
  //支持的运算符和优先级
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @description 角度和弧度互相转换
3
+ * @param value 角度值或弧度值
4
+ * @param type 角度类型或弧度类型
5
+ * @example
6
+ * //角度转弧度
7
+ * libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
8
+ *
9
+ * //弧度转角度
10
+ * libJsConvertAngle(Math.PI, "deg"); //返回 180
11
+ */
12
+ export declare const libJsConvertAngle: (value: number, type: "rad" | "deg") => number;