lyb-js 1.6.14 → 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.
@@ -5,4 +5,5 @@ export declare const LibJsEmitter: <T extends Record<string, any>>() => {
5
5
  on: <K extends keyof T>(event: K, listener: T[K] extends any[] ? (...args: T[K]) => void : (arg: T[K]) => void) => void;
6
6
  emit: <K extends keyof T>(event: K, ...args: T[K] extends any[] ? T[K] : [T[K]]) => void;
7
7
  off: <K extends keyof T>(event: K, listener?: T[K] extends any[] ? (...args: T[K]) => void : (arg: T[K]) => void) => void;
8
+ clear: () => void;
8
9
  };
@@ -24,5 +24,6 @@ export const LibJsEmitter = () => {
24
24
  }
25
25
  }
26
26
  };
27
- return { on, emit, off };
27
+ const clear = () => _eventMap.clear();
28
+ return { on, emit, off, clear };
28
29
  };
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,9 @@
1
+ export declare const libJsCountdown: (endTime: number) => {
2
+ years: string;
3
+ months: string;
4
+ days: string;
5
+ hours: string;
6
+ minutes: string;
7
+ seconds: string;
8
+ ended: boolean;
9
+ };
@@ -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
@@ -276,6 +276,7 @@ export declare const Misc: {
276
276
  on: <K extends keyof T>(event: K, listener: T[K] extends any[] ? (...args: T[K]) => void : (arg: T[K]) => void) => void;
277
277
  emit: <K extends keyof T>(event: K, ...args: T[K] extends any[] ? T[K] : [T[K]]) => void;
278
278
  off: <K extends keyof T>(event: K, listener?: T[K] extends any[] ? (...args: T[K]) => void : (arg: T[K]) => void) => void;
279
+ clear: () => void;
279
280
  };
280
281
  /** @description 类属性监听器
281
282
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsClassObservable-类属性监听器
@@ -332,4 +333,16 @@ export declare const Time: {
332
333
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
333
334
  */
334
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
+ };
335
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
@@ -3389,7 +3389,8 @@ ${log3.label}:`, log3.value];
3389
3389
  }
3390
3390
  }
3391
3391
  };
3392
- return { on, emit, off };
3392
+ const clear = () => _eventMap.clear();
3393
+ return { on, emit, off, clear };
3393
3394
  };
3394
3395
  const LibJsLerp = (start, end, value) => {
3395
3396
  const t = Math.min(Math.max(value, 0), 1);
@@ -3600,6 +3601,22 @@ ${log3.label}:`, log3.value];
3600
3601
  return void 0;
3601
3602
  return available[libJsRandom(0, available.length - 1)];
3602
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
+ };
3603
3620
  const Base = {
3604
3621
  /**
3605
3622
  * @description 返回数据类型
@@ -3890,7 +3907,11 @@ ${log3.label}:`, log3.value];
3890
3907
  * @param greet 自定义问候语对象
3891
3908
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
3892
3909
  */
3893
- libJsTimeGreeting
3910
+ libJsTimeGreeting,
3911
+ /** @description 倒计时
3912
+ * @param endTime 毫秒时间戳
3913
+ */
3914
+ libJsCountdown
3894
3915
  };
3895
3916
  const LibJs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3896
3917
  __proto__: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.14",
3
+ "version": "1.6.16",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",