@bereasoftware/time-guard 2.6.0 → 2.7.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 (98) hide show
  1. package/README.en.md +232 -0
  2. package/README.md +259 -4
  3. package/dist/{types/adapters → adapters}/temporal.adapter.d.ts +4 -9
  4. package/dist/angular/index.cjs +148 -0
  5. package/dist/angular/index.d.ts +2 -0
  6. package/dist/angular/index.es.js +143 -0
  7. package/dist/angular.d.ts +59 -0
  8. package/dist/calendars/index.cjs +357 -2
  9. package/dist/calendars/index.es.js +99 -68
  10. package/dist/chunk-Ddh6569R.cjs +36 -0
  11. package/dist/core-BAd7GYfw.js +1809 -0
  12. package/dist/core-CafqOI7W.cjs +1892 -0
  13. package/dist/core.d.ts +224 -0
  14. package/dist/index.d.ts +9 -0
  15. package/dist/locales/african.locale.d.ts +7 -0
  16. package/dist/locales/index.cjs +7 -2
  17. package/dist/{types/locales → locales}/index.d.ts +2 -2
  18. package/dist/locales/index.es.js +3 -2797
  19. package/dist/locales/south-american.locale.d.ts +7 -0
  20. package/dist/locales-C2-lOmC8.cjs +3537 -0
  21. package/dist/locales-CcuSu4P1.js +3514 -0
  22. package/dist/native/index.cjs +48 -0
  23. package/dist/native/index.d.ts +2 -0
  24. package/dist/native/index.es.js +18 -0
  25. package/dist/native.d.ts +9 -0
  26. package/dist/plugins/advanced-format.cjs +105 -2
  27. package/dist/plugins/advanced-format.es.js +63 -45
  28. package/dist/plugins/duration.cjs +258 -2
  29. package/dist/plugins/duration.es.js +165 -61
  30. package/dist/plugins/index.d.ts +10 -0
  31. package/dist/plugins/relative-time.cjs +166 -2
  32. package/dist/plugins/relative-time.es.js +74 -37
  33. package/dist/qwik/index.cjs +104 -0
  34. package/dist/qwik/index.d.ts +2 -0
  35. package/dist/qwik/index.es.js +100 -0
  36. package/dist/qwik.d.ts +32 -0
  37. package/dist/react/index.cjs +112 -0
  38. package/dist/react/index.d.ts +2 -0
  39. package/dist/react/index.es.js +103 -0
  40. package/dist/react.d.ts +46 -0
  41. package/dist/solid/index.cjs +127 -0
  42. package/dist/solid/index.d.ts +2 -0
  43. package/dist/solid/index.es.js +122 -0
  44. package/dist/solid.d.ts +53 -0
  45. package/dist/svelte/index.cjs +398 -0
  46. package/dist/svelte/index.d.ts +2 -0
  47. package/dist/svelte/index.es.js +393 -0
  48. package/dist/svelte.d.ts +88 -0
  49. package/dist/time-guard.cjs +7359 -4
  50. package/dist/time-guard.d.ts +2 -0
  51. package/dist/time-guard.es.js +3625 -8073
  52. package/dist/time-guard.iife.js +13549 -4
  53. package/dist/time-guard.umd.js +13550 -4
  54. package/dist/types/index.d.ts +651 -128
  55. package/dist/vue/index.cjs +143 -0
  56. package/dist/vue/index.d.ts +2 -0
  57. package/dist/vue/index.es.js +137 -0
  58. package/dist/vue.d.ts +35 -0
  59. package/package.json +111 -17
  60. package/dist/calendars/index.cjs.map +0 -1
  61. package/dist/calendars/index.es.js.map +0 -1
  62. package/dist/locales/index.cjs.map +0 -1
  63. package/dist/locales/index.es.js.map +0 -1
  64. package/dist/plugins/advanced-format.cjs.map +0 -1
  65. package/dist/plugins/advanced-format.es.js.map +0 -1
  66. package/dist/plugins/duration.cjs.map +0 -1
  67. package/dist/plugins/duration.es.js.map +0 -1
  68. package/dist/plugins/relative-time.cjs.map +0 -1
  69. package/dist/plugins/relative-time.es.js.map +0 -1
  70. package/dist/time-guard.cjs.map +0 -1
  71. package/dist/time-guard.es.js.map +0 -1
  72. package/dist/time-guard.iife.js.map +0 -1
  73. package/dist/time-guard.umd.js.map +0 -1
  74. package/dist/types/plugins/index.d.ts +0 -10
  75. package/dist/types/types/index.d.ts +0 -586
  76. /package/dist/{types/calendars → calendars}/calendar.manager.d.ts +0 -0
  77. /package/dist/{types/calendars → calendars}/index.d.ts +0 -0
  78. /package/dist/{types/formatters → formatters}/date.formatter.d.ts +0 -0
  79. /package/dist/{types/locales → locales}/additional.locale.d.ts +0 -0
  80. /package/dist/{types/locales → locales}/asian.locale.d.ts +0 -0
  81. /package/dist/{types/locales → locales}/english.locale.d.ts +0 -0
  82. /package/dist/{types/locales → locales}/european.locale.d.ts +0 -0
  83. /package/dist/{types/locales → locales}/locale.manager.d.ts +0 -0
  84. /package/dist/{types/locales → locales}/middle-eastern.locale.d.ts +0 -0
  85. /package/dist/{types/locales → locales}/nordic.locale.d.ts +0 -0
  86. /package/dist/{types/locales → locales}/romance.locale.d.ts +0 -0
  87. /package/dist/{types/locales → locales}/slavic.locale.d.ts +0 -0
  88. /package/dist/{types/locales → locales}/spanish.locale.d.ts +0 -0
  89. /package/dist/{types/plugins → plugins}/advanced-format/index.d.ts +0 -0
  90. /package/dist/{types/plugins → plugins}/advanced-format.d.ts +0 -0
  91. /package/dist/{types/plugins → plugins}/duration/index.d.ts +0 -0
  92. /package/dist/{types/plugins → plugins}/duration/types.d.ts +0 -0
  93. /package/dist/{types/plugins → plugins}/duration.d.ts +0 -0
  94. /package/dist/{types/plugins → plugins}/manager.d.ts +0 -0
  95. /package/dist/{types/plugins → plugins}/relative-time/index.d.ts +0 -0
  96. /package/dist/{types/plugins → plugins}/relative-time/types.d.ts +0 -0
  97. /package/dist/{types/plugins → plugins}/relative-time.d.ts +0 -0
  98. /package/dist/{types/utils → utils}/duration-locale.d.ts +0 -0
@@ -0,0 +1,104 @@
1
+ /*! time-guard v2.7.0 | (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-CafqOI7W.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;
@@ -0,0 +1,2 @@
1
+ export * from '../qwik'
2
+ export {}
@@ -0,0 +1,100 @@
1
+ /*! time-guard v2.7.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
+ import { n as TimeGuard, r as TimeRange } from "../core-BAd7GYfw.js";
3
+ import { useSignal, useTask$, useVisibleTask$ } from "@builder.io/qwik";
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;
42
+ }
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;
59
+ }
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;
85
+ }
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;
98
+ }
99
+ //#endregion
100
+ export { useCurrentTime, useRelativeTime, useTimeGuard, useTimeRange };
package/dist/qwik.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Signal } from '@builder.io/qwik';
2
+ import { TimeGuard, ITimeGuardConfig, TimeRange } from './core';
3
+ /**
4
+ * Creates a Qwik Signal of a TimeGuard instance.
5
+ * Uses `useTask$` to reactively update when input changes.
6
+ * Must be called inside `component$`.
7
+ */
8
+ export declare function useTimeGuard(input?: unknown, config?: ITimeGuardConfig): Signal<TimeGuard>;
9
+ /**
10
+ * Creates a Qwik Signal of the current time that ticks on a specified
11
+ * interval (default 1000ms). Uses `useVisibleTask$` for cleanup.
12
+ * Must be called inside `component$`.
13
+ */
14
+ export declare function useCurrentTime(options?: {
15
+ interval?: number;
16
+ config?: ITimeGuardConfig;
17
+ }): Signal<TimeGuard>;
18
+ /**
19
+ * Creates a Qwik Signal of a relative time string that recalculates
20
+ * periodically (default every 60s).
21
+ * Must be called inside `component$`.
22
+ */
23
+ export declare function useRelativeTime(date: unknown, options?: {
24
+ interval?: number;
25
+ locale?: string;
26
+ numeric?: 'always' | 'auto';
27
+ }): Signal<string>;
28
+ /**
29
+ * Creates a Qwik Signal of a TimeRange instance.
30
+ * Must be called inside `component$`.
31
+ */
32
+ export declare function useTimeRange(start: unknown, end: unknown, config?: ITimeGuardConfig): Signal<TimeRange>;
@@ -0,0 +1,112 @@
1
+ /*! time-guard v2.7.0 | (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-Ddh6569R.cjs");
4
+ const require_core = require("../core-CafqOI7W.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;
@@ -0,0 +1,2 @@
1
+ export * from '../react'
2
+ export {}
@@ -0,0 +1,103 @@
1
+ /*! time-guard v2.7.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
+ import { n as TimeGuard, r as TimeRange } from "../core-BAd7GYfw.js";
3
+ import React, { createContext, useContext, useEffect, useState } from "react";
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);
14
+ }
15
+ /**
16
+ * React Hook to safely retrieve the global TimeGuard configuration from Context.
17
+ */
18
+ function useTimeGuardConfig() {
19
+ return useContext(TimeGuardContext);
20
+ }
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;
34
+ }
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;
52
+ }
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
70
+ }));
71
+ };
72
+ update();
73
+ const timer = setInterval(update, interval);
74
+ return () => clearInterval(timer);
75
+ }, [
76
+ date,
77
+ interval,
78
+ locale,
79
+ numeric
80
+ ]);
81
+ return relative;
82
+ }
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)));
95
+ }, [
96
+ start,
97
+ end,
98
+ activeConfig ? JSON.stringify(activeConfig) : void 0
99
+ ]);
100
+ return range;
101
+ }
102
+ //#endregion
103
+ export { TimeGuardContext, TimeGuardProvider, useCurrentTime, useRelativeTime, useTimeGuard, useTimeGuardConfig, useTimeRange };
@@ -0,0 +1,46 @@
1
+ import { default as React, ReactNode } from 'react';
2
+ import { TimeGuard, ITimeGuardConfig, TimeRange } from './core';
3
+ /**
4
+ * Context to share global TimeGuard configuration across the React component tree.
5
+ */
6
+ export declare const TimeGuardContext: React.Context<ITimeGuardConfig | undefined>;
7
+ /**
8
+ * React Provider to define default/global TimeGuard configurations.
9
+ */
10
+ export declare function TimeGuardProvider({ children, config, }: {
11
+ children: ReactNode;
12
+ config?: ITimeGuardConfig;
13
+ }): React.FunctionComponentElement<React.ProviderProps<ITimeGuardConfig | undefined>>;
14
+ /**
15
+ * React Hook to safely retrieve the global TimeGuard configuration from Context.
16
+ */
17
+ export declare function useTimeGuardConfig(): ITimeGuardConfig | undefined;
18
+ /**
19
+ * React Hook to create a reactive TimeGuard instance.
20
+ * Automatically updates when input or configuration changes.
21
+ * Integrates global context configuration as a fallback.
22
+ */
23
+ export declare function useTimeGuard(input?: unknown, config?: ITimeGuardConfig): TimeGuard;
24
+ /**
25
+ * React Hook to get a reactive TimeGuard instance representing the current time.
26
+ * Automatically updates on a specified interval (default: 1000ms).
27
+ * Integrates global context configuration as a fallback.
28
+ */
29
+ export declare function useCurrentTime(options?: {
30
+ interval?: number;
31
+ config?: ITimeGuardConfig;
32
+ }): TimeGuard;
33
+ /**
34
+ * React Hook that returns a dynamic relative time string that updates periodically.
35
+ * Integrates global context configuration as a fallback.
36
+ */
37
+ export declare function useRelativeTime(date: unknown, options?: {
38
+ interval?: number;
39
+ locale?: string;
40
+ numeric?: 'always' | 'auto';
41
+ }): string;
42
+ /**
43
+ * React Hook to create and manage reactive TimeRange instances.
44
+ * Automatically updates when start, end, or configuration changes.
45
+ */
46
+ export declare function useTimeRange(start: unknown, end: unknown, config?: ITimeGuardConfig): TimeRange;
@@ -0,0 +1,127 @@
1
+ /*! time-guard v2.7.0 | (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-CafqOI7W.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;
@@ -0,0 +1,2 @@
1
+ export * from '../solid'
2
+ export {}