lyb-js 1.1.5 → 1.1.7

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 +110 -47
  2. package/dist/Base/LibJsGetDataType/index.d.ts +1 -5
  3. package/dist/Base/LibJsGetDataType/index.js +2 -6
  4. package/dist/Base/LibJsPromiseTimeout/index.d.ts +1 -5
  5. package/dist/Base/LibJsPromiseTimeout/index.js +12 -15
  6. package/dist/Browser/LibJsColorConsole/index.d.ts +1 -7
  7. package/dist/Browser/LibJsColorConsole/index.js +23 -19
  8. package/dist/Browser/LibJsIsMobile/index.d.ts +1 -4
  9. package/dist/Browser/LibJsIsMobile/index.js +3 -6
  10. package/dist/Browser/LibJsIsPad/index.d.ts +1 -4
  11. package/dist/Browser/LibJsIsPad/index.js +9 -12
  12. package/dist/Browser/LibJsObjToUrlParams/index.d.ts +1 -4
  13. package/dist/Browser/LibJsObjToUrlParams/index.js +6 -6
  14. package/dist/Browser/LibJsPathParams/index.d.ts +1 -4
  15. package/dist/Browser/LibJsPathParams/index.js +6 -9
  16. package/dist/Browser/LibJsSetTitleIcon/index.d.ts +1 -3
  17. package/dist/Browser/LibJsSetTitleIcon/index.js +4 -6
  18. package/dist/Browser/LibJsTagTitleTip/index.d.ts +1 -3
  19. package/dist/Browser/LibJsTagTitleTip/index.js +6 -8
  20. package/dist/Data/LibJsChunkArray/index.d.ts +1 -4
  21. package/dist/Data/LibJsChunkArray/index.js +4 -7
  22. package/dist/Data/LibJsDeepJSONParse/index.d.ts +1 -4
  23. package/dist/Data/LibJsDeepJSONParse/index.js +6 -9
  24. package/dist/Data/LibJsGroupArrayByKey/index.d.ts +1 -4
  25. package/dist/Data/LibJsGroupArrayByKey/index.js +4 -6
  26. package/dist/Data/LibJsMatchEmail/index.d.ts +1 -4
  27. package/dist/Data/LibJsMatchEmail/index.js +5 -8
  28. package/dist/Data/LibJsShuffleArray/index.d.ts +1 -4
  29. package/dist/Data/LibJsShuffleArray/index.js +16 -9
  30. package/dist/Data/LibJsStepArray/index.d.ts +1 -4
  31. package/dist/Data/LibJsStepArray/index.js +4 -7
  32. package/dist/Data/LibReverseArrayFromIndex/index.d.ts +1 -4
  33. package/dist/Data/LibReverseArrayFromIndex/index.js +13 -7
  34. package/dist/File/LibJsDownloadImageLink/index.d.ts +1 -3
  35. package/dist/File/LibJsDownloadImageLink/index.js +6 -8
  36. package/dist/File/LibJsImageOptimizer/index.d.ts +1 -14
  37. package/dist/File/LibJsImageOptimizer/index.js +37 -50
  38. package/dist/File/LibJsSaveJson/index.d.ts +1 -4
  39. package/dist/File/LibJsSaveJson/index.js +5 -8
  40. package/dist/Formatter/LibJsFormatterByte/index.d.ts +1 -4
  41. package/dist/Formatter/LibJsFormatterByte/index.js +7 -10
  42. package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +1 -4
  43. package/dist/Formatter/LibJsMaskPhoneNumber/index.js +3 -6
  44. package/dist/Formatter/LibJsNumComma/index.d.ts +1 -4
  45. package/dist/Formatter/LibJsNumComma/index.js +5 -7
  46. package/dist/Formatter/LibJsNumberUnit/index.d.ts +6 -9
  47. package/dist/Formatter/LibJsNumberUnit/index.js +18 -14
  48. package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +1 -6
  49. package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +16 -21
  50. package/dist/Math/LibJsCalculateExpression/index.d.ts +1 -4
  51. package/dist/Math/LibJsCalculateExpression/index.js +33 -32
  52. package/dist/Math/LibJsConvertAngle/index.d.ts +1 -7
  53. package/dist/Math/LibJsConvertAngle/index.js +2 -8
  54. package/dist/Math/LibJsCoordsAngle/index.d.ts +1 -5
  55. package/dist/Math/LibJsCoordsAngle/index.js +6 -10
  56. package/dist/Math/LibJsCoordsDistance/index.d.ts +1 -5
  57. package/dist/Math/LibJsCoordsDistance/index.js +5 -9
  58. package/dist/Math/LibJsDecimal/index.d.ts +1 -5
  59. package/dist/Math/LibJsDecimal/index.js +9 -12
  60. package/dist/Misc/LibJsRegFormValidate/index.d.ts +1 -16
  61. package/dist/Misc/LibJsRegFormValidate/index.js +7 -22
  62. package/dist/Misc/LibJsRetryRequest/index.d.ts +1 -12
  63. package/dist/Misc/LibJsRetryRequest/index.js +8 -18
  64. package/dist/Misc/LibNumerStepper/index.d.ts +1 -6
  65. package/dist/Misc/LibNumerStepper/index.js +28 -35
  66. package/dist/Random/LibJsProbabilityResult/index.d.ts +1 -5
  67. package/dist/Random/LibJsProbabilityResult/index.js +4 -6
  68. package/dist/Random/LibJsRandom/index.d.ts +1 -4
  69. package/dist/Random/LibJsRandom/index.js +3 -5
  70. package/dist/Random/LibJsRandomColor/index.d.ts +1 -4
  71. package/dist/Random/LibJsRandomColor/index.js +7 -9
  72. package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +1 -4
  73. package/dist/Random/LibJsUniqueRandomNumbers/index.js +7 -9
  74. package/dist/Time/LibJsSameTimeCheck/index.d.ts +1 -5
  75. package/dist/Time/LibJsSameTimeCheck/index.js +4 -8
  76. package/dist/Time/LibJsTimeAgo/index.d.ts +1 -6
  77. package/dist/Time/LibJsTimeAgo/index.js +9 -13
  78. package/dist/Time/LibJsTimeGreeting/index.d.ts +1 -5
  79. package/dist/Time/LibJsTimeGreeting/index.js +5 -8
  80. package/dist/libJs.d.ts +42 -201
  81. package/dist/libJs.js +95 -256
  82. package/package.json +1 -1
  83. package/umd/lyb.js +3 -3
@@ -2,23 +2,27 @@ import Decimal from "decimal.js";
2
2
  /** @description 将大于1000的数字使用k为单位
3
3
  * @param num 数字
4
4
  * @param units 单位组,key为单位,value为格式化阈值
5
- * @returns [数字, 单位]
6
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
7
- * @example
8
- * const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
9
- * console.log(value, unit); //1.50 K
5
+ * @param point 保留几位小数
6
+ * @returns [数字, 单位, 数字+单位]
7
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumberUnit-数字单位
10
8
  */
11
- export const libJsNumberUnit = (num, units) => {
12
- const decimalValue = new Decimal(num);
13
- const sortedUnits = Object.entries(units).sort(([, a], [, b]) => b - a);
14
- for (const [unit, threshold] of sortedUnits) {
15
- const decimalThreshold = new Decimal(threshold);
9
+ export var libJsNumberUnit = function (num, units, point) {
10
+ if (point === void 0) { point = 2; }
11
+ var decimalValue = new Decimal(num);
12
+ var sortedUnits = Object.entries(units).sort(function (_a, _b) {
13
+ var a = _a[1];
14
+ var b = _b[1];
15
+ return b - a;
16
+ });
17
+ for (var _i = 0, sortedUnits_1 = sortedUnits; _i < sortedUnits_1.length; _i++) {
18
+ var _a = sortedUnits_1[_i], unit = _a[0], threshold = _a[1];
19
+ var decimalThreshold = new Decimal(threshold);
16
20
  if (decimalValue.greaterThanOrEqualTo(decimalThreshold)) {
17
- const formattedValue = decimalValue
21
+ var formattedValue = decimalValue
18
22
  .dividedBy(decimalThreshold)
19
- .toFixed(2);
20
- return [formattedValue, unit];
23
+ .toFixed(point);
24
+ return [formattedValue, unit, formattedValue + unit];
21
25
  }
22
26
  }
23
- return [decimalValue.toFixed(2), ""];
27
+ return [decimalValue.toFixed(point), ""];
24
28
  };
@@ -2,11 +2,6 @@
2
2
  * @description 将秒数格式化为中文时间描述,支持扩展到年
3
3
  * @param seconds 秒数
4
4
  * @returns 格式化后的中文时间
5
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
- * @example
7
- * libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
8
- * libJsSecondsFormatterChinese(31536000); //"1年"
9
- * libJsSecondsFormatterChinese(3600); //"1小时"
10
- * libJsSecondsFormatterChinese(90); //"1分30秒"
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSecondsFormatterChinese-中文时间
11
6
  */
12
7
  export declare const libJsSecondsFormatterChinese: (seconds: number) => string;
@@ -5,39 +5,34 @@ dayjs.extend(duration);
5
5
  * @description 将秒数格式化为中文时间描述,支持扩展到年
6
6
  * @param seconds 秒数
7
7
  * @returns 格式化后的中文时间
8
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
9
- * @example
10
- * libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
11
- * libJsSecondsFormatterChinese(31536000); //"1年"
12
- * libJsSecondsFormatterChinese(3600); //"1小时"
13
- * libJsSecondsFormatterChinese(90); //"1分30秒"
8
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSecondsFormatterChinese-中文时间
14
9
  */
15
- export const libJsSecondsFormatterChinese = (seconds) => {
16
- const duration = dayjs.duration(seconds, "seconds");
17
- const years = Math.floor(duration.asYears());
18
- const months = Math.floor(duration.asMonths() % 12);
19
- const days = Math.floor(duration.asDays() % 30);
20
- const hours = duration.hours();
21
- const minutes = duration.minutes();
22
- const remainingSeconds = duration.seconds();
23
- const timeParts = [];
10
+ export var libJsSecondsFormatterChinese = function (seconds) {
11
+ var duration = dayjs.duration(seconds, "seconds");
12
+ var years = Math.floor(duration.asYears());
13
+ var months = Math.floor(duration.asMonths() % 12);
14
+ var days = Math.floor(duration.asDays() % 30);
15
+ var hours = duration.hours();
16
+ var minutes = duration.minutes();
17
+ var remainingSeconds = duration.seconds();
18
+ var timeParts = [];
24
19
  if (years > 0) {
25
- timeParts.push(`${years}年`);
20
+ timeParts.push("".concat(years, "\u5E74"));
26
21
  }
27
22
  if (months > 0) {
28
- timeParts.push(`${months}月`);
23
+ timeParts.push("".concat(months, "\u6708"));
29
24
  }
30
25
  if (days > 0) {
31
- timeParts.push(`${days}天`);
26
+ timeParts.push("".concat(days, "\u5929"));
32
27
  }
33
28
  if (hours > 0) {
34
- timeParts.push(`${hours}小时`);
29
+ timeParts.push("".concat(hours, "\u5C0F\u65F6"));
35
30
  }
36
31
  if (minutes > 0) {
37
- timeParts.push(`${minutes}分`);
32
+ timeParts.push("".concat(minutes, "\u5206"));
38
33
  }
39
34
  if (timeParts.length === 0 || remainingSeconds > 0) {
40
- timeParts.push(`${remainingSeconds}秒`);
35
+ timeParts.push("".concat(remainingSeconds, "\u79D2"));
41
36
  }
42
37
  return timeParts.join("");
43
38
  };
@@ -2,9 +2,6 @@
2
2
  * @param expression 表达式字符串
3
3
  * @param point 小数点精度
4
4
  * @returns 计算结果
5
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
- * @example
7
- * const result = libJsCalculateExpression("(1+2)-(3*4)/5");
8
- * console.log(result); //0.6
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCalculateExpression-表达式字符串
9
6
  */
10
7
  export declare const libJsCalculateExpression: (expression: string, point?: number) => number;
@@ -1,38 +1,36 @@
1
- import Decimal from 'decimal.js';
1
+ import Decimal from "decimal.js";
2
2
  /** @description 计算表达式字符串
3
3
  * @param expression 表达式字符串
4
4
  * @param point 小数点精度
5
5
  * @returns 计算结果
6
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
7
- * @example
8
- * const result = libJsCalculateExpression("(1+2)-(3*4)/5");
9
- * console.log(result); //0.6
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCalculateExpression-表达式字符串
10
7
  */
11
- export const libJsCalculateExpression = (expression, point = 2) => {
8
+ export var libJsCalculateExpression = function (expression, point) {
9
+ if (point === void 0) { point = 2; }
12
10
  //清除所有空格
13
- expression = expression.replace(/\s+/g, '');
11
+ expression = expression.replace(/\s+/g, "");
14
12
  //支持的运算符和优先级
15
- const operators = {
13
+ var operators = {
16
14
  "+": 1,
17
15
  "-": 1,
18
16
  "*": 2,
19
17
  "/": 2,
20
18
  };
21
19
  //支持的小数点精度
22
- const toDecimal = (value) => new Decimal(value);
20
+ var toDecimal = function (value) { return new Decimal(value); };
23
21
  //判断字符是否是运算符
24
- const isOperator = (char) => ['+', '-', '*', '/'].includes(char);
22
+ var isOperator = function (char) { return ["+", "-", "*", "/"].includes(char); };
25
23
  //判断字符是否是数字(包括小数点)
26
- const isNumber = (char) => /[0-9.]/.test(char);
24
+ var isNumber = function (char) { return /[0-9.]/.test(char); };
27
25
  //解析表达式并计算
28
- const evaluate = (expression) => {
29
- const outputQueue = []; //输出队列
30
- const operatorStack = []; //操作符栈
31
- let i = 0;
26
+ var evaluate = function (expression) {
27
+ var outputQueue = []; //输出队列
28
+ var operatorStack = []; //操作符栈
29
+ var i = 0;
32
30
  while (i < expression.length) {
33
- const char = expression[i];
31
+ var char = expression[i];
34
32
  if (isNumber(char)) {
35
- let numStr = '';
33
+ var numStr = "";
36
34
  //处理多位数字(支持小数)
37
35
  while (i < expression.length && isNumber(expression[i])) {
38
36
  numStr += expression[i];
@@ -40,13 +38,14 @@ export const libJsCalculateExpression = (expression, point = 2) => {
40
38
  }
41
39
  outputQueue.push(toDecimal(numStr));
42
40
  }
43
- else if (char === '(') {
41
+ else if (char === "(") {
44
42
  operatorStack.push(char);
45
43
  i++;
46
44
  }
47
- else if (char === ')') {
45
+ else if (char === ")") {
48
46
  //处理右括号,直到遇到左括号
49
- while (operatorStack.length > 0 && operatorStack[operatorStack.length - 1] !== '(') {
47
+ while (operatorStack.length > 0 &&
48
+ operatorStack[operatorStack.length - 1] !== "(") {
50
49
  outputQueue.push(operatorStack.pop());
51
50
  }
52
51
  operatorStack.pop(); //弹出左括号
@@ -54,14 +53,15 @@ export const libJsCalculateExpression = (expression, point = 2) => {
54
53
  }
55
54
  else if (isOperator(char)) {
56
55
  //运算符
57
- while (operatorStack.length > 0 && operators[operatorStack[operatorStack.length - 1]] >= operators[char]) {
56
+ while (operatorStack.length > 0 &&
57
+ operators[operatorStack[operatorStack.length - 1]] >= operators[char]) {
58
58
  outputQueue.push(operatorStack.pop());
59
59
  }
60
60
  operatorStack.push(char);
61
61
  i++;
62
62
  }
63
63
  else {
64
- throw new Error(`无效字符: ${char}`);
64
+ throw new Error("\u65E0\u6548\u5B57\u7B26: ".concat(char));
65
65
  }
66
66
  }
67
67
  //把所有剩余的操作符添加到输出队列
@@ -69,22 +69,23 @@ export const libJsCalculateExpression = (expression, point = 2) => {
69
69
  outputQueue.push(operatorStack.pop());
70
70
  }
71
71
  //执行运算
72
- const calcStack = [];
73
- for (let token of outputQueue) {
74
- if (typeof token === 'string') {
75
- const b = calcStack.pop();
76
- const a = calcStack.pop();
72
+ var calcStack = [];
73
+ for (var _i = 0, outputQueue_1 = outputQueue; _i < outputQueue_1.length; _i++) {
74
+ var token = outputQueue_1[_i];
75
+ if (typeof token === "string") {
76
+ var b = calcStack.pop();
77
+ var a = calcStack.pop();
77
78
  switch (token) {
78
- case '+':
79
+ case "+":
79
80
  calcStack.push(a.add(b));
80
81
  break;
81
- case '-':
82
+ case "-":
82
83
  calcStack.push(a.sub(b));
83
84
  break;
84
- case '*':
85
+ case "*":
85
86
  calcStack.push(a.mul(b));
86
87
  break;
87
- case '/':
88
+ case "/":
88
89
  if (b.eq(0))
89
90
  throw new Error("除数不能为零");
90
91
  calcStack.push(a.div(b));
@@ -99,7 +100,7 @@ export const libJsCalculateExpression = (expression, point = 2) => {
99
100
  };
100
101
  try {
101
102
  //调用计算器并返回结果
102
- const result = evaluate(expression);
103
+ var result = evaluate(expression);
103
104
  return Number(result.toFixed(point)); //保留指定的小数位数
104
105
  }
105
106
  catch (error) {
@@ -2,12 +2,6 @@
2
2
  * @description 角度和弧度互相转换
3
3
  * @param value 角度值或弧度值
4
4
  * @param type 角度类型或弧度类型
5
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
- * @example
7
- * //角度转弧度
8
- * libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
9
- *
10
- * //弧度转角度
11
- * libJsConvertAngle(Math.PI, "deg"); //返回 180
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsConvertAngle-角弧度互转
12
6
  */
13
7
  export declare const libJsConvertAngle: (value: number, type: "rad" | "deg") => number;
@@ -2,15 +2,9 @@
2
2
  * @description 角度和弧度互相转换
3
3
  * @param value 角度值或弧度值
4
4
  * @param type 角度类型或弧度类型
5
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
- * @example
7
- * //角度转弧度
8
- * libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
9
- *
10
- * //弧度转角度
11
- * libJsConvertAngle(Math.PI, "deg"); //返回 180
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsConvertAngle-角弧度互转
12
6
  */
13
- export const libJsConvertAngle = (value, type) => {
7
+ export var libJsConvertAngle = function (value, type) {
14
8
  if (type === "rad") {
15
9
  return value * (Math.PI / 180);
16
10
  }
@@ -1,11 +1,7 @@
1
1
  /** @description 计算两点角度
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
- * @example
6
- * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
7
- * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
8
- * libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsAngle-两点角度
9
5
  */
10
6
  export declare const libJsCoordsAngle: (coord1: {
11
7
  x: number;
@@ -1,20 +1,16 @@
1
1
  /** @description 计算两点角度
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
- * @example
6
- * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
7
- * libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
8
- * libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsAngle-两点角度
9
5
  */
10
- export const libJsCoordsAngle = (coord1, coord2) => {
6
+ export var libJsCoordsAngle = function (coord1, coord2) {
11
7
  //计算相对于第一个坐标的水平和垂直距离
12
- const deltaX = coord2.x - coord1.x;
13
- const deltaY = coord2.y - coord1.y;
8
+ var deltaX = coord2.x - coord1.x;
9
+ var deltaY = coord2.y - coord1.y;
14
10
  //使用反三角函数计算角度(以弧度为单位)
15
- const angleRad = Math.atan2(deltaY, deltaX);
11
+ var angleRad = Math.atan2(deltaY, deltaX);
16
12
  //将弧度转换为角度
17
- let angleDeg = angleRad * (180 / Math.PI);
13
+ var angleDeg = angleRad * (180 / Math.PI);
18
14
  //将角度转换为顺时针方向为正方向的角度
19
15
  angleDeg = -angleDeg + 90;
20
16
  //调整角度使得右边成为 360 度的位置变为 0 度
@@ -1,11 +1,7 @@
1
1
  /** @description 计算两点距离
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
- * @example
6
- * libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
7
- * libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
8
- * libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsDistance-两点距离
9
5
  */
10
6
  export declare const libJsCoordsDistance: (coord1: {
11
7
  x: number;
@@ -1,17 +1,13 @@
1
1
  /** @description 计算两点距离
2
2
  * @param coord1 起点坐标
3
3
  * @param coord2 终点坐标
4
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
5
- * @example
6
- * libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
7
- * libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
8
- * libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsDistance-两点距离
9
5
  */
10
- export const libJsCoordsDistance = (coord1, coord2) => {
6
+ export var libJsCoordsDistance = function (coord1, coord2) {
11
7
  //计算两个坐标之间的水平和垂直距离
12
- const deltaX = coord2.x - coord1.x;
13
- const deltaY = coord2.y - coord1.y;
8
+ var deltaX = coord2.x - coord1.x;
9
+ var deltaY = coord2.y - coord1.y;
14
10
  //使用勾股定理计算两点之间的距离
15
- const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
11
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
16
12
  return distance;
17
13
  };
@@ -2,10 +2,6 @@
2
2
  * @param num1 第一个数
3
3
  * @param num2 第二个数
4
4
  * @param operator 运算符,支持加减乘除
5
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
6
- * @example
7
- * libJsDecimal(10, 3, "+"); //13
8
- * libJsDecimal(10, 3, "-"); //7
9
- * libJsDecimal(10, 3, "/", 2); //3.33
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDecimal-高精度计算
10
6
  */
11
7
  export declare const libJsDecimal: (num1: number, num2: number, operator: "+" | "-" | "*" | "/", point?: number) => number;
@@ -3,24 +3,21 @@ import { Decimal } from "decimal.js";
3
3
  * @param num1 第一个数
4
4
  * @param num2 第二个数
5
5
  * @param operator 运算符,支持加减乘除
6
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
7
- * @example
8
- * libJsDecimal(10, 3, "+"); //13
9
- * libJsDecimal(10, 3, "-"); //7
10
- * libJsDecimal(10, 3, "/", 2); //3.33
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDecimal-高精度计算
11
7
  */
12
- export const libJsDecimal = (num1, num2, operator, point = 2) => {
13
- const calc = {
14
- "+": (a, b) => a.add(b),
15
- "-": (a, b) => a.sub(b),
16
- "*": (a, b) => a.mul(b),
17
- "/": (a, b) => {
8
+ export var libJsDecimal = function (num1, num2, operator, point) {
9
+ if (point === void 0) { point = 2; }
10
+ var calc = {
11
+ "+": function (a, b) { return a.add(b); },
12
+ "-": function (a, b) { return a.sub(b); },
13
+ "*": function (a, b) { return a.mul(b); },
14
+ "/": function (a, b) {
18
15
  if (b.eq(0)) {
19
16
  throw new Error("除数不能为0");
20
17
  }
21
18
  return a.div(b);
22
19
  },
23
20
  };
24
- const result = calc[operator](new Decimal(num1), new Decimal(num2));
21
+ var result = calc[operator](new Decimal(num1), new Decimal(num2));
25
22
  return Number(result.toFixed(point));
26
23
  };
@@ -8,22 +8,7 @@ export type ValidationResult = {
8
8
  * @param form 表单数据对象
9
9
  * @param rules 验证规则数组
10
10
  * @returns 验证结果数组,包含未通过验证的项
11
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
12
- * @example
13
- * const form = { username: "john", email: "john@example.com" };
14
- * const rules = [
15
- * { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
16
- * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
17
- * ];
18
- * libJsRegFormValidate(form, rules);
19
- * //返回结果: []
20
- *
21
- * const invalidForm = { username: "jo", email: "invalid-email" };
22
- * libJsRegFormValidate(invalidForm, rules);
23
- * //返回结果: [
24
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
25
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
26
- * //]
11
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRegFormValidate-表单验证
27
12
  */
28
13
  export declare const libJsRegFormValidate: (form: Record<string, any>, rules: Array<{
29
14
  key: string;
@@ -3,32 +3,17 @@
3
3
  * @param form 表单数据对象
4
4
  * @param rules 验证规则数组
5
5
  * @returns 验证结果数组,包含未通过验证的项
6
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
7
- * @example
8
- * const form = { username: "john", email: "john@example.com" };
9
- * const rules = [
10
- * { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
11
- * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
12
- * ];
13
- * libJsRegFormValidate(form, rules);
14
- * //返回结果: []
15
- *
16
- * const invalidForm = { username: "jo", email: "invalid-email" };
17
- * libJsRegFormValidate(invalidForm, rules);
18
- * //返回结果: [
19
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
20
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
21
- * //]
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRegFormValidate-表单验证
22
7
  */
23
- export const libJsRegFormValidate = (form, rules) => {
24
- return rules.reduce((result, rule) => {
25
- const { key, verify, msg, name } = rule;
26
- const value = form[key];
8
+ export var libJsRegFormValidate = function (form, rules) {
9
+ return rules.reduce(function (result, rule) {
10
+ var key = rule.key, verify = rule.verify, msg = rule.msg, name = rule.name;
11
+ var value = form[key];
27
12
  if (value === "" || value === undefined || value === null) {
28
- result.push({ key, msg: "必填项", name });
13
+ result.push({ key: key, msg: "必填项", name: name });
29
14
  }
30
15
  else if (typeof verify === "function" ? !verify(value) : !verify.test(value)) {
31
- result.push({ key, msg, name });
16
+ result.push({ key: key, msg: msg, name: name });
32
17
  }
33
18
  return result;
34
19
  }, []);
@@ -3,18 +3,7 @@
3
3
  * @param maxRetries 最大重试次数
4
4
  * @param retryDelay 重试间隔时间
5
5
  * @param params 请求参数
6
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
7
- * @example
8
- * const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
9
- * const params = { url: "https://api.example.com/data" };
10
- * libJsRetryRequest({
11
- * promiseFn: requestFn,
12
- * params,
13
- * maxRetries: 5,
14
- * retryDelay: 1000
15
- * })
16
- * .then(data => console.log(data))
17
- * .catch(err => console.error(err));
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRetryRequest-请求重连
18
7
  */
19
8
  export declare const libJsRetryRequest: <T>({ promiseFn, maxRetries, retryDelay, params, }: {
20
9
  promiseFn: (params?: any) => Promise<T>;
@@ -3,28 +3,18 @@
3
3
  * @param maxRetries 最大重试次数
4
4
  * @param retryDelay 重试间隔时间
5
5
  * @param params 请求参数
6
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
7
- * @example
8
- * const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
9
- * const params = { url: "https://api.example.com/data" };
10
- * libJsRetryRequest({
11
- * promiseFn: requestFn,
12
- * params,
13
- * maxRetries: 5,
14
- * retryDelay: 1000
15
- * })
16
- * .then(data => console.log(data))
17
- * .catch(err => console.error(err));
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRetryRequest-请求重连
18
7
  */
19
- export const libJsRetryRequest = ({ promiseFn, maxRetries = 3, retryDelay = 2000, params = undefined, }) => {
20
- return new Promise((resolve, reject) => {
21
- let count = 0;
22
- const makeRequest = () => {
8
+ export var libJsRetryRequest = function (_a) {
9
+ var promiseFn = _a.promiseFn, _b = _a.maxRetries, maxRetries = _b === void 0 ? 3 : _b, _c = _a.retryDelay, retryDelay = _c === void 0 ? 2000 : _c, _d = _a.params, params = _d === void 0 ? undefined : _d;
10
+ return new Promise(function (resolve, reject) {
11
+ var count = 0;
12
+ var makeRequest = function () {
23
13
  promiseFn(params)
24
- .then((res) => {
14
+ .then(function (res) {
25
15
  resolve(res);
26
16
  })
27
- .catch((err) => {
17
+ .catch(function (err) {
28
18
  count++;
29
19
  if (count >= maxRetries) {
30
20
  reject(err);
@@ -1,10 +1,5 @@
1
1
  /** @description 数字步进器
2
- * @link 了解更多:https://www.npmjs.com/package/lyb-js
3
- * @example
4
- * const stepper = new libNumerStepper(10, (index) => console.log(index));
5
- * stepper.down("add"); // 索引加1
6
- * stepper.updateIndex(5); // 更新索引为5
7
- * stepper.down("sub"); // 索引减1
2
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibNumerStepper-数字步进器
8
3
  */
9
4
  export declare class libNumerStepper {
10
5
  /** 数字变动时触发 */