@bereasoftware/time-guard 2.7.2 → 2.9.0

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 (52) hide show
  1. package/README.en.md +5 -1
  2. package/README.md +5 -1
  3. package/dist/adapters/temporal.adapter.d.ts +6 -2
  4. package/dist/angular/index.cjs +1 -148
  5. package/dist/angular/index.es.js +63 -112
  6. package/dist/calendars/index.cjs +1 -357
  7. package/dist/calendars/index.es.js +66 -99
  8. package/dist/chunk-C6qsp3rV.cjs +1 -0
  9. package/dist/core-BDQnStek.cjs +1 -0
  10. package/dist/core-GHK7isoa.js +1200 -0
  11. package/dist/core.d.ts +27 -1
  12. package/dist/index.d.ts +4 -2
  13. package/dist/locales/index.cjs +1 -7
  14. package/dist/locales/index.d.ts +11 -0
  15. package/dist/locales/index.es.js +3 -3
  16. package/dist/{locales-CGdn0DJN.cjs → locales-Dwe5oGoy.js} +201 -82
  17. package/dist/locales-bc-5kDuZ.cjs +1 -0
  18. package/dist/native/index.cjs +1 -48
  19. package/dist/native/index.es.js +8 -18
  20. package/dist/plugins/advanced-format/index.d.ts +8 -0
  21. package/dist/plugins/advanced-format.cjs +1 -105
  22. package/dist/plugins/advanced-format.es.js +48 -63
  23. package/dist/plugins/duration/index.d.ts +6 -0
  24. package/dist/plugins/duration.cjs +1 -258
  25. package/dist/plugins/duration.es.js +63 -165
  26. package/dist/plugins/manager.d.ts +6 -2
  27. package/dist/plugins/relative-time/index.d.ts +6 -0
  28. package/dist/plugins/relative-time.cjs +1 -166
  29. package/dist/plugins/relative-time.es.js +39 -74
  30. package/dist/qwik/index.cjs +1 -104
  31. package/dist/qwik/index.es.js +36 -94
  32. package/dist/qwik.d.ts +5 -1
  33. package/dist/react/index.cjs +1 -112
  34. package/dist/react/index.es.js +57 -91
  35. package/dist/solid/index.cjs +1 -127
  36. package/dist/solid/index.es.js +36 -116
  37. package/dist/solid.d.ts +5 -2
  38. package/dist/svelte/index.cjs +1 -398
  39. package/dist/svelte/index.es.js +85 -344
  40. package/dist/time-guard.cjs +3 -7359
  41. package/dist/time-guard.es.js +3412 -3625
  42. package/dist/time-guard.iife.js +3 -13549
  43. package/dist/time-guard.umd.js +3 -13550
  44. package/dist/types/index.d.ts +10 -0
  45. package/dist/vue/index.cjs +1 -143
  46. package/dist/vue/index.es.js +62 -116
  47. package/dist/vue.d.ts +5 -3
  48. package/package.json +3 -4
  49. package/dist/chunk-S8Y6Ng9i.cjs +0 -36
  50. package/dist/core-BIDjudpO.cjs +0 -1892
  51. package/dist/core-DWPXk3rz.js +0 -1809
  52. package/dist/locales-BUE_aq8K.js +0 -3514
@@ -1,104 +1 @@
1
- /*! time-guard v2.7.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_core = require("../core-BIDjudpO.cjs");
4
- let _builder_io_qwik = require("@builder.io/qwik");
5
- //#region src/qwik.ts
6
- /**
7
- * TimeGuard — Qwik Integration
8
- *
9
- * Provides reactive signal-based wrappers for TimeGuard using Qwik's
10
- * resumable reactivity model. All hooks use `useSignal` and
11
- * `useVisibleTask$` with automatic cleanup for optimal performance.
12
- *
13
- * @example
14
- * ```tsx
15
- * import { component$ } from '@builder.io/qwik';
16
- * import { useCurrentTime, useRelativeTime } from '@bereasoftware/time-guard/qwik';
17
- *
18
- * export default component$(() => {
19
- * const now = useCurrentTime({ interval: 1000 });
20
- * const relative = useRelativeTime('2026-05-20T08:00:00');
21
- *
22
- * return (
23
- * <div>
24
- * <h1>{now.value.format('HH:mm:ss')}</h1>
25
- * <p>Published: {relative.value}</p>
26
- * </div>
27
- * );
28
- * });
29
- * ```
30
- */
31
- /**
32
- * Creates a Qwik Signal of a TimeGuard instance.
33
- * Uses `useTask$` to reactively update when input changes.
34
- * Must be called inside `component$`.
35
- */
36
- function useTimeGuard(input, config) {
37
- const tg = (0, _builder_io_qwik.useSignal)(require_core.TimeGuard.from(input, config));
38
- (0, _builder_io_qwik.useTask$)(({ track }) => {
39
- track(() => input);
40
- tg.value = require_core.TimeGuard.from(input, config);
41
- });
42
- return tg;
43
- }
44
- /**
45
- * Creates a Qwik Signal of the current time that ticks on a specified
46
- * interval (default 1000ms). Uses `useVisibleTask$` for cleanup.
47
- * Must be called inside `component$`.
48
- */
49
- function useCurrentTime(options) {
50
- const interval = options?.interval ?? 1e3;
51
- const config = options?.config;
52
- const time = (0, _builder_io_qwik.useSignal)(require_core.TimeGuard.now(config));
53
- (0, _builder_io_qwik.useVisibleTask$)(({ cleanup }) => {
54
- const timer = setInterval(() => {
55
- time.value = require_core.TimeGuard.now(config);
56
- }, interval);
57
- cleanup(() => clearInterval(timer));
58
- });
59
- return time;
60
- }
61
- /**
62
- * Creates a Qwik Signal of a relative time string that recalculates
63
- * periodically (default every 60s).
64
- * Must be called inside `component$`.
65
- */
66
- function useRelativeTime(date, options) {
67
- const interval = options?.interval ?? 6e4;
68
- const locale = options?.locale;
69
- const numeric = options?.numeric;
70
- const compute = () => {
71
- const tgDate = require_core.TimeGuard.from(date);
72
- const now = require_core.TimeGuard.now();
73
- return tgDate.since(now).humanize({
74
- locale,
75
- numeric
76
- });
77
- };
78
- const relative = (0, _builder_io_qwik.useSignal)(compute());
79
- (0, _builder_io_qwik.useVisibleTask$)(({ cleanup }) => {
80
- const timer = setInterval(() => {
81
- relative.value = compute();
82
- }, interval);
83
- cleanup(() => clearInterval(timer));
84
- });
85
- return relative;
86
- }
87
- /**
88
- * Creates a Qwik Signal of a TimeRange instance.
89
- * Must be called inside `component$`.
90
- */
91
- function useTimeRange(start, end, config) {
92
- const range = (0, _builder_io_qwik.useSignal)(new require_core.TimeRange(require_core.TimeGuard.from(start, config), require_core.TimeGuard.from(end, config)));
93
- (0, _builder_io_qwik.useTask$)(({ track }) => {
94
- track(() => start);
95
- track(() => end);
96
- range.value = new require_core.TimeRange(require_core.TimeGuard.from(start, config), require_core.TimeGuard.from(end, config));
97
- });
98
- return range;
99
- }
100
- //#endregion
101
- exports.useCurrentTime = useCurrentTime;
102
- exports.useRelativeTime = useRelativeTime;
103
- exports.useTimeGuard = useTimeGuard;
104
- exports.useTimeRange = useTimeRange;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../core-BDQnStek.cjs");let t=require("@builder.io/qwik");function n(n,r){let i=(0,t.useSignal)(e.i.from((0,t.isSignal)(n)?n.value:n,r));return(0,t.useTask$)(({track:a})=>{if((0,t.isSignal)(n)){let t=n;i.value=e.i.from(a(()=>t.value),r)}else i.value=e.i.from(n,r)}),i}function r(n){let r=n?.interval??1e3,i=n?.config,a=(0,t.useSignal)(e.i.now(i));return(0,t.useVisibleTask$)(({cleanup:t})=>{let n=setInterval(()=>{a.value=e.i.now(i)},r);t(()=>clearInterval(n))}),a}function i(n,r){let i=r?.interval??6e4,a=r?.locale,o=r?.numeric,s=()=>e.o(n,{locale:a,numeric:o}),c=(0,t.useSignal)(s());return(0,t.useVisibleTask$)(({cleanup:e})=>{let t=setInterval(()=>{c.value=s()},i);e(()=>clearInterval(t))}),c}function a(n,r,i){let a=(0,t.useSignal)(e.s(n,r,i));return(0,t.useTask$)(({track:t})=>{t(()=>n),t(()=>r),a.value=e.s(n,r,i)}),a}exports.useCurrentTime=r,exports.useRelativeTime=i,exports.useTimeGuard=n,exports.useTimeRange=a;
@@ -1,100 +1,42 @@
1
- /*! time-guard v2.7.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- import { n as TimeGuard, r as TimeRange } from "../core-DWPXk3rz.js";
3
- import { useSignal, useTask$, useVisibleTask$ } from "@builder.io/qwik";
1
+ /*! time-guard v2.9.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
+ import { i as e, o as t, s as n } from "../core-GHK7isoa.js";
3
+ import { isSignal as r, useSignal as i, useTask$ as a, useVisibleTask$ as o } from "@builder.io/qwik";
4
4
  //#region src/qwik.ts
5
- /**
6
- * TimeGuard Qwik Integration
7
- *
8
- * Provides reactive signal-based wrappers for TimeGuard using Qwik's
9
- * resumable reactivity model. All hooks use `useSignal` and
10
- * `useVisibleTask$` with automatic cleanup for optimal performance.
11
- *
12
- * @example
13
- * ```tsx
14
- * import { component$ } from '@builder.io/qwik';
15
- * import { useCurrentTime, useRelativeTime } from '@bereasoftware/time-guard/qwik';
16
- *
17
- * export default component$(() => {
18
- * const now = useCurrentTime({ interval: 1000 });
19
- * const relative = useRelativeTime('2026-05-20T08:00:00');
20
- *
21
- * return (
22
- * <div>
23
- * <h1>{now.value.format('HH:mm:ss')}</h1>
24
- * <p>Published: {relative.value}</p>
25
- * </div>
26
- * );
27
- * });
28
- * ```
29
- */
30
- /**
31
- * Creates a Qwik Signal of a TimeGuard instance.
32
- * Uses `useTask$` to reactively update when input changes.
33
- * Must be called inside `component$`.
34
- */
35
- function useTimeGuard(input, config) {
36
- const tg = useSignal(TimeGuard.from(input, config));
37
- useTask$(({ track }) => {
38
- track(() => input);
39
- tg.value = TimeGuard.from(input, config);
40
- });
41
- return tg;
5
+ function s(t, n) {
6
+ let o = i(e.from(r(t) ? t.value : t, n));
7
+ return a(({ track: i }) => {
8
+ if (r(t)) {
9
+ let r = t;
10
+ o.value = e.from(i(() => r.value), n);
11
+ } else o.value = e.from(t, n);
12
+ }), o;
42
13
  }
43
- /**
44
- * Creates a Qwik Signal of the current time that ticks on a specified
45
- * interval (default 1000ms). Uses `useVisibleTask$` for cleanup.
46
- * Must be called inside `component$`.
47
- */
48
- function useCurrentTime(options) {
49
- const interval = options?.interval ?? 1e3;
50
- const config = options?.config;
51
- const time = useSignal(TimeGuard.now(config));
52
- useVisibleTask$(({ cleanup }) => {
53
- const timer = setInterval(() => {
54
- time.value = TimeGuard.now(config);
55
- }, interval);
56
- cleanup(() => clearInterval(timer));
57
- });
58
- return time;
14
+ function c(t) {
15
+ let n = t?.interval ?? 1e3, r = t?.config, a = i(e.now(r));
16
+ return o(({ cleanup: t }) => {
17
+ let i = setInterval(() => {
18
+ a.value = e.now(r);
19
+ }, n);
20
+ t(() => clearInterval(i));
21
+ }), a;
59
22
  }
60
- /**
61
- * Creates a Qwik Signal of a relative time string that recalculates
62
- * periodically (default every 60s).
63
- * Must be called inside `component$`.
64
- */
65
- function useRelativeTime(date, options) {
66
- const interval = options?.interval ?? 6e4;
67
- const locale = options?.locale;
68
- const numeric = options?.numeric;
69
- const compute = () => {
70
- const tgDate = TimeGuard.from(date);
71
- const now = TimeGuard.now();
72
- return tgDate.since(now).humanize({
73
- locale,
74
- numeric
75
- });
76
- };
77
- const relative = useSignal(compute());
78
- useVisibleTask$(({ cleanup }) => {
79
- const timer = setInterval(() => {
80
- relative.value = compute();
81
- }, interval);
82
- cleanup(() => clearInterval(timer));
83
- });
84
- return relative;
23
+ function l(e, n) {
24
+ let r = n?.interval ?? 6e4, a = n?.locale, s = n?.numeric, c = () => t(e, {
25
+ locale: a,
26
+ numeric: s
27
+ }), l = i(c());
28
+ return o(({ cleanup: e }) => {
29
+ let t = setInterval(() => {
30
+ l.value = c();
31
+ }, r);
32
+ e(() => clearInterval(t));
33
+ }), l;
85
34
  }
86
- /**
87
- * Creates a Qwik Signal of a TimeRange instance.
88
- * Must be called inside `component$`.
89
- */
90
- function useTimeRange(start, end, config) {
91
- const range = useSignal(new TimeRange(TimeGuard.from(start, config), TimeGuard.from(end, config)));
92
- useTask$(({ track }) => {
93
- track(() => start);
94
- track(() => end);
95
- range.value = new TimeRange(TimeGuard.from(start, config), TimeGuard.from(end, config));
96
- });
97
- return range;
35
+ function u(e, t, r) {
36
+ let o = i(n(e, t, r));
37
+ return a(({ track: i }) => {
38
+ i(() => e), i(() => t), o.value = n(e, t, r);
39
+ }), o;
98
40
  }
99
41
  //#endregion
100
- export { useCurrentTime, useRelativeTime, useTimeGuard, useTimeRange };
42
+ export { c as useCurrentTime, l as useRelativeTime, s as useTimeGuard, u as useTimeRange };
package/dist/qwik.d.ts CHANGED
@@ -2,7 +2,11 @@ import { Signal } from '@builder.io/qwik';
2
2
  import { TimeGuard, ITimeGuardConfig, TimeRange } from './core';
3
3
  /**
4
4
  * Creates a Qwik Signal of a TimeGuard instance.
5
- * Uses `useTask$` to reactively update when input changes.
5
+ * Uses `useTask$` to reactively update when input changes — pass a Signal
6
+ * for `input` to make this actually track it via `track()`; a plain value
7
+ * is used once and won't update on its own (`track()` only registers a
8
+ * dependency when it reads a Signal's `.value`, not a closed-over plain
9
+ * variable).
6
10
  * Must be called inside `component$`.
7
11
  */
8
12
  export declare function useTimeGuard(input?: unknown, config?: ITimeGuardConfig): Signal<TimeGuard>;
@@ -1,112 +1 @@
1
- /*! time-guard v2.7.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_chunk = require("../chunk-S8Y6Ng9i.cjs");
4
- const require_core = require("../core-BIDjudpO.cjs");
5
- let react = require("react");
6
- react = require_chunk.__toESM(react, 1);
7
- //#region src/react.ts
8
- /**
9
- * Context to share global TimeGuard configuration across the React component tree.
10
- */
11
- var TimeGuardContext = (0, react.createContext)(void 0);
12
- /**
13
- * React Provider to define default/global TimeGuard configurations.
14
- */
15
- function TimeGuardProvider({ children, config }) {
16
- return react.default.createElement(TimeGuardContext.Provider, { value: config }, children);
17
- }
18
- /**
19
- * React Hook to safely retrieve the global TimeGuard configuration from Context.
20
- */
21
- function useTimeGuardConfig() {
22
- return (0, react.useContext)(TimeGuardContext);
23
- }
24
- /**
25
- * React Hook to create a reactive TimeGuard instance.
26
- * Automatically updates when input or configuration changes.
27
- * Integrates global context configuration as a fallback.
28
- */
29
- function useTimeGuard(input, config) {
30
- const globalConfig = useTimeGuardConfig();
31
- const activeConfig = config ?? globalConfig;
32
- const [tg, setTg] = (0, react.useState)(() => require_core.TimeGuard.from(input, activeConfig));
33
- (0, react.useEffect)(() => {
34
- setTg(require_core.TimeGuard.from(input, activeConfig));
35
- }, [input, activeConfig ? JSON.stringify(activeConfig) : void 0]);
36
- return tg;
37
- }
38
- /**
39
- * React Hook to get a reactive TimeGuard instance representing the current time.
40
- * Automatically updates on a specified interval (default: 1000ms).
41
- * Integrates global context configuration as a fallback.
42
- */
43
- function useCurrentTime(options) {
44
- const globalConfig = useTimeGuardConfig();
45
- const activeConfig = options?.config ?? globalConfig;
46
- const interval = options?.interval ?? 1e3;
47
- const [time, setTime] = (0, react.useState)(() => require_core.TimeGuard.now(activeConfig));
48
- (0, react.useEffect)(() => {
49
- const timer = setInterval(() => {
50
- setTime(require_core.TimeGuard.now(activeConfig));
51
- }, interval);
52
- return () => clearInterval(timer);
53
- }, [interval, activeConfig ? JSON.stringify(activeConfig) : void 0]);
54
- return time;
55
- }
56
- /**
57
- * React Hook that returns a dynamic relative time string that updates periodically.
58
- * Integrates global context configuration as a fallback.
59
- */
60
- function useRelativeTime(date, options) {
61
- const globalConfig = useTimeGuardConfig();
62
- const interval = options?.interval ?? 6e4;
63
- const locale = options?.locale ?? globalConfig?.locale;
64
- const numeric = options?.numeric;
65
- const [relative, setRelative] = (0, react.useState)("");
66
- (0, react.useEffect)(() => {
67
- const update = () => {
68
- const tgDate = require_core.TimeGuard.from(date);
69
- const now = require_core.TimeGuard.now();
70
- setRelative(tgDate.since(now).humanize({
71
- locale,
72
- numeric
73
- }));
74
- };
75
- update();
76
- const timer = setInterval(update, interval);
77
- return () => clearInterval(timer);
78
- }, [
79
- date,
80
- interval,
81
- locale,
82
- numeric
83
- ]);
84
- return relative;
85
- }
86
- /**
87
- * React Hook to create and manage reactive TimeRange instances.
88
- * Automatically updates when start, end, or configuration changes.
89
- */
90
- function useTimeRange(start, end, config) {
91
- const globalConfig = useTimeGuardConfig();
92
- const activeConfig = config ?? globalConfig;
93
- const [range, setRange] = (0, react.useState)(() => {
94
- return new require_core.TimeRange(require_core.TimeGuard.from(start, activeConfig), require_core.TimeGuard.from(end, activeConfig));
95
- });
96
- (0, react.useEffect)(() => {
97
- setRange(new require_core.TimeRange(require_core.TimeGuard.from(start, activeConfig), require_core.TimeGuard.from(end, activeConfig)));
98
- }, [
99
- start,
100
- end,
101
- activeConfig ? JSON.stringify(activeConfig) : void 0
102
- ]);
103
- return range;
104
- }
105
- //#endregion
106
- exports.TimeGuardContext = TimeGuardContext;
107
- exports.TimeGuardProvider = TimeGuardProvider;
108
- exports.useCurrentTime = useCurrentTime;
109
- exports.useRelativeTime = useRelativeTime;
110
- exports.useTimeGuard = useTimeGuard;
111
- exports.useTimeGuardConfig = useTimeGuardConfig;
112
- exports.useTimeRange = useTimeRange;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../chunk-C6qsp3rV.cjs"),t=require("../core-BDQnStek.cjs");let n=require("react");n=e.n(n,1);var r=(0,n.createContext)(void 0);function i({children:e,config:t}){return n.default.createElement(r.Provider,{value:t},e)}function a(){return(0,n.useContext)(r)}function o(e,r){let i=a(),o=r??i,[s,c]=(0,n.useState)(()=>t.i.from(e,o));return(0,n.useEffect)(()=>{c(t.i.from(e,o))},[e,o?.locale,o?.timezone,o?.strict]),s}function s(e){let r=a(),i=e?.config??r,o=e?.interval??1e3,[s,c]=(0,n.useState)(()=>t.i.now(i));return(0,n.useEffect)(()=>{let e=setInterval(()=>{c(t.i.now(i))},o);return()=>clearInterval(e)},[o,i?.locale,i?.timezone,i?.strict]),s}function c(e,r){let i=a(),o=r?.interval??6e4,s=r?.locale??i?.locale,c=r?.numeric,[l,u]=(0,n.useState)(``);return(0,n.useEffect)(()=>{let n=()=>{u(t.o(e,{locale:s,numeric:c}))};n();let r=setInterval(n,o);return()=>clearInterval(r)},[e,o,s,c]),l}function l(e,r,i){let o=a(),s=i??o,[c,l]=(0,n.useState)(()=>t.s(e,r,s));return(0,n.useEffect)(()=>{l(t.s(e,r,s))},[e,r,s?.locale,s?.timezone,s?.strict]),c}exports.TimeGuardContext=r,exports.TimeGuardProvider=i,exports.useCurrentTime=s,exports.useRelativeTime=c,exports.useTimeGuard=o,exports.useTimeGuardConfig=a,exports.useTimeRange=l;
@@ -1,103 +1,69 @@
1
- /*! time-guard v2.7.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- import { n as TimeGuard, r as TimeRange } from "../core-DWPXk3rz.js";
3
- import React, { createContext, useContext, useEffect, useState } from "react";
1
+ /*! time-guard v2.9.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
+ import { i as e, o as t, s as n } from "../core-GHK7isoa.js";
3
+ import r, { createContext as i, useContext as a, useEffect as o, useState as s } from "react";
4
4
  //#region src/react.ts
5
- /**
6
- * Context to share global TimeGuard configuration across the React component tree.
7
- */
8
- var TimeGuardContext = createContext(void 0);
9
- /**
10
- * React Provider to define default/global TimeGuard configurations.
11
- */
12
- function TimeGuardProvider({ children, config }) {
13
- return React.createElement(TimeGuardContext.Provider, { value: config }, children);
5
+ var c = i(void 0);
6
+ function l({ children: e, config: t }) {
7
+ return r.createElement(c.Provider, { value: t }, e);
14
8
  }
15
- /**
16
- * React Hook to safely retrieve the global TimeGuard configuration from Context.
17
- */
18
- function useTimeGuardConfig() {
19
- return useContext(TimeGuardContext);
9
+ function u() {
10
+ return a(c);
20
11
  }
21
- /**
22
- * React Hook to create a reactive TimeGuard instance.
23
- * Automatically updates when input or configuration changes.
24
- * Integrates global context configuration as a fallback.
25
- */
26
- function useTimeGuard(input, config) {
27
- const globalConfig = useTimeGuardConfig();
28
- const activeConfig = config ?? globalConfig;
29
- const [tg, setTg] = useState(() => TimeGuard.from(input, activeConfig));
30
- useEffect(() => {
31
- setTg(TimeGuard.from(input, activeConfig));
32
- }, [input, activeConfig ? JSON.stringify(activeConfig) : void 0]);
33
- return tg;
12
+ function d(t, n) {
13
+ let r = u(), i = n ?? r, [a, c] = s(() => e.from(t, i));
14
+ return o(() => {
15
+ c(e.from(t, i));
16
+ }, [
17
+ t,
18
+ i?.locale,
19
+ i?.timezone,
20
+ i?.strict
21
+ ]), a;
34
22
  }
35
- /**
36
- * React Hook to get a reactive TimeGuard instance representing the current time.
37
- * Automatically updates on a specified interval (default: 1000ms).
38
- * Integrates global context configuration as a fallback.
39
- */
40
- function useCurrentTime(options) {
41
- const globalConfig = useTimeGuardConfig();
42
- const activeConfig = options?.config ?? globalConfig;
43
- const interval = options?.interval ?? 1e3;
44
- const [time, setTime] = useState(() => TimeGuard.now(activeConfig));
45
- useEffect(() => {
46
- const timer = setInterval(() => {
47
- setTime(TimeGuard.now(activeConfig));
48
- }, interval);
49
- return () => clearInterval(timer);
50
- }, [interval, activeConfig ? JSON.stringify(activeConfig) : void 0]);
51
- return time;
23
+ function f(t) {
24
+ let n = u(), r = t?.config ?? n, i = t?.interval ?? 1e3, [a, c] = s(() => e.now(r));
25
+ return o(() => {
26
+ let t = setInterval(() => {
27
+ c(e.now(r));
28
+ }, i);
29
+ return () => clearInterval(t);
30
+ }, [
31
+ i,
32
+ r?.locale,
33
+ r?.timezone,
34
+ r?.strict
35
+ ]), a;
52
36
  }
53
- /**
54
- * React Hook that returns a dynamic relative time string that updates periodically.
55
- * Integrates global context configuration as a fallback.
56
- */
57
- function useRelativeTime(date, options) {
58
- const globalConfig = useTimeGuardConfig();
59
- const interval = options?.interval ?? 6e4;
60
- const locale = options?.locale ?? globalConfig?.locale;
61
- const numeric = options?.numeric;
62
- const [relative, setRelative] = useState("");
63
- useEffect(() => {
64
- const update = () => {
65
- const tgDate = TimeGuard.from(date);
66
- const now = TimeGuard.now();
67
- setRelative(tgDate.since(now).humanize({
68
- locale,
69
- numeric
37
+ function p(e, n) {
38
+ let r = u(), i = n?.interval ?? 6e4, a = n?.locale ?? r?.locale, c = n?.numeric, [l, d] = s("");
39
+ return o(() => {
40
+ let n = () => {
41
+ d(t(e, {
42
+ locale: a,
43
+ numeric: c
70
44
  }));
71
45
  };
72
- update();
73
- const timer = setInterval(update, interval);
74
- return () => clearInterval(timer);
46
+ n();
47
+ let r = setInterval(n, i);
48
+ return () => clearInterval(r);
75
49
  }, [
76
- date,
77
- interval,
78
- locale,
79
- numeric
80
- ]);
81
- return relative;
50
+ e,
51
+ i,
52
+ a,
53
+ c
54
+ ]), l;
82
55
  }
83
- /**
84
- * React Hook to create and manage reactive TimeRange instances.
85
- * Automatically updates when start, end, or configuration changes.
86
- */
87
- function useTimeRange(start, end, config) {
88
- const globalConfig = useTimeGuardConfig();
89
- const activeConfig = config ?? globalConfig;
90
- const [range, setRange] = useState(() => {
91
- return new TimeRange(TimeGuard.from(start, activeConfig), TimeGuard.from(end, activeConfig));
92
- });
93
- useEffect(() => {
94
- setRange(new TimeRange(TimeGuard.from(start, activeConfig), TimeGuard.from(end, activeConfig)));
56
+ function m(e, t, r) {
57
+ let i = u(), a = r ?? i, [c, l] = s(() => n(e, t, a));
58
+ return o(() => {
59
+ l(n(e, t, a));
95
60
  }, [
96
- start,
97
- end,
98
- activeConfig ? JSON.stringify(activeConfig) : void 0
99
- ]);
100
- return range;
61
+ e,
62
+ t,
63
+ a?.locale,
64
+ a?.timezone,
65
+ a?.strict
66
+ ]), c;
101
67
  }
102
68
  //#endregion
103
- export { TimeGuardContext, TimeGuardProvider, useCurrentTime, useRelativeTime, useTimeGuard, useTimeGuardConfig, useTimeRange };
69
+ export { c as TimeGuardContext, l as TimeGuardProvider, f as useCurrentTime, p as useRelativeTime, d as useTimeGuard, u as useTimeGuardConfig, m as useTimeRange };
@@ -1,127 +1 @@
1
- /*! time-guard v2.7.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_core = require("../core-BIDjudpO.cjs");
4
- let solid_js = require("solid-js");
5
- //#region src/solid.ts
6
- /**
7
- * TimeGuard — SolidJS Integration
8
- *
9
- * Provides reactive signal-based wrappers for TimeGuard using Solid's
10
- * fine-grained reactivity system. All hooks return signals (`Accessor`)
11
- * that automatically update without re-rendering the entire component tree.
12
- *
13
- * @example
14
- * ```tsx
15
- * import { useCurrentTime, useRelativeTime } from '@bereasoftware/time-guard/solid';
16
- *
17
- * function Clock() {
18
- * const now = useCurrentTime({ interval: 1000 });
19
- * const relative = useRelativeTime('2026-05-20T08:00:00');
20
- *
21
- * return (
22
- * <div>
23
- * <h1>{now().format('HH:mm:ss')}</h1>
24
- * <p>Published: {relative()}</p>
25
- * </div>
26
- * );
27
- * }
28
- * ```
29
- */
30
- /**
31
- * Context key for providing global TimeGuard configuration.
32
- * Use Solid's `createContext` + `useContext` at the app level.
33
- */
34
- var TimeGuardConfigContext = Symbol("TimeGuardConfig");
35
- /**
36
- * Creates a reactive signal of a TimeGuard instance.
37
- * The signal updates reactively when `input` changes.
38
- *
39
- * ```tsx
40
- * const tg = useTimeGuard('2026-05-20');
41
- * return <p>{tg().format('dddd, DD MMMM YYYY')}</p>;
42
- * ```
43
- */
44
- function useTimeGuard(input, config) {
45
- const [tg, setTg] = (0, solid_js.createSignal)(require_core.TimeGuard.from(input, config));
46
- (0, solid_js.createEffect)(() => {
47
- const _input = input;
48
- setTg(() => require_core.TimeGuard.from(_input, config));
49
- });
50
- return tg;
51
- }
52
- /**
53
- * Creates a signal of the current time that ticks on a specified interval
54
- * (default 1000ms). Clears the interval on cleanup.
55
- *
56
- * ```tsx
57
- * const now = useCurrentTime({ interval: 1000 });
58
- * return <p>{now().format('HH:mm:ss')}</p>;
59
- * ```
60
- */
61
- function useCurrentTime(options) {
62
- const interval = options?.interval ?? 1e3;
63
- const config = options?.config;
64
- const [time, setTime] = (0, solid_js.createSignal)(require_core.TimeGuard.now(config));
65
- const timer = setInterval(() => {
66
- setTime(require_core.TimeGuard.now(config));
67
- }, interval);
68
- (0, solid_js.onCleanup)(() => {
69
- clearInterval(timer);
70
- });
71
- return time;
72
- }
73
- /**
74
- * Creates a signal of a relative time string that recalculates periodically
75
- * (default every 60s).
76
- *
77
- * ```tsx
78
- * const relative = useRelativeTime('2026-05-20T08:00:00', { locale: 'es' });
79
- * return <p>{relative()}</p>;
80
- * ```
81
- */
82
- function useRelativeTime(date, options) {
83
- const interval = options?.interval ?? 6e4;
84
- const locale = options?.locale;
85
- const numeric = options?.numeric;
86
- const compute = () => {
87
- const tgDate = require_core.TimeGuard.from(date);
88
- const now = require_core.TimeGuard.now();
89
- return tgDate.since(now).humanize({
90
- locale,
91
- numeric
92
- });
93
- };
94
- const [relative, setRelative] = (0, solid_js.createSignal)(compute());
95
- const timer = setInterval(() => {
96
- setRelative(compute());
97
- }, interval);
98
- (0, solid_js.onCleanup)(() => {
99
- clearInterval(timer);
100
- });
101
- return relative;
102
- }
103
- /**
104
- * Creates a signal of a TimeRange instance.
105
- *
106
- * ```tsx
107
- * const range = useTimeRange('2026-05-20', '2026-06-01');
108
- * return <p>Duration: {range().humanize()}</p>;
109
- * ```
110
- */
111
- function useTimeRange(start, end, config) {
112
- const [range, setRange] = (0, solid_js.createSignal)(new require_core.TimeRange(require_core.TimeGuard.from(start, config), require_core.TimeGuard.from(end, config)));
113
- (0, solid_js.createEffect)(() => {
114
- const _start = start;
115
- const _end = end;
116
- const startTg = require_core.TimeGuard.from(_start, config);
117
- const endTg = require_core.TimeGuard.from(_end, config);
118
- setRange(() => new require_core.TimeRange(startTg, endTg));
119
- });
120
- return range;
121
- }
122
- //#endregion
123
- exports.TimeGuardConfigContext = TimeGuardConfigContext;
124
- exports.useCurrentTime = useCurrentTime;
125
- exports.useRelativeTime = useRelativeTime;
126
- exports.useTimeGuard = useTimeGuard;
127
- exports.useTimeRange = useTimeRange;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../core-BDQnStek.cjs");let t=require("solid-js");var n=Symbol(`TimeGuardConfig`);function r(e){return typeof e==`function`?e():e}function i(n,i){let[a,o]=(0,t.createSignal)(e.i.from(r(n),i));return(0,t.createEffect)(()=>{o(()=>e.i.from(r(n),i))}),a}function a(n){let r=n?.interval??1e3,i=n?.config,[a,o]=(0,t.createSignal)(e.i.now(i)),s=setInterval(()=>{o(e.i.now(i))},r);return(0,t.onCleanup)(()=>{clearInterval(s)}),a}function o(n,r){let i=r?.interval??6e4,a=r?.locale,o=r?.numeric,s=()=>e.o(n,{locale:a,numeric:o}),[c,l]=(0,t.createSignal)(s()),u=setInterval(()=>{l(s())},i);return(0,t.onCleanup)(()=>{clearInterval(u)}),c}function s(n,r,i){let[a,o]=(0,t.createSignal)(e.s(n,r,i));return(0,t.createEffect)(()=>{let t=n,a=r;o(()=>e.s(t,a,i))}),a}exports.TimeGuardConfigContext=n,exports.useCurrentTime=a,exports.useRelativeTime=o,exports.useTimeGuard=i,exports.useTimeRange=s;