lyb-js 1.0.6 → 1.0.8

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 (152) hide show
  1. package/README.md +143 -144
  2. package/dist/Base/LibGetDataType/index.d.ts +10 -0
  3. package/dist/Base/LibGetDataType/index.js +15 -0
  4. package/dist/Base/LibJsGetDataType/index.d.ts +10 -0
  5. package/dist/Base/LibJsGetDataType/index.js +15 -0
  6. package/dist/Base/LibJsPromiseTimeout/index.d.ts +10 -0
  7. package/dist/Base/LibJsPromiseTimeout/index.js +40 -0
  8. package/dist/Base/LibPromiseTimeout/index.d.ts +10 -0
  9. package/dist/Base/LibPromiseTimeout/index.js +40 -0
  10. package/dist/Browser/LibColorConsole/index.d.ts +15 -0
  11. package/dist/Browser/LibColorConsole/index.js +38 -0
  12. package/dist/Browser/LibIsMobile/index.d.ts +6 -0
  13. package/dist/Browser/LibIsMobile/index.js +9 -0
  14. package/dist/Browser/LibIsPad/index.d.ts +6 -0
  15. package/dist/Browser/LibIsPad/index.js +15 -0
  16. package/dist/Browser/LibJsColorConsole/index.d.ts +15 -0
  17. package/dist/Browser/LibJsColorConsole/index.js +38 -0
  18. package/dist/Browser/LibJsIsMobile/index.d.ts +6 -0
  19. package/dist/Browser/LibJsIsMobile/index.js +9 -0
  20. package/dist/Browser/LibJsIsPad/index.d.ts +6 -0
  21. package/dist/Browser/LibJsIsPad/index.js +15 -0
  22. package/dist/Browser/LibJsPathParams/index.d.ts +6 -0
  23. package/dist/Browser/LibJsPathParams/index.js +16 -0
  24. package/dist/Browser/LibJsSetTitleIcon/index.d.ts +7 -0
  25. package/dist/Browser/LibJsSetTitleIcon/index.js +14 -0
  26. package/dist/Browser/LibJsTagTitleTip/index.d.ts +7 -0
  27. package/dist/Browser/LibJsTagTitleTip/index.js +24 -0
  28. package/dist/Browser/LibPathParams/index.d.ts +6 -0
  29. package/dist/Browser/LibPathParams/index.js +16 -0
  30. package/dist/Browser/LibSetTitleIcon/index.d.ts +7 -0
  31. package/dist/Browser/LibSetTitleIcon/index.js +14 -0
  32. package/dist/Browser/LibTagTitleTip/index.d.ts +7 -0
  33. package/dist/Browser/LibTagTitleTip/index.js +24 -0
  34. package/dist/Data/LibChunkArray/index.d.ts +9 -0
  35. package/dist/Data/LibChunkArray/index.js +15 -0
  36. package/dist/Data/LibDeepJSONParse/index.d.ts +6 -0
  37. package/dist/Data/LibDeepJSONParse/index.js +32 -0
  38. package/dist/Data/LibGroupArrayByKey/index.d.ts +10 -0
  39. package/dist/Data/LibGroupArrayByKey/index.js +20 -0
  40. package/dist/Data/LibJsChunkArray/index.d.ts +9 -0
  41. package/dist/Data/LibJsChunkArray/index.js +15 -0
  42. package/dist/Data/LibJsDeepJSONParse/index.d.ts +6 -0
  43. package/dist/Data/LibJsDeepJSONParse/index.js +32 -0
  44. package/dist/Data/LibJsGroupArrayByKey/index.d.ts +10 -0
  45. package/dist/Data/LibJsGroupArrayByKey/index.js +20 -0
  46. package/dist/Data/LibJsMatchEmail/index.d.ts +10 -0
  47. package/dist/Data/LibJsMatchEmail/index.js +16 -0
  48. package/dist/Data/LibJsShuffleArray/index.d.ts +7 -0
  49. package/dist/Data/LibJsShuffleArray/index.js +14 -0
  50. package/dist/Data/LibJsStepArray/index.d.ts +8 -0
  51. package/dist/Data/LibJsStepArray/index.js +14 -0
  52. package/dist/Data/LibMatchEmail/index.d.ts +10 -0
  53. package/dist/Data/LibMatchEmail/index.js +16 -0
  54. package/dist/Data/LibShuffleArray/index.d.ts +7 -0
  55. package/dist/Data/LibShuffleArray/index.js +14 -0
  56. package/dist/Data/LibStepArray/index.d.ts +8 -0
  57. package/dist/Data/LibStepArray/index.js +14 -0
  58. package/dist/File/LibDownloadImageLink/index.d.ts +7 -0
  59. package/dist/File/LibDownloadImageLink/index.js +17 -0
  60. package/dist/File/LibImageOptimizer/index.d.ts +32 -0
  61. package/dist/File/LibImageOptimizer/index.js +83 -0
  62. package/dist/File/LibJsDownloadImageLink/index.d.ts +7 -0
  63. package/dist/File/LibJsDownloadImageLink/index.js +17 -0
  64. package/dist/File/LibJsImageOptimizer/index.d.ts +31 -0
  65. package/dist/File/LibJsImageOptimizer/index.js +82 -0
  66. package/dist/File/LibJsSaveJson/index.d.ts +9 -0
  67. package/dist/File/LibJsSaveJson/index.js +17 -0
  68. package/dist/File/LibSaveJson/index.d.ts +9 -0
  69. package/dist/File/LibSaveJson/index.js +17 -0
  70. package/dist/Formatter/LibFormatterByte/index.d.ts +9 -0
  71. package/dist/Formatter/LibFormatterByte/index.js +17 -0
  72. package/dist/Formatter/LibJsFormatterByte/index.d.ts +9 -0
  73. package/dist/Formatter/LibJsFormatterByte/index.js +17 -0
  74. package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +8 -0
  75. package/dist/Formatter/LibJsMaskPhoneNumber/index.js +11 -0
  76. package/dist/Formatter/LibJsNumComma/index.d.ts +9 -0
  77. package/dist/Formatter/LibJsNumComma/index.js +13 -0
  78. package/dist/Formatter/LibJsNumberUnit/index.d.ts +12 -0
  79. package/dist/Formatter/LibJsNumberUnit/index.js +23 -0
  80. package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +11 -0
  81. package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +42 -0
  82. package/dist/Formatter/LibMaskPhoneNumber/index.d.ts +8 -0
  83. package/dist/Formatter/LibMaskPhoneNumber/index.js +11 -0
  84. package/dist/Formatter/LibNumComma/index.d.ts +9 -0
  85. package/dist/Formatter/LibNumComma/index.js +13 -0
  86. package/dist/Formatter/LibNumberUnit/index.d.ts +12 -0
  87. package/dist/Formatter/LibNumberUnit/index.js +23 -0
  88. package/dist/Formatter/LibSecondsFormatterChinese/index.d.ts +11 -0
  89. package/dist/Formatter/LibSecondsFormatterChinese/index.js +42 -0
  90. package/dist/Math/LibCalculateExpression/index.d.ts +9 -0
  91. package/dist/Math/LibCalculateExpression/index.js +107 -0
  92. package/dist/Math/LibConvertAngle/index.d.ts +12 -0
  93. package/dist/Math/LibConvertAngle/index.js +22 -0
  94. package/dist/Math/LibCoordsAngle/index.d.ts +15 -0
  95. package/dist/Math/LibCoordsAngle/index.js +24 -0
  96. package/dist/Math/LibCoordsDistance/index.d.ts +15 -0
  97. package/dist/Math/LibCoordsDistance/index.js +16 -0
  98. package/dist/Math/LibDecimal/index.d.ts +10 -0
  99. package/dist/Math/LibDecimal/index.js +25 -0
  100. package/dist/Math/LibJsCalculateExpression/index.d.ts +9 -0
  101. package/dist/Math/LibJsCalculateExpression/index.js +107 -0
  102. package/dist/Math/LibJsConvertAngle/index.d.ts +12 -0
  103. package/dist/Math/LibJsConvertAngle/index.js +22 -0
  104. package/dist/Math/LibJsCoordsAngle/index.d.ts +15 -0
  105. package/dist/Math/LibJsCoordsAngle/index.js +24 -0
  106. package/dist/Math/LibJsCoordsDistance/index.d.ts +15 -0
  107. package/dist/Math/LibJsCoordsDistance/index.js +16 -0
  108. package/dist/Math/LibJsDecimal/index.d.ts +10 -0
  109. package/dist/Math/LibJsDecimal/index.js +25 -0
  110. package/dist/Misc/LibJsRegFormValidate/index.d.ts +32 -0
  111. package/dist/Misc/LibJsRegFormValidate/index.js +34 -0
  112. package/dist/Misc/LibJsRetryRequest/index.d.ts +24 -0
  113. package/dist/Misc/LibJsRetryRequest/index.js +37 -0
  114. package/dist/Misc/LibRegFormValidate/index.d.ts +32 -0
  115. package/dist/Misc/LibRegFormValidate/index.js +34 -0
  116. package/dist/Misc/LibRetryRequest/index.d.ts +24 -0
  117. package/dist/Misc/LibRetryRequest/index.js +37 -0
  118. package/dist/Random/LibJsProbabilityResult/index.d.ts +8 -0
  119. package/dist/Random/LibJsProbabilityResult/index.js +8 -0
  120. package/dist/Random/LibJsRandom/index.d.ts +9 -0
  121. package/dist/Random/LibJsRandom/index.js +11 -0
  122. package/dist/Random/LibJsRandomColor/index.d.ts +7 -0
  123. package/dist/Random/LibJsRandomColor/index.js +12 -0
  124. package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +9 -0
  125. package/dist/Random/LibJsUniqueRandomNumbers/index.js +16 -0
  126. package/dist/Random/LibProbabilityResult/index.d.ts +8 -0
  127. package/dist/Random/LibProbabilityResult/index.js +8 -0
  128. package/dist/Random/LibRandom/index.d.ts +9 -0
  129. package/dist/Random/LibRandom/index.js +11 -0
  130. package/dist/Random/LibRandomColor/index.d.ts +7 -0
  131. package/dist/Random/LibRandomColor/index.js +12 -0
  132. package/dist/Random/LibUniqueRandomNumbers/index.d.ts +9 -0
  133. package/dist/Random/LibUniqueRandomNumbers/index.js +16 -0
  134. package/dist/Time/LibJsSameTimeCheck/index.d.ts +12 -0
  135. package/dist/Time/LibJsSameTimeCheck/index.js +24 -0
  136. package/dist/Time/LibJsTimeAgo/index.d.ts +9 -0
  137. package/dist/Time/LibJsTimeAgo/index.js +27 -0
  138. package/dist/Time/LibJsTimeGreeting/index.d.ts +17 -0
  139. package/dist/Time/LibJsTimeGreeting/index.js +23 -0
  140. package/dist/Time/LibSameTimeCheck/index.d.ts +12 -0
  141. package/dist/Time/LibSameTimeCheck/index.js +24 -0
  142. package/dist/Time/LibTimeAgo/index.d.ts +9 -0
  143. package/dist/Time/LibTimeAgo/index.js +27 -0
  144. package/dist/Time/LibTimeGreeting/index.d.ts +17 -0
  145. package/dist/Time/LibTimeGreeting/index.js +23 -0
  146. package/dist/index.d.ts +1 -0
  147. package/dist/index.js +1 -0
  148. package/dist/lib.d.ts +394 -0
  149. package/dist/lib.js +404 -0
  150. package/dist/libJs.d.ts +394 -0
  151. package/dist/libJs.js +404 -0
  152. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @description 返回数据类型
3
+ * @param v 需要判断类型的数据
4
+ * @example
5
+ * libGetDataType(123); //"number"
6
+ * libGetDataType("hello"); //"string"
7
+ * libGetDataType([1, 2, 3]); //"array"
8
+ */
9
+ export const libGetDataType = (v) => {
10
+ return Object.prototype.toString
11
+ .call(v)
12
+ .substring(8)
13
+ .replace(/]/g, "")
14
+ .toLowerCase();
15
+ };
@@ -0,0 +1,10 @@
1
+ export type LibJsGetDataTypeReturnType = "string" | "number" | "boolean" | "array" | "function" | "object";
2
+ /**
3
+ * @description 返回数据类型
4
+ * @param v 需要判断类型的数据
5
+ * @example
6
+ * libJsGetDataType(123); //"number"
7
+ * libJsGetDataType("hello"); //"string"
8
+ * libJsGetDataType([1, 2, 3]); //"array"
9
+ */
10
+ export declare const libJsGetDataType: (v: any) => LibJsGetDataTypeReturnType;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @description 返回数据类型
3
+ * @param v 需要判断类型的数据
4
+ * @example
5
+ * libJsGetDataType(123); //"number"
6
+ * libJsGetDataType("hello"); //"string"
7
+ * libJsGetDataType([1, 2, 3]); //"array"
8
+ */
9
+ export const libJsGetDataType = (v) => {
10
+ return Object.prototype.toString
11
+ .call(v)
12
+ .substring(8)
13
+ .replace(/]/g, "")
14
+ .toLowerCase();
15
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description 延时执行,切换到其他页面会暂停
3
+ * @param delay 延时毫秒数
4
+ * @param fn 延时执行函数
5
+ * @example
6
+ * libJsPromiseTimeout(3000, () => {
7
+ * console.log("执行延时函数");
8
+ * });
9
+ */
10
+ export declare const libJsPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @description 延时执行,切换到其他页面会暂停
3
+ * @param delay 延时毫秒数
4
+ * @param fn 延时执行函数
5
+ * @example
6
+ * libJsPromiseTimeout(3000, () => {
7
+ * console.log("执行延时函数");
8
+ * });
9
+ */
10
+ export const libJsPromiseTimeout = (delay = 1, fn) => {
11
+ let timeoutId;
12
+ let remainingTime = delay;
13
+ let startTime = Date.now();
14
+ let isPaused = false;
15
+ return new Promise((resolve) => {
16
+ const handleVisibilityChange = () => {
17
+ if (document.hidden) {
18
+ isPaused = true;
19
+ clearTimeout(timeoutId);
20
+ remainingTime -= Date.now() - startTime;
21
+ }
22
+ else {
23
+ if (isPaused) {
24
+ isPaused = false;
25
+ startTime = Date.now();
26
+ startTimeout(resolve);
27
+ }
28
+ }
29
+ };
30
+ const startTimeout = (resolve) => {
31
+ timeoutId = setTimeout(() => {
32
+ fn?.();
33
+ resolve();
34
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
35
+ }, remainingTime);
36
+ };
37
+ document.addEventListener("visibilitychange", handleVisibilityChange);
38
+ startTimeout(resolve);
39
+ });
40
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description 延时执行,切换到其他页面会暂停
3
+ * @param delay 延时毫秒数
4
+ * @param fn 延时执行函数
5
+ * @example
6
+ * libPromiseTimeout(3000, () => {
7
+ * console.log("执行延时函数");
8
+ * });
9
+ */
10
+ export declare const libPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @description 延时执行,切换到其他页面会暂停
3
+ * @param delay 延时毫秒数
4
+ * @param fn 延时执行函数
5
+ * @example
6
+ * libPromiseTimeout(3000, () => {
7
+ * console.log("执行延时函数");
8
+ * });
9
+ */
10
+ export const libPromiseTimeout = (delay = 1, fn) => {
11
+ let timeoutId;
12
+ let remainingTime = delay;
13
+ let startTime = Date.now();
14
+ let isPaused = false;
15
+ return new Promise((resolve) => {
16
+ const handleVisibilityChange = () => {
17
+ if (document.hidden) {
18
+ isPaused = true;
19
+ clearTimeout(timeoutId);
20
+ remainingTime -= Date.now() - startTime;
21
+ }
22
+ else {
23
+ if (isPaused) {
24
+ isPaused = false;
25
+ startTime = Date.now();
26
+ startTimeout(resolve);
27
+ }
28
+ }
29
+ };
30
+ const startTimeout = (resolve) => {
31
+ timeoutId = setTimeout(() => {
32
+ fn?.();
33
+ resolve();
34
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
35
+ }, remainingTime);
36
+ };
37
+ document.addEventListener("visibilitychange", handleVisibilityChange);
38
+ startTimeout(resolve);
39
+ });
40
+ };
@@ -0,0 +1,15 @@
1
+ /** @description console颜色打印
2
+ * @param title 标题
3
+ * @param color 颜色
4
+ * @param logs 信息
5
+ * @example
6
+ * //使用红色打印日志
7
+ * libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
8
+ *
9
+ * //使用蓝色打印简单日志
10
+ * libColorConsole("信息", "blue", "操作成功");
11
+ */
12
+ export declare const libColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
13
+ label: string;
14
+ value: any;
15
+ }[] | any) => void;
@@ -0,0 +1,38 @@
1
+ /** @description console颜色打印
2
+ * @param title 标题
3
+ * @param color 颜色
4
+ * @param logs 信息
5
+ * @example
6
+ * //使用红色打印日志
7
+ * libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
8
+ *
9
+ * //使用蓝色打印简单日志
10
+ * libColorConsole("信息", "blue", "操作成功");
11
+ */
12
+ export const libColorConsole = (title, color, logs = []) => {
13
+ const colors = {
14
+ red: "#c0392b",
15
+ orange: "#d35400",
16
+ yellow: "#f1c40f",
17
+ green: "#27ae60",
18
+ blue: "#2980b9",
19
+ purple: "#be2edd",
20
+ };
21
+ //时间戳生成函数
22
+ const getTimestamp = () => {
23
+ const now = new Date();
24
+ const hour = String(now.getHours()).padStart(2, "0");
25
+ const minutes = String(now.getMinutes()).padStart(2, "0");
26
+ const seconds = String(now.getSeconds()).padStart(2, "0");
27
+ return `[${hour}:${minutes}:${seconds}]`;
28
+ };
29
+ if (Array.isArray(logs)) {
30
+ const v = logs.map((log) => {
31
+ return [`\n${log.label}:`, log.value];
32
+ });
33
+ console.log(`%c${getTimestamp()}-${title}`, `color: #fff;background: ${colors[color]}; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0`, ...v.flat(Infinity));
34
+ }
35
+ else {
36
+ console.log(`%c${getTimestamp()}-${title}`, `color: #fff;background: ${colors[color]}; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0`, logs);
37
+ }
38
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 判断是否为移动设备
2
+ * @example
3
+ * const isMobile = libIsMobile();
4
+ * console.log(isMobile); //true 或 false
5
+ */
6
+ export declare const libIsMobile: () => boolean;
@@ -0,0 +1,9 @@
1
+ /** @description 判断是否为移动设备
2
+ * @example
3
+ * const isMobile = libIsMobile();
4
+ * console.log(isMobile); //true 或 false
5
+ */
6
+ export const libIsMobile = () => {
7
+ const ua = navigator.userAgent.toLowerCase();
8
+ return /mobile|android|iphone|ipod/.test(ua);
9
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 判断是否为平板
2
+ * @example
3
+ * const isPad = libIsPad();
4
+ * console.log(isPad); //true 或 false
5
+ */
6
+ export declare const libIsPad: () => boolean;
@@ -0,0 +1,15 @@
1
+ /** @description 判断是否为平板
2
+ * @example
3
+ * const isPad = libIsPad();
4
+ * console.log(isPad); //true 或 false
5
+ */
6
+ export const libIsPad = () => {
7
+ const ua = navigator.userAgent.toLowerCase();
8
+ const width = Math.max(window.screen.width, window.screen.height);
9
+ const height = Math.min(window.screen.width, window.screen.height);
10
+ const aspectRatio = width / height;
11
+ const isTabletUserAgent = /ipad|tablet|playbook|silk/.test(ua) && !/mobile/.test(ua);
12
+ const isTabletWidth = width >= 768 && width <= 1366;
13
+ const isTabletAspectRatio = aspectRatio >= 1.3 && aspectRatio <= 1.6;
14
+ return isTabletUserAgent || (isTabletWidth && isTabletAspectRatio);
15
+ };
@@ -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;
@@ -0,0 +1,38 @@
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 const libJsColorConsole = (title, color, logs = []) => {
13
+ const colors = {
14
+ red: "#c0392b",
15
+ orange: "#d35400",
16
+ yellow: "#f1c40f",
17
+ green: "#27ae60",
18
+ blue: "#2980b9",
19
+ purple: "#be2edd",
20
+ };
21
+ //时间戳生成函数
22
+ const getTimestamp = () => {
23
+ const now = new Date();
24
+ const hour = String(now.getHours()).padStart(2, "0");
25
+ const minutes = String(now.getMinutes()).padStart(2, "0");
26
+ const seconds = String(now.getSeconds()).padStart(2, "0");
27
+ return `[${hour}:${minutes}:${seconds}]`;
28
+ };
29
+ if (Array.isArray(logs)) {
30
+ const v = logs.map((log) => {
31
+ return [`\n${log.label}:`, log.value];
32
+ });
33
+ console.log(`%c${getTimestamp()}-${title}`, `color: #fff;background: ${colors[color]}; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0`, ...v.flat(Infinity));
34
+ }
35
+ else {
36
+ console.log(`%c${getTimestamp()}-${title}`, `color: #fff;background: ${colors[color]}; font-size:14px;border-radius:5px;padding:0.25em;margin:0.5em 0`, logs);
37
+ }
38
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 判断是否为移动设备
2
+ * @example
3
+ * const isMobile = libIsMobile();
4
+ * console.log(isMobile); //true 或 false
5
+ */
6
+ export declare const libJsIsMobile: () => boolean;
@@ -0,0 +1,9 @@
1
+ /** @description 判断是否为移动设备
2
+ * @example
3
+ * const isMobile = libIsMobile();
4
+ * console.log(isMobile); //true 或 false
5
+ */
6
+ export const libJsIsMobile = () => {
7
+ const ua = navigator.userAgent.toLowerCase();
8
+ return /mobile|android|iphone|ipod/.test(ua);
9
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 判断是否为平板
2
+ * @example
3
+ * const isPad = libJsIsPad();
4
+ * console.log(isPad); //true 或 false
5
+ */
6
+ export declare const libJsIsPad: () => boolean;
@@ -0,0 +1,15 @@
1
+ /** @description 判断是否为平板
2
+ * @example
3
+ * const isPad = libJsIsPad();
4
+ * console.log(isPad); //true 或 false
5
+ */
6
+ export const libJsIsPad = () => {
7
+ const ua = navigator.userAgent.toLowerCase();
8
+ const width = Math.max(window.screen.width, window.screen.height);
9
+ const height = Math.min(window.screen.width, window.screen.height);
10
+ const aspectRatio = width / height;
11
+ const isTabletUserAgent = /ipad|tablet|playbook|silk/.test(ua) && !/mobile/.test(ua);
12
+ const isTabletWidth = width >= 768 && width <= 1366;
13
+ const isTabletAspectRatio = aspectRatio >= 1.3 && aspectRatio <= 1.6;
14
+ return isTabletUserAgent || (isTabletWidth && isTabletAspectRatio);
15
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 获取浏览器地址栏参数
2
+ * @example
3
+ * const params = libJsPathParams();
4
+ * console.log(params); //{ param1: "value1", param2: "value2" }
5
+ */
6
+ export declare const libJsPathParams: () => Record<string, string>;
@@ -0,0 +1,16 @@
1
+ /** @description 获取浏览器地址栏参数
2
+ * @example
3
+ * const params = libJsPathParams();
4
+ * console.log(params); //{ param1: "value1", param2: "value2" }
5
+ */
6
+ export const libJsPathParams = () => {
7
+ const v = location.href;
8
+ const url = v.split("?")[1];
9
+ if (!url)
10
+ return {};
11
+ const params = url.split("&").reduce((pre, cur) => {
12
+ const [k, v] = cur.split(/=(.+)/);
13
+ return (pre[k] = v), pre;
14
+ }, {}) || {};
15
+ return params;
16
+ };
@@ -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;
@@ -0,0 +1,14 @@
1
+ /** @description 动态设置网站标题及图标
2
+ * @param title 网站标题
3
+ * @param url 网站图标地址
4
+ * @example
5
+ * libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
+ */
7
+ export const libJsSetTitleIcon = (title, url) => {
8
+ document.title = title;
9
+ const link = document.createElement("link");
10
+ link.setAttribute("rel", "icon");
11
+ link.setAttribute("href", url);
12
+ const head = document.head || document.getElementsByTagName("head")[0];
13
+ head.appendChild(link);
14
+ };
@@ -0,0 +1,7 @@
1
+ /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
+ * @param backTitle 从其他网页返回时显示的标题
3
+ * @param leaveTitle 从当前网页离开时显示的标题
4
+ * @example
5
+ * libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
+ */
7
+ export declare const libJsTagTitleTip: (backTitle: string, leaveTitle: string) => void;
@@ -0,0 +1,24 @@
1
+ /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
+ * @param backTitle 从其他网页返回时显示的标题
3
+ * @param leaveTitle 从当前网页离开时显示的标题
4
+ * @example
5
+ * libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
+ */
7
+ export const libJsTagTitleTip = (backTitle, leaveTitle) => {
8
+ let document_title = "";
9
+ let timer;
10
+ window.addEventListener("visibilitychange", () => {
11
+ clearTimeout(timer);
12
+ if (document.hidden) {
13
+ if (document.title !== backTitle) {
14
+ document_title = document.title;
15
+ }
16
+ document.title = leaveTitle;
17
+ return;
18
+ }
19
+ document.title = backTitle;
20
+ timer = setTimeout(() => {
21
+ document.title = document_title;
22
+ }, 1000);
23
+ });
24
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 获取浏览器地址栏参数
2
+ * @example
3
+ * const params = libPathParams();
4
+ * console.log(params); //{ param1: "value1", param2: "value2" }
5
+ */
6
+ export declare const libPathParams: () => Record<string, string>;
@@ -0,0 +1,16 @@
1
+ /** @description 获取浏览器地址栏参数
2
+ * @example
3
+ * const params = libPathParams();
4
+ * console.log(params); //{ param1: "value1", param2: "value2" }
5
+ */
6
+ export const libPathParams = () => {
7
+ const v = location.href;
8
+ const url = v.split("?")[1];
9
+ if (!url)
10
+ return {};
11
+ const params = url.split("&").reduce((pre, cur) => {
12
+ const [k, v] = cur.split(/=(.+)/);
13
+ return (pre[k] = v), pre;
14
+ }, {}) || {};
15
+ return params;
16
+ };
@@ -0,0 +1,7 @@
1
+ /** @description 动态设置网站标题及图标
2
+ * @param title 网站标题
3
+ * @param url 网站图标地址
4
+ * @example
5
+ * libSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
+ */
7
+ export declare const libSetTitleIcon: (title: string, url: string) => void;
@@ -0,0 +1,14 @@
1
+ /** @description 动态设置网站标题及图标
2
+ * @param title 网站标题
3
+ * @param url 网站图标地址
4
+ * @example
5
+ * libSetTitleIcon("我的网站", "https://example.com/favicon.ico");
6
+ */
7
+ export const libSetTitleIcon = (title, url) => {
8
+ document.title = title;
9
+ const link = document.createElement("link");
10
+ link.setAttribute("rel", "icon");
11
+ link.setAttribute("href", url);
12
+ const head = document.head || document.getElementsByTagName("head")[0];
13
+ head.appendChild(link);
14
+ };
@@ -0,0 +1,7 @@
1
+ /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
+ * @param backTitle 从其他网页返回时显示的标题
3
+ * @param leaveTitle 从当前网页离开时显示的标题
4
+ * * @example
5
+ * libTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
+ */
7
+ export declare const libTagTitleTip: (backTitle: string, leaveTitle: string) => void;
@@ -0,0 +1,24 @@
1
+ /** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
2
+ * @param backTitle 从其他网页返回时显示的标题
3
+ * @param leaveTitle 从当前网页离开时显示的标题
4
+ * * @example
5
+ * libTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
6
+ */
7
+ export const libTagTitleTip = (backTitle, leaveTitle) => {
8
+ let document_title = "";
9
+ let timer;
10
+ window.addEventListener("visibilitychange", () => {
11
+ clearTimeout(timer);
12
+ if (document.hidden) {
13
+ if (document.title !== backTitle) {
14
+ document_title = document.title;
15
+ }
16
+ document.title = leaveTitle;
17
+ return;
18
+ }
19
+ document.title = backTitle;
20
+ timer = setTimeout(() => {
21
+ document.title = document_title;
22
+ }, 1000);
23
+ });
24
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description 将数组拆分成指定数组元素数量的多个数组
3
+ * @param arr 需要拆分的数组
4
+ * @param chunkSize 每个数组的元素数量
5
+ * @example
6
+ * const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
7
+ * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
8
+ */
9
+ export declare const libChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @description 将数组拆分成指定数组元素数量的多个数组
3
+ * @param arr 需要拆分的数组
4
+ * @param chunkSize 每个数组的元素数量
5
+ * @example
6
+ * const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
7
+ * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
8
+ */
9
+ export const libChunkArray = (arr, chunkSize) => {
10
+ const result = [];
11
+ for (let i = 0; i < arr.length; i += chunkSize) {
12
+ result.push(arr.slice(i, i + chunkSize));
13
+ }
14
+ return result;
15
+ };
@@ -0,0 +1,6 @@
1
+ /** @description 递归将JSON字符串深度解析为对象
2
+ * @example
3
+ * const obj = libDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
4
+ * console.log(obj); //{ a: 1, b: { c: 2 } }
5
+ */
6
+ export declare const libDeepJSONParse: <T>(data: any) => T;
@@ -0,0 +1,32 @@
1
+ /** @description 递归将JSON字符串深度解析为对象
2
+ * @example
3
+ * const obj = libDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
4
+ * console.log(obj); //{ a: 1, b: { c: 2 } }
5
+ */
6
+ export const libDeepJSONParse = (data) => {
7
+ //检查是否为字符串并尝试解析
8
+ if (typeof data === "string") {
9
+ try {
10
+ const parsed = JSON.parse(data);
11
+ //递归解析解析后的结果
12
+ return libDeepJSONParse(parsed);
13
+ }
14
+ catch {
15
+ //如果解析失败,返回原始字符串
16
+ return data;
17
+ }
18
+ }
19
+ //如果是数组,递归处理每个元素
20
+ if (Array.isArray(data)) {
21
+ return data.map((item) => libDeepJSONParse(item));
22
+ }
23
+ //如果是对象,递归处理每个属性值
24
+ if (data !== null && typeof data === "object") {
25
+ return Object.keys(data).reduce((acc, key) => {
26
+ acc[key] = libDeepJSONParse(data[key]);
27
+ return acc;
28
+ }, {});
29
+ }
30
+ //其他情况返回原始值
31
+ return data;
32
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
3
+ * @param arr 要分组的数组
4
+ * @param key 分组的键
5
+ * @returns 分组后的对象
6
+ * @example
7
+ * const grouped = libGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
8
+ * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
9
+ */
10
+ export declare const libGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
3
+ * @param arr 要分组的数组
4
+ * @param key 分组的键
5
+ * @returns 分组后的对象
6
+ * @example
7
+ * const grouped = libGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
8
+ * console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
9
+ */
10
+ export const libGroupArrayByKey = (arr = [], key) => {
11
+ return key
12
+ ? arr.reduce((t, v) => {
13
+ if (!t[v[key]]) {
14
+ t[v[key]] = [];
15
+ }
16
+ t[v[key]].push(v);
17
+ return t;
18
+ }, {})
19
+ : {};
20
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description 将数组拆分成指定数组元素数量的多个数组
3
+ * @param arr 需要拆分的数组
4
+ * @param chunkSize 每个数组的元素数量
5
+ * @example
6
+ * const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
7
+ * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
8
+ */
9
+ export declare const libJsChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @description 将数组拆分成指定数组元素数量的多个数组
3
+ * @param arr 需要拆分的数组
4
+ * @param chunkSize 每个数组的元素数量
5
+ * @example
6
+ * const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
7
+ * console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
8
+ */
9
+ export const libJsChunkArray = (arr, chunkSize) => {
10
+ const result = [];
11
+ for (let i = 0; i < arr.length; i += chunkSize) {
12
+ result.push(arr.slice(i, i + chunkSize));
13
+ }
14
+ return result;
15
+ };
@@ -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;