lyb-js 1.6.33 → 1.6.36

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.
@@ -0,0 +1,4 @@
1
+ export * from "./LibJsGetDataType.js";
2
+ export * from "./LibJsIsNull.js";
3
+ export * from "./LibJsPromiseTimeout.js";
4
+ export * from "./LibJsResizeWatcher.js";
package/Base/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./LibJsGetDataType.js";
2
+ export * from "./LibJsIsNull.js";
3
+ export * from "./LibJsPromiseTimeout.js";
4
+ export * from "./LibJsResizeWatcher.js";
@@ -0,0 +1,10 @@
1
+ export * from "./LibJsColorConsole.js";
2
+ export * from "./LibJsCopy.js";
3
+ export * from "./LibJsGetRowValue.js";
4
+ export * from "./LibJsIsMobile.js";
5
+ export * from "./LibJsIsPad.js";
6
+ export * from "./LibJsObjToUrlParams.js";
7
+ export * from "./libJsParseQueryString.js";
8
+ export * from "./LibJsPathParams.js";
9
+ export * from "./LibJsSetTitleIcon.js";
10
+ export * from "./LibJsTagTitleTip.js";
@@ -0,0 +1,10 @@
1
+ export * from "./LibJsColorConsole.js";
2
+ export * from "./LibJsCopy.js";
3
+ export * from "./LibJsGetRowValue.js";
4
+ export * from "./LibJsIsMobile.js";
5
+ export * from "./LibJsIsPad.js";
6
+ export * from "./LibJsObjToUrlParams.js";
7
+ export * from "./libJsParseQueryString.js";
8
+ export * from "./LibJsPathParams.js";
9
+ export * from "./LibJsSetTitleIcon.js";
10
+ export * from "./LibJsTagTitleTip.js";
@@ -0,0 +1,8 @@
1
+ export * from "./LibJsChunkArray.js";
2
+ export * from "./LibJsDeepJSONParse.js";
3
+ export * from "./LibJsGroupArrayByKey.js";
4
+ export * from "./LibJsMatchEmail.js";
5
+ export * from "./libJsPickUnique.js";
6
+ export * from "./LibJsShuffleArray.js";
7
+ export * from "./LibJsStepArray.js";
8
+ export * from "./LibReverseArrayFromIndex.js";
package/Data/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./LibJsChunkArray.js";
2
+ export * from "./LibJsDeepJSONParse.js";
3
+ export * from "./LibJsGroupArrayByKey.js";
4
+ export * from "./LibJsMatchEmail.js";
5
+ export * from "./libJsPickUnique.js";
6
+ export * from "./LibJsShuffleArray.js";
7
+ export * from "./LibJsStepArray.js";
8
+ export * from "./LibReverseArrayFromIndex.js";
@@ -1,4 +1,4 @@
1
- import { libJsRandom } from "../Random/LibJsRandom";
1
+ import { libJsRandom } from "../Random/LibJsRandom.js";
2
2
  /**
3
3
  * @description 从候选数组中随机取一个未使用的元素
4
4
  * @param pool 全部候选数组
@@ -0,0 +1,3 @@
1
+ export * from "./LibJsDownloadImageLink.js";
2
+ export * from "./LibJsImageOptimizer.js";
3
+ export * from "./LibJsSaveJson.js";
package/File/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./LibJsDownloadImageLink.js";
2
+ export * from "./LibJsImageOptimizer.js";
3
+ export * from "./LibJsSaveJson.js";
@@ -1,7 +1,2 @@
1
- /**
2
- * @description 数字每三位添加逗号(不四舍五入)
3
- * @param num 需要格式化的数字
4
- * @param reserve 保留小数位数
5
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
6
- */
1
+ /** @description 数字每三位添加逗号,不四舍五入 */
7
2
  export declare const libJsNumComma: (num: number, reserve?: number) => string;
@@ -1,13 +1,7 @@
1
- import Decimal from "decimal.js";
2
- /**
3
- * @description 数字每三位添加逗号(不四舍五入)
4
- * @param num 需要格式化的数字
5
- * @param reserve 保留小数位数
6
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
7
- */
1
+ import { Decimal } from "decimal.js";
2
+ /** @description 数字每三位添加逗号,不四舍五入 */
8
3
  export const libJsNumComma = (num, reserve = 2) => {
9
4
  const decimal = new Decimal(num);
10
- // 截断小数,不四舍五入
11
5
  const str = decimal.toFixed(reserve, Decimal.ROUND_DOWN);
12
6
  const reg = str.includes(".") ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
13
7
  return str.replace(reg, "$1,");
@@ -1,8 +1,2 @@
1
- /** @description 将大于或等于单位组的属性值,则使用它的属性名作为单位,你甚至可以用中文键名
2
- * @param num 数字
3
- * @param units 单位组,key为单位,value为格式化阈值
4
- * @param retain 保留几位小数
5
- * @returns 数字+单位
6
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumberUnit-数字单位
7
- */
1
+ /** @description 将大于或等于单位组属性值的数值,格式化为对应单位 */
8
2
  export declare const libJsNumberUnit: (num: number, units: Record<string, number>, retain?: number) => string;
@@ -1,12 +1,6 @@
1
- import Decimal from "decimal.js";
2
- import { libJsNumComma } from './LibJsNumComma';
3
- /** @description 将大于或等于单位组的属性值,则使用它的属性名作为单位,你甚至可以用中文键名
4
- * @param num 数字
5
- * @param units 单位组,key为单位,value为格式化阈值
6
- * @param retain 保留几位小数
7
- * @returns 数字+单位
8
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumberUnit-数字单位
9
- */
1
+ import { Decimal } from "decimal.js";
2
+ import { libJsNumComma } from "./LibJsNumComma.js";
3
+ /** @description 将大于或等于单位组属性值的数值,格式化为对应单位 */
10
4
  export const libJsNumberUnit = (num, units, retain = 0) => {
11
5
  const decimalValue = new Decimal(num);
12
6
  const sortedUnits = Object.entries(units).sort(([, a], [, b]) => b - a);
@@ -14,10 +8,8 @@ export const libJsNumberUnit = (num, units, retain = 0) => {
14
8
  const decimalThreshold = new Decimal(threshold);
15
9
  if (decimalValue.greaterThanOrEqualTo(decimalThreshold)) {
16
10
  const formattedValue = decimalValue.dividedBy(decimalThreshold);
17
- const v = libJsNumComma(Number(formattedValue), retain);
18
- return v + unit;
11
+ return `${libJsNumComma(Number(formattedValue), retain)}${unit}`;
19
12
  }
20
13
  }
21
- const v = libJsNumComma(Number(decimalValue), retain);
22
- return v;
14
+ return libJsNumComma(Number(decimalValue), retain);
23
15
  };
@@ -1,7 +1,2 @@
1
- /**
2
- * @description 将秒数格式化为中文时间描述,支持扩展到年
3
- * @param seconds 秒数
4
- * @returns 格式化后的中文时间
5
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSecondsFormatterChinese-中文时间
6
- */
1
+ /** @description 将秒数格式化为中文时间描述 */
7
2
  export declare const libJsSecondsFormatterChinese: (seconds: number) => string;
@@ -1,20 +1,15 @@
1
1
  import dayjs from "dayjs";
2
- import duration from "dayjs/plugin/duration";
2
+ import duration from "dayjs/plugin/duration.js";
3
3
  dayjs.extend(duration);
4
- /**
5
- * @description 将秒数格式化为中文时间描述,支持扩展到年
6
- * @param seconds 秒数
7
- * @returns 格式化后的中文时间
8
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSecondsFormatterChinese-中文时间
9
- */
4
+ /** @description 将秒数格式化为中文时间描述 */
10
5
  export const libJsSecondsFormatterChinese = (seconds) => {
11
- const duration = dayjs.duration(seconds, "seconds");
12
- const years = Math.floor(duration.asYears());
13
- const months = Math.floor(duration.asMonths() % 12);
14
- const days = Math.floor(duration.asDays() % 30);
15
- const hours = duration.hours();
16
- const minutes = duration.minutes();
17
- const remainingSeconds = duration.seconds();
6
+ const currentDuration = dayjs.duration(seconds, "seconds");
7
+ const years = Math.floor(currentDuration.asYears());
8
+ const months = Math.floor(currentDuration.asMonths() % 12);
9
+ const days = Math.floor(currentDuration.asDays() % 30);
10
+ const hours = currentDuration.hours();
11
+ const minutes = currentDuration.minutes();
12
+ const remainingSeconds = currentDuration.seconds();
18
13
  const timeParts = [];
19
14
  if (years > 0) {
20
15
  timeParts.push(`${years}年`);
@@ -0,0 +1,5 @@
1
+ export * from "./LibJsFormatterByte.js";
2
+ export * from "./LibJsMaskPhoneNumber.js";
3
+ export * from "./LibJsNumberUnit.js";
4
+ export * from "./LibJsNumComma.js";
5
+ export * from "./LibJsSecondsFormatterChinese.js";
@@ -0,0 +1,5 @@
1
+ export * from "./LibJsFormatterByte.js";
2
+ export * from "./LibJsMaskPhoneNumber.js";
3
+ export * from "./LibJsNumberUnit.js";
4
+ export * from "./LibJsNumComma.js";
5
+ export * from "./LibJsSecondsFormatterChinese.js";
@@ -1,7 +1,2 @@
1
- /** @description 计算表达式字符串
2
- * @param expression 表达式字符串
3
- * @param point 小数点精度
4
- * @returns 计算结果
5
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCalculateExpression-表达式字符串
6
- */
1
+ /** @description 计算表达式字符串 */
7
2
  export declare const libJsCalculateExpression: (expression: string, point?: number) => number;
@@ -1,107 +1,90 @@
1
- import Decimal from "decimal.js";
2
- /** @description 计算表达式字符串
3
- * @param expression 表达式字符串
4
- * @param point 小数点精度
5
- * @returns 计算结果
6
- * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCalculateExpression-表达式字符串
7
- */
1
+ import { Decimal } from "decimal.js";
2
+ /** @description 计算表达式字符串 */
8
3
  export const libJsCalculateExpression = (expression, point = 2) => {
9
- //清除所有空格
10
4
  expression = expression.replace(/\s+/g, "");
11
- //支持的运算符和优先级
12
5
  const operators = {
13
6
  "+": 1,
14
7
  "-": 1,
15
8
  "*": 2,
16
9
  "/": 2,
17
10
  };
18
- //支持的小数点精度
19
11
  const toDecimal = (value) => new Decimal(value);
20
- //判断字符是否是运算符
21
12
  const isOperator = (char) => ["+", "-", "*", "/"].includes(char);
22
- //判断字符是否是数字(包括小数点)
23
13
  const isNumber = (char) => /[0-9.]/.test(char);
24
- //解析表达式并计算
25
- const evaluate = (expression) => {
26
- const outputQueue = []; //输出队列
27
- const operatorStack = []; //操作符栈
28
- let i = 0;
29
- while (i < expression.length) {
30
- const char = expression[i];
14
+ const evaluate = (inputExpression) => {
15
+ const outputQueue = [];
16
+ const operatorStack = [];
17
+ let index = 0;
18
+ while (index < inputExpression.length) {
19
+ const char = inputExpression[index];
31
20
  if (isNumber(char)) {
32
21
  let numStr = "";
33
- //处理多位数字(支持小数)
34
- while (i < expression.length && isNumber(expression[i])) {
35
- numStr += expression[i];
36
- i++;
22
+ while (index < inputExpression.length && isNumber(inputExpression[index])) {
23
+ numStr += inputExpression[index];
24
+ index++;
37
25
  }
38
26
  outputQueue.push(toDecimal(numStr));
27
+ continue;
39
28
  }
40
- else if (char === "(") {
29
+ if (char === "(") {
41
30
  operatorStack.push(char);
42
- i++;
31
+ index++;
32
+ continue;
43
33
  }
44
- else if (char === ")") {
45
- //处理右括号,直到遇到左括号
46
- while (operatorStack.length > 0 &&
47
- operatorStack[operatorStack.length - 1] !== "(") {
34
+ if (char === ")") {
35
+ while (operatorStack.length > 0 && operatorStack[operatorStack.length - 1] !== "(") {
48
36
  outputQueue.push(operatorStack.pop());
49
37
  }
50
- operatorStack.pop(); //弹出左括号
51
- i++;
38
+ operatorStack.pop();
39
+ index++;
40
+ continue;
52
41
  }
53
- else if (isOperator(char)) {
54
- //运算符
42
+ if (isOperator(char)) {
55
43
  while (operatorStack.length > 0 &&
56
44
  operators[operatorStack[operatorStack.length - 1]] >= operators[char]) {
57
45
  outputQueue.push(operatorStack.pop());
58
46
  }
59
47
  operatorStack.push(char);
60
- i++;
61
- }
62
- else {
63
- throw new Error(`无效字符: ${char}`);
48
+ index++;
49
+ continue;
64
50
  }
51
+ throw new Error(`无效字符: ${char}`);
65
52
  }
66
- //把所有剩余的操作符添加到输出队列
67
53
  while (operatorStack.length > 0) {
68
54
  outputQueue.push(operatorStack.pop());
69
55
  }
70
- //执行运算
71
56
  const calcStack = [];
72
- for (let token of outputQueue) {
73
- if (typeof token === "string") {
74
- const b = calcStack.pop();
75
- const a = calcStack.pop();
76
- switch (token) {
77
- case "+":
78
- calcStack.push(a.add(b));
79
- break;
80
- case "-":
81
- calcStack.push(a.sub(b));
82
- break;
83
- case "*":
84
- calcStack.push(a.mul(b));
85
- break;
86
- case "/":
87
- if (b.eq(0))
88
- throw new Error("除数不能为零");
89
- calcStack.push(a.div(b));
90
- break;
91
- }
92
- }
93
- else {
57
+ for (const token of outputQueue) {
58
+ if (typeof token !== "string") {
94
59
  calcStack.push(token);
60
+ continue;
61
+ }
62
+ const b = calcStack.pop();
63
+ const a = calcStack.pop();
64
+ switch (token) {
65
+ case "+":
66
+ calcStack.push(a.add(b));
67
+ break;
68
+ case "-":
69
+ calcStack.push(a.sub(b));
70
+ break;
71
+ case "*":
72
+ calcStack.push(a.mul(b));
73
+ break;
74
+ case "/":
75
+ if (b.eq(0)) {
76
+ throw new Error("除数不能为零");
77
+ }
78
+ calcStack.push(a.div(b));
79
+ break;
95
80
  }
96
81
  }
97
82
  return calcStack.pop();
98
83
  };
99
84
  try {
100
- //调用计算器并返回结果
101
- const result = evaluate(expression);
102
- return Number(result.toFixed(point, Decimal.ROUND_DOWN)); //保留指定的小数位数
85
+ return Number(evaluate(expression).toFixed(point, Decimal.ROUND_DOWN));
103
86
  }
104
87
  catch (error) {
105
- throw new Error("表达式计算失败:" + error.message);
88
+ throw new Error(`表达式计算失败:${error.message}`);
106
89
  }
107
90
  };
@@ -0,0 +1,7 @@
1
+ export * from "./LibJsCalculateExpression.js";
2
+ export * from "./LibJsConvertAngle.js";
3
+ export * from "./LibJsCoordsAngle.js";
4
+ export * from "./LibJsCoordsDistance.js";
5
+ export * from "./LibJsDecimal.js";
6
+ export * from "./LibJsLerp.js";
7
+ export * from "./LibJsNormalizeInRange.js";
package/Math/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./LibJsCalculateExpression.js";
2
+ export * from "./LibJsConvertAngle.js";
3
+ export * from "./LibJsCoordsAngle.js";
4
+ export * from "./LibJsCoordsDistance.js";
5
+ export * from "./LibJsDecimal.js";
6
+ export * from "./LibJsLerp.js";
7
+ export * from "./LibJsNormalizeInRange.js";
@@ -1,4 +1,4 @@
1
- import { libJsDecimal } from "../Math/LibJsDecimal";
1
+ import { libJsDecimal } from "../Math/LibJsDecimal.js";
2
2
  /** @description 类属性监听器
3
3
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsClassObservable-类属性监听器
4
4
  */
@@ -0,0 +1,8 @@
1
+ /** @description 筛出已修改的值 */
2
+ /**
3
+ * @description 深度对比对象差异(只返回新对象中发生变更的字段)
4
+ * - 基础类型:值不同则返回新值
5
+ * - 对象:递归 diff
6
+ * - 数组:不做 diff,值不同直接返回新数组
7
+ */
8
+ export declare const libDiffObject: <T extends Record<string, any>>(oldObj: T, newObj: T) => Partial<Record<keyof T, any>>;
@@ -0,0 +1,48 @@
1
+ /** @description 筛出已修改的值 */
2
+ /**
3
+ * @description 深度对比对象差异(只返回新对象中发生变更的字段)
4
+ * - 基础类型:值不同则返回新值
5
+ * - 对象:递归 diff
6
+ * - 数组:不做 diff,值不同直接返回新数组
7
+ */
8
+ export const libDiffObject = (oldObj, newObj) => {
9
+ const result = {};
10
+ const isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
11
+ Object.keys(newObj).forEach((key) => {
12
+ const oldVal = oldObj?.[key];
13
+ const newVal = newObj[key];
14
+ // 数组:不递归,值不同直接返回
15
+ if (Array.isArray(newVal)) {
16
+ if (!Array.isArray(oldVal) || oldVal.length !== newVal.length) {
17
+ result[key] = newVal;
18
+ return;
19
+ }
20
+ const changed = newVal.some((item, index) => {
21
+ const oldItem = oldVal[index];
22
+ // 对象递归
23
+ if (item && typeof item === "object" && !Array.isArray(item)) {
24
+ return Object.keys(libDiffObject(oldItem || {}, item)).length > 0;
25
+ }
26
+ // 基础类型
27
+ return oldItem !== item;
28
+ });
29
+ if (changed) {
30
+ result[key] = newVal;
31
+ }
32
+ return;
33
+ }
34
+ // 对象:递归 diff
35
+ if (isObject(newVal)) {
36
+ const childDiff = libDiffObject(oldVal || {}, newVal);
37
+ if (Object.keys(childDiff).length > 0) {
38
+ result[key] = childDiff;
39
+ }
40
+ return;
41
+ }
42
+ // 基础类型
43
+ if (oldVal !== newVal) {
44
+ result[key] = newVal;
45
+ }
46
+ });
47
+ return result;
48
+ };
@@ -1,4 +1,4 @@
1
- import { libJsIsNull } from "../Base/LibJsIsNull";
1
+ import { libJsIsNull } from "../Base/LibJsIsNull.js";
2
2
  /** @description 去掉对象内的空值 */
3
3
  export const libJsPruneEmpty = (obj) => {
4
4
  const result = Object.entries(obj).reduce((acc, [key, value]) => {
@@ -7,7 +7,10 @@ export const libJsPruneEmpty = (obj) => {
7
7
  acc[key] = value;
8
8
  return acc;
9
9
  }
10
- if (value && typeof value === "object" && !Array.isArray(value)) {
10
+ if (value &&
11
+ typeof value === "object" &&
12
+ !Array.isArray(value) &&
13
+ !(value instanceof Date)) {
11
14
  const next = libJsPruneEmpty(value);
12
15
  if (next)
13
16
  acc[key] = next;
@@ -1,4 +1,4 @@
1
- import { LibJsClassObservable } from "./LibJsClassObservable";
1
+ import { LibJsClassObservable } from "./LibJsClassObservable.js";
2
2
  interface PullUpLoadObservable {
3
3
  /** 当前加载状态文案 */
4
4
  statusText: string;
@@ -1,4 +1,4 @@
1
- import { LibJsClassObservable } from "./LibJsClassObservable";
1
+ import { LibJsClassObservable } from "./LibJsClassObservable.js";
2
2
  /** @description 上拉加载 */
3
3
  export class LibJsPullUpLoad extends LibJsClassObservable {
4
4
  constructor(params) {
@@ -0,0 +1,10 @@
1
+ export * from "./LibJsClassObservable.js";
2
+ export * from "./LibJsDiffObject.js";
3
+ export * from "./LibJsEmitter.js";
4
+ export * from "./LibJsEmitterClose.js";
5
+ export * from "./LibJsHorizontal.js";
6
+ export * from "./LibJsNumberStepper.js";
7
+ export * from "./LibJsPruneEmpty.js";
8
+ export * from "./LibJsPullUpLoad.js";
9
+ export * from "./LibJsRegFormValidate.js";
10
+ export * from "./LibJsRetryRequest.js";
package/Misc/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./LibJsClassObservable.js";
2
+ export * from "./LibJsDiffObject.js";
3
+ export * from "./LibJsEmitter.js";
4
+ export * from "./LibJsEmitterClose.js";
5
+ export * from "./LibJsHorizontal.js";
6
+ export * from "./LibJsNumberStepper.js";
7
+ export * from "./LibJsPruneEmpty.js";
8
+ export * from "./LibJsPullUpLoad.js";
9
+ export * from "./LibJsRegFormValidate.js";
10
+ export * from "./LibJsRetryRequest.js";
package/README.md CHANGED
@@ -155,6 +155,7 @@ console.log(libJsGetRowValue({ user: { name: "Tom" } }, "user.name")); // "Tom"
155
155
  - [LibJsEmitterClose-一次性关闭监听](#libjsemitterclose-一次性关闭监听)
156
156
  - [LibJsHorizontal-游戏横版状态](#libjshorizontal-游戏横版状态)
157
157
  - [LibJsNumberStepper-数字步进器](#libjsnumberstepper-数字步进器)
158
+ - [LibJsDiffObject-筛出已修改的值](#libjsdiffobject-筛出已修改的值)
158
159
  - [LibJsPruneEmpty-对象属性去空值](#libjspruneempty-对象属性去空值)
159
160
  - [LibJsPullUpLoad-上拉加载](#libjspullupload-上拉加载)
160
161
  - [LibJsRegFormValidate-表单验证](#libjsregformvalidate-表单验证)
@@ -764,15 +765,39 @@ addButton.addEventListener("pointerdown", () => stepper.down("add"));
764
765
  subButton.addEventListener("pointerdown", () => stepper.down("sub"));
765
766
  ```
766
767
 
768
+ ### LibJsDiffObject-筛出已修改的值
769
+
770
+ 深度对比对象差异,只返回新对象中发生变更的字段。
771
+
772
+ ```ts
773
+ import { libDiffObject } from "lyb-js/Misc/LibJsDiffObject";
774
+
775
+ const oldObj = {
776
+ name: "Tom",
777
+ profile: { city: "Shanghai", age: 18 },
778
+ tags: [{ id: 1 }, { id: 2 }],
779
+ };
780
+
781
+ const newObj = {
782
+ name: "Jerry",
783
+ profile: { city: "Shanghai", age: 20 },
784
+ tags: [{ id: 1 }, { id: 3 }],
785
+ };
786
+
787
+ console.log(libDiffObject(oldObj, newObj));
788
+ // { name: "Jerry", profile: { age: 20 }, tags: [{ id: 1 }, { id: 3 }] }
789
+ ```
790
+
767
791
  ### LibJsPruneEmpty-对象属性去空值
768
792
 
769
- 递归移除对象中的空字符串、`null`、`undefined` 和空对象;空数组也会被去掉。
793
+ 递归移除对象中的空字符串、`null`、`undefined` 和空对象;空数组也会被去掉。`Date` 会保留原值,不会被递归处理。
770
794
 
771
795
  ```ts
772
796
  import { libJsPruneEmpty } from "lyb-js/Misc/LibJsPruneEmpty";
773
797
 
774
798
  const result = libJsPruneEmpty({
775
799
  name: "Tom",
800
+ createdAt: new Date("2026-05-07T00:00:00.000Z"),
776
801
  empty: "",
777
802
  profile: {
778
803
  age: undefined,
@@ -782,7 +807,7 @@ const result = libJsPruneEmpty({
782
807
  });
783
808
 
784
809
  console.log(result);
785
- // { name: "Tom", profile: { city: "Shanghai" } }
810
+ // { name: "Tom", createdAt: 2026-05-07T00:00:00.000Z, profile: { city: "Shanghai" } }
786
811
  ```
787
812
 
788
813
  ### LibJsPullUpLoad-上拉加载
@@ -0,0 +1,4 @@
1
+ export * from "./LibJsProbabilityResult.js";
2
+ export * from "./LibJsRandom.js";
3
+ export * from "./LibJsRandomColor.js";
4
+ export * from "./LibJsUniqueRandomNumbers.js";
@@ -0,0 +1,4 @@
1
+ export * from "./LibJsProbabilityResult.js";
2
+ export * from "./LibJsRandom.js";
3
+ export * from "./LibJsRandomColor.js";
4
+ export * from "./LibJsUniqueRandomNumbers.js";
@@ -1,4 +1,4 @@
1
- /** @description 倒计时,keepUnit 为保留单位,不再使用其上的进制 */
1
+ /** @description 倒计时,keepUnit 为保留单位时不再使用更高单位进位 */
2
2
  export declare const libJsCountdown: (endTime: number, keepUnit: "year" | "month" | "day" | "hour" | "minute" | "second") => {
3
3
  years: string;
4
4
  months: string;
@@ -1,12 +1,12 @@
1
1
  import dayjs from "dayjs";
2
- import duration from "dayjs/plugin/duration";
2
+ import duration from "dayjs/plugin/duration.js";
3
3
  dayjs.extend(duration);
4
- /** @description 倒计时,keepUnit 为保留单位,不再使用其上的进制 */
4
+ /** @description 倒计时,keepUnit 为保留单位时不再使用更高单位进位 */
5
5
  export const libJsCountdown = (endTime, keepUnit) => {
6
6
  const startTime = dayjs();
7
7
  const diff = dayjs(endTime).diff(startTime);
8
8
  const time = dayjs.duration(diff);
9
- const pad = (n) => n.toString().padStart(2, "0");
9
+ const pad = (num) => num.toString().padStart(2, "0");
10
10
  if (diff <= 0) {
11
11
  return {
12
12
  years: "00",
@@ -18,24 +18,21 @@ export const libJsCountdown = (endTime, keepUnit) => {
18
18
  ended: true,
19
19
  };
20
20
  }
21
- // 先获取原始值
22
21
  const years = time.years();
23
22
  const months = time.months();
24
23
  const days = time.days();
25
24
  let hours = time.hours();
26
25
  let minutes = time.minutes();
27
26
  let seconds = time.seconds();
28
- // 将整个时长打平成秒
29
- const totalSec = time.asSeconds();
30
- // 根据保留单位展开
27
+ const totalSeconds = time.asSeconds();
31
28
  if (keepUnit === "hour") {
32
- hours = Math.floor(totalSec / 3600); // total hours
33
- minutes = Math.floor((totalSec % 3600) / 60);
34
- seconds = Math.floor(totalSec % 60);
29
+ hours = Math.floor(totalSeconds / 3600);
30
+ minutes = Math.floor((totalSeconds % 3600) / 60);
31
+ seconds = Math.floor(totalSeconds % 60);
35
32
  }
36
33
  else if (keepUnit === "minute") {
37
- minutes = Math.floor(totalSec / 60); // total minutes
38
- seconds = Math.floor(totalSec % 60);
34
+ minutes = Math.floor(totalSeconds / 60);
35
+ seconds = Math.floor(totalSeconds % 60);
39
36
  }
40
37
  return {
41
38
  years: pad(years),
@@ -0,0 +1,4 @@
1
+ export * from "./LibJsCountdown.js";
2
+ export * from "./LibJsSameTimeCheck.js";
3
+ export * from "./LibJsTimeAgo.js";
4
+ export * from "./LibJsTimeGreeting.js";
package/Time/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./LibJsCountdown.js";
2
+ export * from "./LibJsSameTimeCheck.js";
3
+ export * from "./LibJsTimeAgo.js";
4
+ export * from "./LibJsTimeGreeting.js";
package/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import * as Base from "./Base/index.js";
2
+ import * as Browser from "./Browser/index.js";
3
+ import * as Data from "./Data/index.js";
4
+ import * as File from "./File/index.js";
5
+ import * as Formatter from "./Formatter/index.js";
6
+ import * as Math from "./Math/index.js";
7
+ import * as Misc from "./Misc/index.js";
8
+ import * as Random from "./Random/index.js";
9
+ import * as Time from "./Time/index.js";
10
+ export * from "./Base/index.js";
11
+ export * from "./Browser/index.js";
12
+ export * from "./Data/index.js";
13
+ export * from "./File/index.js";
14
+ export * from "./Formatter/index.js";
15
+ export * from "./Math/index.js";
16
+ export * from "./Misc/index.js";
17
+ export * from "./Random/index.js";
18
+ export * from "./Time/index.js";
19
+ export { Base, Browser, Data, File, Formatter, Math, Misc, Random, Time };
20
+ export declare const LibJs: {
21
+ Base: typeof Base;
22
+ Browser: typeof Browser;
23
+ Data: typeof Data;
24
+ File: typeof File;
25
+ Formatter: typeof Formatter;
26
+ Math: typeof Math;
27
+ Misc: typeof Misc;
28
+ Random: typeof Random;
29
+ Time: typeof Time;
30
+ };
package/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import * as Base from "./Base/index.js";
2
+ import * as Browser from "./Browser/index.js";
3
+ import * as Data from "./Data/index.js";
4
+ import * as File from "./File/index.js";
5
+ import * as Formatter from "./Formatter/index.js";
6
+ import * as Math from "./Math/index.js";
7
+ import * as Misc from "./Misc/index.js";
8
+ import * as Random from "./Random/index.js";
9
+ import * as Time from "./Time/index.js";
10
+ export * from "./Base/index.js";
11
+ export * from "./Browser/index.js";
12
+ export * from "./Data/index.js";
13
+ export * from "./File/index.js";
14
+ export * from "./Formatter/index.js";
15
+ export * from "./Math/index.js";
16
+ export * from "./Misc/index.js";
17
+ export * from "./Random/index.js";
18
+ export * from "./Time/index.js";
19
+ export { Base, Browser, Data, File, Formatter, Math, Misc, Random, Time };
20
+ export const LibJs = {
21
+ Base,
22
+ Browser,
23
+ Data,
24
+ File,
25
+ Formatter,
26
+ Math,
27
+ Misc,
28
+ Random,
29
+ Time,
30
+ };
package/package.json CHANGED
@@ -1,25 +1,49 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.33",
4
- "description": "自用JS方法库",
3
+ "version": "1.6.36",
4
+ "description": "JavaScript utility library",
5
5
  "license": "ISC",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "main": "./index.js",
9
+ "module": "./index.js",
10
+ "files": [
11
+ "*.js",
12
+ "*.d.ts",
13
+ "Base",
14
+ "Browser",
15
+ "Data",
16
+ "File",
17
+ "Formatter",
18
+ "Math",
19
+ "Misc",
20
+ "Random",
21
+ "Time",
22
+ "README.md"
23
+ ],
9
24
  "exports": {
10
25
  ".": "./index.js",
26
+ "./Base": "./Base/index.js",
11
27
  "./Base/*": "./Base/*",
28
+ "./Browser": "./Browser/index.js",
12
29
  "./Browser/*": "./Browser/*",
30
+ "./Data": "./Data/index.js",
13
31
  "./Data/*": "./Data/*",
32
+ "./File": "./File/index.js",
14
33
  "./File/*": "./File/*",
34
+ "./Formatter": "./Formatter/index.js",
15
35
  "./Formatter/*": "./Formatter/*",
36
+ "./Math": "./Math/index.js",
16
37
  "./Math/*": "./Math/*",
38
+ "./Misc": "./Misc/index.js",
17
39
  "./Misc/*": "./Misc/*",
40
+ "./Random": "./Random/index.js",
18
41
  "./Random/*": "./Random/*",
42
+ "./Time": "./Time/index.js",
19
43
  "./Time/*": "./Time/*"
20
44
  },
21
45
  "author": {
22
- "name": "冷弋白",
46
+ "name": "lengyibai",
23
47
  "email": "1329670984@qq.com"
24
48
  },
25
49
  "repository": {
@@ -27,14 +51,13 @@
27
51
  "url": "git+https://github.com/lengyibai/lyb-js.git"
28
52
  },
29
53
  "keywords": [
30
- "冷弋白",
31
54
  "lengyibai",
32
55
  "lyb",
33
- "lyb-js"
56
+ "lyb-js",
57
+ "javascript"
34
58
  ],
35
59
  "dependencies": {
36
60
  "dayjs": "^1.11.13",
37
- "decimal.js": "^10.4.3",
38
- "vite": "^4.5.5"
61
+ "decimal.js": "^10.4.3"
39
62
  }
40
63
  }
@@ -1,2 +0,0 @@
1
- /** @description 判断是否为空值 */
2
- export declare const libIsNull: (value: any) => boolean;
package/Base/LibIsNull.js DELETED
@@ -1,2 +0,0 @@
1
- /** @description 判断是否为空值 */
2
- export const libIsNull = (value) => value === null || value === undefined || value === "";