@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,393 +1,134 @@
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
- Array.isArray;
4
- Array.prototype.indexOf;
5
- Array.prototype.includes;
6
- Array.from;
7
- Array.prototype;
8
- var noop = () => {};
9
- /** @param {Array<() => void>} arr */
10
- function run_all(arr) {
11
- for (var i = 0; i < arr.length; i++) arr[i]();
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
+ Array.isArray, Array.prototype.indexOf, Array.prototype.includes, Array.from, Array.prototype;
4
+ var r = () => {};
5
+ function i(e) {
6
+ for (var t = 0; t < e.length; t++) e[t]();
12
7
  }
13
8
  //#endregion
14
9
  //#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/internal/client/constants.js
15
- var CLEAN = 1024;
16
- var DIRTY = 2048;
17
- var MAYBE_DIRTY = 4096;
18
- /**
19
- * 'Transparent' effects do not create a transition boundary.
20
- * This is on a block effect 99% of the time but may also be on a branch effect if its parent block effect was pruned
21
- */
22
- var EFFECT_TRANSPARENT = 65536;
23
- var EFFECT_PRESERVED = 1 << 19;
24
- new class StaleReactionError extends Error {
10
+ var a = 1024, o = 2048, s = 4096, c = 65536, l = 1 << 19;
11
+ new class extends Error {
25
12
  name = "StaleReactionError";
26
13
  message = "The reaction that called `getAbortSignal()` was re-run or destroyed";
27
- }();
28
- globalThis.document?.contentType;
14
+ }(), globalThis.document?.contentType;
29
15
  //#endregion
30
16
  //#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/internal/client/reactivity/equality.js
31
- /**
32
- * @param {unknown} a
33
- * @param {unknown} b
34
- * @returns {boolean}
35
- */
36
- function safe_not_equal(a, b) {
37
- return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
17
+ function u(e, t) {
18
+ return e == e ? e !== t || typeof e == "object" && !!e || typeof e == "function" : t == t;
38
19
  }
39
- ~(DIRTY | MAYBE_DIRTY | CLEAN);
20
+ ~(o | s | a);
40
21
  //#endregion
41
22
  //#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/store/utils.js
42
- /** @import { Readable } from './public' */
43
- /**
44
- * @template T
45
- * @param {Readable<T> | null | undefined} store
46
- * @param {(value: T) => void} run
47
- * @param {(value: T) => void} [invalidate]
48
- * @returns {() => void}
49
- */
50
- function subscribe_to_store(store, run, invalidate) {
51
- if (store == null) {
52
- run(void 0);
53
- if (invalidate) invalidate(void 0);
54
- return noop;
55
- }
56
- const unsub = untrack(() => store.subscribe(run, invalidate));
57
- return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
23
+ function d(e, t, n) {
24
+ if (e == null) return t(void 0), n && n(void 0), r;
25
+ let i = _(() => e.subscribe(t, n));
26
+ return i.unsubscribe ? () => i.unsubscribe() : i;
58
27
  }
59
28
  //#endregion
60
29
  //#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/store/shared/index.js
61
- /** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from '../public.js' */
62
- /** @import { Stores, StoresValues, SubscribeInvalidateTuple } from '../private.js' */
63
- /**
64
- * @type {Array<SubscribeInvalidateTuple<any> | any>}
65
- */
66
- var subscriber_queue = [];
67
- /**
68
- * Creates a `Readable` store that allows reading by subscription.
69
- *
70
- * @template T
71
- * @param {T} [value] initial value
72
- * @param {StartStopNotifier<T>} [start]
73
- * @returns {Readable<T>}
74
- */
75
- function readable(value, start) {
76
- return { subscribe: writable(value, start).subscribe };
30
+ var f = [];
31
+ function p(e, t) {
32
+ return { subscribe: m(e, t).subscribe };
77
33
  }
78
- /**
79
- * Create a `Writable` store that allows both updating and reading by subscription.
80
- *
81
- * @template T
82
- * @param {T} [value] initial value
83
- * @param {StartStopNotifier<T>} [start]
84
- * @returns {Writable<T>}
85
- */
86
- function writable(value, start = noop) {
87
- /** @type {Unsubscriber | null} */
88
- let stop = null;
89
- /** @type {Set<SubscribeInvalidateTuple<T>>} */
90
- const subscribers = /* @__PURE__ */ new Set();
91
- /**
92
- * @param {T} new_value
93
- * @returns {void}
94
- */
95
- function set(new_value) {
96
- if (safe_not_equal(value, new_value)) {
97
- value = new_value;
98
- if (stop) {
99
- const run_queue = !subscriber_queue.length;
100
- for (const subscriber of subscribers) {
101
- subscriber[1]();
102
- subscriber_queue.push(subscriber, value);
103
- }
104
- if (run_queue) {
105
- for (let i = 0; i < subscriber_queue.length; i += 2) subscriber_queue[i][0](subscriber_queue[i + 1]);
106
- subscriber_queue.length = 0;
107
- }
34
+ function m(e, t = r) {
35
+ let n = null, i = /* @__PURE__ */ new Set();
36
+ function a(t) {
37
+ if (u(e, t) && (e = t, n)) {
38
+ let t = !f.length;
39
+ for (let t of i) t[1](), f.push(t, e);
40
+ if (t) {
41
+ for (let e = 0; e < f.length; e += 2) f[e][0](f[e + 1]);
42
+ f.length = 0;
108
43
  }
109
44
  }
110
45
  }
111
- /**
112
- * @param {Updater<T>} fn
113
- * @returns {void}
114
- */
115
- function update(fn) {
116
- set(fn(value));
46
+ function o(t) {
47
+ a(t(e));
117
48
  }
118
- /**
119
- * @param {Subscriber<T>} run
120
- * @param {() => void} [invalidate]
121
- * @returns {Unsubscriber}
122
- */
123
- function subscribe(run, invalidate = noop) {
124
- /** @type {SubscribeInvalidateTuple<T>} */
125
- const subscriber = [run, invalidate];
126
- subscribers.add(subscriber);
127
- if (subscribers.size === 1) stop = start(set, update) || noop;
128
- run(value);
129
- return () => {
130
- subscribers.delete(subscriber);
131
- if (subscribers.size === 0 && stop) {
132
- stop();
133
- stop = null;
134
- }
49
+ function s(s, c = r) {
50
+ let l = [s, c];
51
+ return i.add(l), i.size === 1 && (n = t(a, o) || r), s(e), () => {
52
+ i.delete(l), i.size === 0 && n && (n(), n = null);
135
53
  };
136
54
  }
137
55
  return {
138
- set,
139
- update,
140
- subscribe
56
+ set: a,
57
+ update: o,
58
+ subscribe: s
141
59
  };
142
60
  }
143
- /**
144
- * Derived value store by synchronizing one or more readable stores and
145
- * applying an aggregation function over its input values.
146
- *
147
- * @template {Stores} S
148
- * @template T
149
- * @overload
150
- * @param {S} stores
151
- * @param {(values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void} fn
152
- * @param {T} [initial_value]
153
- * @returns {Readable<T>}
154
- */
155
- /**
156
- * Derived value store by synchronizing one or more readable stores and
157
- * applying an aggregation function over its input values.
158
- *
159
- * @template {Stores} S
160
- * @template T
161
- * @overload
162
- * @param {S} stores
163
- * @param {(values: StoresValues<S>) => T} fn
164
- * @param {T} [initial_value]
165
- * @returns {Readable<T>}
166
- */
167
- /**
168
- * @template {Stores} S
169
- * @template T
170
- * @param {S} stores
171
- * @param {Function} fn
172
- * @param {T} [initial_value]
173
- * @returns {Readable<T>}
174
- */
175
- function derived(stores, fn, initial_value) {
176
- const single = !Array.isArray(stores);
177
- /** @type {Array<Readable<any>>} */
178
- const stores_array = single ? [stores] : stores;
179
- if (!stores_array.every(Boolean)) throw new Error("derived() expects stores as input, got a falsy value");
180
- const auto = fn.length < 2;
181
- return readable(initial_value, (set, update) => {
182
- let started = false;
183
- /** @type {T[]} */
184
- const values = [];
185
- let pending = 0;
186
- let cleanup = noop;
187
- const sync = () => {
188
- if (pending) return;
189
- cleanup();
190
- const result = fn(single ? values[0] : values, set, update);
191
- if (auto) set(result);
192
- else cleanup = typeof result === "function" ? result : noop;
193
- };
194
- const unsubscribers = stores_array.map((store, i) => subscribe_to_store(store, (value) => {
195
- values[i] = value;
196
- pending &= ~(1 << i);
197
- if (started) sync();
61
+ function h(e, t, n) {
62
+ let a = !Array.isArray(e), o = a ? [e] : e;
63
+ if (!o.every(Boolean)) throw Error("derived() expects stores as input, got a falsy value");
64
+ let s = t.length < 2;
65
+ return p(n, (e, n) => {
66
+ let c = !1, l = [], u = 0, f = r, p = () => {
67
+ if (u) return;
68
+ f();
69
+ let i = t(a ? l[0] : l, e, n);
70
+ s ? e(i) : f = typeof i == "function" ? i : r;
71
+ }, m = o.map((e, t) => d(e, (e) => {
72
+ l[t] = e, u &= ~(1 << t), c && p();
198
73
  }, () => {
199
- pending |= 1 << i;
74
+ u |= 1 << t;
200
75
  }));
201
- started = true;
202
- sync();
203
- return function stop() {
204
- run_all(unsubscribers);
205
- cleanup();
206
- started = false;
76
+ return c = !0, p(), function() {
77
+ i(m), f(), c = !1;
207
78
  };
208
79
  });
209
80
  }
210
- EFFECT_TRANSPARENT | EFFECT_PRESERVED;
81
+ c | l;
211
82
  //#endregion
212
83
  //#region node_modules/.pnpm/svelte@5.55.9_@typescript-eslint+types@8.59.4/node_modules/svelte/src/internal/client/runtime.js
213
- var untracking = false;
214
- /**
215
- * When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived) or [`$effect`](https://svelte.dev/docs/svelte/$effect),
216
- * any state read inside `fn` will not be treated as a dependency.
217
- *
218
- * ```ts
219
- * $effect(() => {
220
- * // this will run when `data` changes, but not when `time` changes
221
- * save(data, {
222
- * timestamp: untrack(() => time)
223
- * });
224
- * });
225
- * ```
226
- * @template T
227
- * @param {() => T} fn
228
- * @returns {T}
229
- */
230
- function untrack(fn) {
231
- var previous_untracking = untracking;
84
+ var g = !1;
85
+ function _(e) {
86
+ var t = g;
232
87
  try {
233
- untracking = true;
234
- return fn();
88
+ return g = !0, e();
235
89
  } finally {
236
- untracking = previous_untracking;
90
+ g = t;
237
91
  }
238
92
  }
239
93
  //#endregion
240
94
  //#region src/svelte.ts
241
- /**
242
- * TimeGuard Svelte 5 Integration
243
- *
244
- * Provides reactive stores and lifecycle-managed wrappers for TimeGuard.
245
- * Compatible with both Svelte 4 (`$store` auto-subscription) and
246
- * Svelte 5 (`$state` + `get()` from stores).
247
- *
248
- * @example
249
- * ```svelte
250
- * <script lang="ts">
251
- * import { useCurrentTime, useRelativeTime } from '@bereasoftware/time-guard/svelte';
252
- *
253
- * const now = useCurrentTime({ interval: 1000 });
254
- * const relative = useRelativeTime('2026-05-20T08:00:00');
255
- * <\/script>
256
- *
257
- * <h1>{$now.format('HH:mm:ss')}</h1>
258
- * <p>Published: {$relative}</p>
259
- * ```
260
- */
261
- /**
262
- * Duck-type check: is this a Svelte store (has `subscribe`)?
263
- */
264
- function isStore(val) {
265
- return typeof val === "object" && val !== null && "subscribe" in val && typeof val.subscribe === "function";
95
+ function v(e) {
96
+ return typeof e == "object" && !!e && "subscribe" in e && typeof e.subscribe == "function";
266
97
  }
267
- /**
268
- * Coerce a plain value or a store into a Readable store.
269
- */
270
- function toStore(val) {
271
- return isStore(val) ? val : readable(val);
98
+ function y(e) {
99
+ return v(e) ? e : p(e);
272
100
  }
273
- /**
274
- * Injection-key symbol to retrieve a global TimeGuard configuration
275
- * provided at the app root. Consumers use `getContext(TimeGuardConfigKey)`.
276
- */
277
- var TimeGuardConfigKey = Symbol("TimeGuardConfig");
278
- /**
279
- * Creates a reactive readable store of a TimeGuard instance.
280
- * Automatically updates when `input` changes (supports both plain values
281
- * and Svelte stores as input — pass a `Readable` for full reactivity).
282
- * Integrates global config from `getContext(TimeGuardConfigKey)` as fallback.
283
- *
284
- * ```svelte
285
- * <script>
286
- * import { writable } from 'svelte/store';
287
- * import { useTimeGuard } from '@bereasoftware/time-guard/svelte';
288
- * import { TimeGuard } from '@bereasoftware/time-guard';
289
- *
290
- * // Static input — no reactivity needed
291
- * const tg = useTimeGuard('2026-05-20');
292
- *
293
- * // Reactive input — pass a store
294
- * const dateStore = writable('2026-05-20');
295
- * const tg2 = useTimeGuard(dateStore);
296
- * <\/script>
297
- *
298
- * <p>{$tg.format('dddd, DD MMMM YYYY')}</p>
299
- * <p>{$tg2.format('dddd, DD MMMM YYYY')}</p>
300
- * ```
301
- */
302
- function useTimeGuard(input, config) {
303
- if (isStore(input)) return derived(input, ($val) => TimeGuard.from($val, config));
304
- return readable(TimeGuard.from(input, config));
101
+ var b = Symbol("TimeGuardConfig");
102
+ function x(t, n) {
103
+ return v(t) ? h(t, (t) => e.from(t, n)) : p(e.from(t, n));
305
104
  }
306
- /**
307
- * Creates a readable store of the current time that ticks on a specified
308
- * interval (default 1000ms). Automatically clears the interval on
309
- * component destroy.
310
- *
311
- * ```svelte
312
- * <script>
313
- * import { useCurrentTime } from '@bereasoftware/time-guard/svelte';
314
- * const now = useCurrentTime({ interval: 1000 });
315
- * <\/script>
316
- * <p>{$now.format('HH:mm:ss')}</p>
317
- * ```
318
- */
319
- function useCurrentTime(options) {
320
- const interval = options?.interval ?? 1e3;
321
- const config = options?.config;
322
- const store = writable(TimeGuard.now(config), () => {
323
- const timer = setInterval(() => {
324
- store.set(TimeGuard.now(config));
325
- }, interval);
105
+ function S(t) {
106
+ let n = t?.interval ?? 1e3, r = t?.config, i = m(e.now(r), () => {
107
+ let t = setInterval(() => {
108
+ i.set(e.now(r));
109
+ }, n);
326
110
  return () => {
327
- clearInterval(timer);
111
+ clearInterval(t);
328
112
  };
329
113
  });
330
- return { subscribe: store.subscribe };
114
+ return { subscribe: i.subscribe };
331
115
  }
332
- /**
333
- * Creates a readable store of a relative time string that recalculates
334
- * periodically (default every 60s).
335
- *
336
- * ```svelte
337
- * <script>
338
- * import { useRelativeTime } from '@bereasoftware/time-guard/svelte';
339
- * const relative = useRelativeTime('2026-05-20T08:00:00', { locale: 'es' });
340
- * <\/script>
341
- * <p>{$relative}</p>
342
- * ```
343
- */
344
- function useRelativeTime(date, options) {
345
- const interval = options?.interval ?? 6e4;
346
- const locale = options?.locale;
347
- const numeric = options?.numeric;
348
- const compute = () => {
349
- const tgDate = TimeGuard.from(date);
350
- const now = TimeGuard.now();
351
- return tgDate.since(now).humanize({
352
- locale,
353
- numeric
354
- });
355
- };
356
- const store = writable(compute(), () => {
357
- const timer = setInterval(() => {
358
- store.set(compute());
359
- }, interval);
116
+ function C(e, n) {
117
+ let r = n?.interval ?? 6e4, i = n?.locale, a = n?.numeric, o = () => t(e, {
118
+ locale: i,
119
+ numeric: a
120
+ }), s = m(o(), () => {
121
+ let e = setInterval(() => {
122
+ s.set(o());
123
+ }, r);
360
124
  return () => {
361
- clearInterval(timer);
125
+ clearInterval(e);
362
126
  };
363
127
  });
364
- return { subscribe: store.subscribe };
128
+ return { subscribe: s.subscribe };
365
129
  }
366
- /**
367
- * Creates a readable store of a TimeRange instance.
368
- * Recalculates reactively when `start` or `end` change (supports both
369
- * plain values and Svelte stores).
370
- *
371
- * ```svelte
372
- * <script>
373
- * import { writable } from 'svelte/store';
374
- * import { useTimeRange } from '@bereasoftware/time-guard/svelte';
375
- *
376
- * // Static range
377
- * const range = useTimeRange('2026-05-20', '2026-06-01');
378
- *
379
- * // Reactive range
380
- * const start = writable('2026-05-20');
381
- * const end = writable('2026-06-01');
382
- * const range2 = useTimeRange(start, end);
383
- * <\/script>
384
- *
385
- * <p>Duration: {$range.toDuration().humanize()}</p>
386
- */
387
- function useTimeRange(start, end, config) {
388
- return derived([toStore(start), toStore(end)], ([$start, $end]) => {
389
- return new TimeRange(TimeGuard.from($start, config), TimeGuard.from($end, config));
390
- });
130
+ function w(e, t, r) {
131
+ return h([y(e), y(t)], ([e, t]) => n(e, t, r));
391
132
  }
392
133
  //#endregion
393
- export { TimeGuardConfigKey, useCurrentTime, useRelativeTime, useTimeGuard, useTimeRange };
134
+ export { b as TimeGuardConfigKey, S as useCurrentTime, C as useRelativeTime, x as useTimeGuard, w as useTimeRange };