lyb-js 1.6.15 → 1.6.16
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/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 +21 -1
- package/package.json +1 -1
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
|
@@ -3601,6 +3601,22 @@ ${log3.label}:`, log3.value];
|
|
|
3601
3601
|
return void 0;
|
|
3602
3602
|
return available[libJsRandom(0, available.length - 1)];
|
|
3603
3603
|
};
|
|
3604
|
+
dayjs.extend(duration);
|
|
3605
|
+
const libJsCountdown = (endTime) => {
|
|
3606
|
+
const startTime = dayjs();
|
|
3607
|
+
const diff = dayjs(endTime).diff(startTime);
|
|
3608
|
+
const time = dayjs.duration(diff);
|
|
3609
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
3610
|
+
return {
|
|
3611
|
+
years: pad(time.years()),
|
|
3612
|
+
months: pad(time.months()),
|
|
3613
|
+
days: pad(time.days()),
|
|
3614
|
+
hours: pad(time.hours()),
|
|
3615
|
+
minutes: pad(time.minutes()),
|
|
3616
|
+
seconds: pad(time.seconds()),
|
|
3617
|
+
ended: diff <= 0
|
|
3618
|
+
};
|
|
3619
|
+
};
|
|
3604
3620
|
const Base = {
|
|
3605
3621
|
/**
|
|
3606
3622
|
* @description 返回数据类型
|
|
@@ -3891,7 +3907,11 @@ ${log3.label}:`, log3.value];
|
|
|
3891
3907
|
* @param greet 自定义问候语对象
|
|
3892
3908
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
3893
3909
|
*/
|
|
3894
|
-
libJsTimeGreeting
|
|
3910
|
+
libJsTimeGreeting,
|
|
3911
|
+
/** @description 倒计时
|
|
3912
|
+
* @param endTime 毫秒时间戳
|
|
3913
|
+
*/
|
|
3914
|
+
libJsCountdown
|
|
3895
3915
|
};
|
|
3896
3916
|
const LibJs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3897
3917
|
__proto__: null,
|