lyb-js 1.6.15 → 1.6.17
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.
- package/Formatter/LibJsNumComma.d.ts +1 -1
- package/Formatter/LibJsNumComma.js +6 -3
- package/README.md +21 -0
- package/Time/LibJsCountdown.d.ts +9 -0
- package/Time/LibJsCountdown.js +18 -0
- package/libJs.d.ts +12 -0
- package/libJs.js +5 -0
- package/lyb.js +24 -3
- package/package.json +1 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
/**
|
|
2
|
-
* @description
|
|
3
|
+
* @description 数字每三位添加逗号(不四舍五入)
|
|
3
4
|
* @param num 需要格式化的数字
|
|
4
5
|
* @param reserve 保留小数位数
|
|
5
6
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
|
|
6
7
|
*/
|
|
7
8
|
export const libJsNumComma = (num, reserve = 2) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
9
|
+
const decimal = new Decimal(num);
|
|
10
|
+
// 截断小数,不四舍五入
|
|
11
|
+
const str = decimal.toFixed(reserve, Decimal.ROUND_DOWN);
|
|
12
|
+
const reg = str.includes(".") ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
|
|
10
13
|
return str.replace(reg, "$1,");
|
|
11
14
|
};
|
package/README.md
CHANGED
|
@@ -778,3 +778,24 @@ const result3 = libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午
|
|
|
778
778
|
console.log(result3); //50% 概率为 true
|
|
779
779
|
```
|
|
780
780
|
|
|
781
|
+
### libJsCountdown-倒计时
|
|
782
|
+
|
|
783
|
+
> 以当前时间为开始时间,传递结束时间,返回年到秒的数值,以及是否结束
|
|
784
|
+
|
|
785
|
+
```ts
|
|
786
|
+
const result = libJsCountdown("2025-12-01 12:00:00");
|
|
787
|
+
|
|
788
|
+
console.log(result);
|
|
789
|
+
/*
|
|
790
|
+
{
|
|
791
|
+
years: "00",
|
|
792
|
+
months: "01",
|
|
793
|
+
days: "20",
|
|
794
|
+
hours: "05",
|
|
795
|
+
minutes: "34",
|
|
796
|
+
seconds: "12",
|
|
797
|
+
ended: false
|
|
798
|
+
}
|
|
799
|
+
*/
|
|
800
|
+
```
|
|
801
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import duration from "dayjs/plugin/duration";
|
|
3
|
+
dayjs.extend(duration);
|
|
4
|
+
export const libJsCountdown = (endTime) => {
|
|
5
|
+
const startTime = dayjs();
|
|
6
|
+
const diff = dayjs(endTime).diff(startTime);
|
|
7
|
+
const time = dayjs.duration(diff);
|
|
8
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
9
|
+
return {
|
|
10
|
+
years: pad(time.years()),
|
|
11
|
+
months: pad(time.months()),
|
|
12
|
+
days: pad(time.days()),
|
|
13
|
+
hours: pad(time.hours()),
|
|
14
|
+
minutes: pad(time.minutes()),
|
|
15
|
+
seconds: pad(time.seconds()),
|
|
16
|
+
ended: diff <= 0,
|
|
17
|
+
};
|
|
18
|
+
};
|
package/libJs.d.ts
CHANGED
|
@@ -333,4 +333,16 @@ export declare const Time: {
|
|
|
333
333
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
334
334
|
*/
|
|
335
335
|
libJsTimeGreeting: (greet?: import("./Time/LibJsTimeGreeting").LibTimeGreetingParams) => string;
|
|
336
|
+
/** @description 倒计时
|
|
337
|
+
* @param endTime 毫秒时间戳
|
|
338
|
+
*/
|
|
339
|
+
libJsCountdown: (endTime: number) => {
|
|
340
|
+
years: string;
|
|
341
|
+
months: string;
|
|
342
|
+
days: string;
|
|
343
|
+
hours: string;
|
|
344
|
+
minutes: string;
|
|
345
|
+
seconds: string;
|
|
346
|
+
ended: boolean;
|
|
347
|
+
};
|
|
336
348
|
};
|
package/libJs.js
CHANGED
|
@@ -45,6 +45,7 @@ import { libJsCopy } from "./Browser/LibJsCopy";
|
|
|
45
45
|
import { LibJsResizeWatcher } from "./Base/LibJsResizeWatcher";
|
|
46
46
|
import { LibJsPullUpLoad } from "./Misc/LibJsPullUpLoad";
|
|
47
47
|
import { libJsPickUnique } from "./Data/libJsPickUnique";
|
|
48
|
+
import { libJsCountdown } from "./Time/LibJsCountdown";
|
|
48
49
|
/** @description 基础方法 */
|
|
49
50
|
export const Base = {
|
|
50
51
|
/**
|
|
@@ -345,4 +346,8 @@ export const Time = {
|
|
|
345
346
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
346
347
|
*/
|
|
347
348
|
libJsTimeGreeting,
|
|
349
|
+
/** @description 倒计时
|
|
350
|
+
* @param endTime 毫秒时间戳
|
|
351
|
+
*/
|
|
352
|
+
libJsCountdown,
|
|
348
353
|
};
|
package/lyb.js
CHANGED
|
@@ -3101,8 +3101,9 @@ ${log3.label}:`, log3.value];
|
|
|
3101
3101
|
return m.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
3102
3102
|
};
|
|
3103
3103
|
const libJsNumComma = (num, reserve = 2) => {
|
|
3104
|
-
const
|
|
3105
|
-
const
|
|
3104
|
+
const decimal = new Decimal(num);
|
|
3105
|
+
const str = decimal.toFixed(reserve, Decimal.ROUND_DOWN);
|
|
3106
|
+
const reg = str.includes(".") ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
|
|
3106
3107
|
return str.replace(reg, "$1,");
|
|
3107
3108
|
};
|
|
3108
3109
|
const libJsNumberUnit = (num, units, retain = 0) => {
|
|
@@ -3601,6 +3602,22 @@ ${log3.label}:`, log3.value];
|
|
|
3601
3602
|
return void 0;
|
|
3602
3603
|
return available[libJsRandom(0, available.length - 1)];
|
|
3603
3604
|
};
|
|
3605
|
+
dayjs.extend(duration);
|
|
3606
|
+
const libJsCountdown = (endTime) => {
|
|
3607
|
+
const startTime = dayjs();
|
|
3608
|
+
const diff = dayjs(endTime).diff(startTime);
|
|
3609
|
+
const time = dayjs.duration(diff);
|
|
3610
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
3611
|
+
return {
|
|
3612
|
+
years: pad(time.years()),
|
|
3613
|
+
months: pad(time.months()),
|
|
3614
|
+
days: pad(time.days()),
|
|
3615
|
+
hours: pad(time.hours()),
|
|
3616
|
+
minutes: pad(time.minutes()),
|
|
3617
|
+
seconds: pad(time.seconds()),
|
|
3618
|
+
ended: diff <= 0
|
|
3619
|
+
};
|
|
3620
|
+
};
|
|
3604
3621
|
const Base = {
|
|
3605
3622
|
/**
|
|
3606
3623
|
* @description 返回数据类型
|
|
@@ -3891,7 +3908,11 @@ ${log3.label}:`, log3.value];
|
|
|
3891
3908
|
* @param greet 自定义问候语对象
|
|
3892
3909
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
3893
3910
|
*/
|
|
3894
|
-
libJsTimeGreeting
|
|
3911
|
+
libJsTimeGreeting,
|
|
3912
|
+
/** @description 倒计时
|
|
3913
|
+
* @param endTime 毫秒时间戳
|
|
3914
|
+
*/
|
|
3915
|
+
libJsCountdown
|
|
3895
3916
|
};
|
|
3896
3917
|
const LibJs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3897
3918
|
__proto__: null,
|