@bereasoftware/time-guard 2.7.1 → 2.8.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 (43) hide show
  1. package/README.en.md +5 -1
  2. package/README.md +5 -1
  3. package/dist/angular/index.cjs +1 -148
  4. package/dist/angular/index.es.js +60 -112
  5. package/dist/calendars/index.cjs +1 -357
  6. package/dist/calendars/index.es.js +66 -99
  7. package/dist/chunk-C6qsp3rV.cjs +1 -0
  8. package/dist/core-Dxn1aRFk.js +1186 -0
  9. package/dist/core-TqmHKXY1.cjs +1 -0
  10. package/dist/core.d.ts +27 -1
  11. package/dist/index.d.ts +4 -2
  12. package/dist/locales/index.cjs +1 -7
  13. package/dist/locales/index.d.ts +11 -0
  14. package/dist/locales/index.es.js +3 -3
  15. package/dist/{locales-B1mDDyn_.cjs → locales-3Mw99lQ-.js} +201 -82
  16. package/dist/locales-bc-5kDuZ.cjs +1 -0
  17. package/dist/native/index.cjs +1 -48
  18. package/dist/native/index.es.js +8 -18
  19. package/dist/plugins/advanced-format.cjs +1 -105
  20. package/dist/plugins/advanced-format.es.js +43 -63
  21. package/dist/plugins/duration.cjs +1 -258
  22. package/dist/plugins/duration.es.js +59 -165
  23. package/dist/plugins/relative-time.cjs +1 -166
  24. package/dist/plugins/relative-time.es.js +36 -74
  25. package/dist/qwik/index.cjs +1 -104
  26. package/dist/qwik/index.es.js +33 -94
  27. package/dist/react/index.cjs +1 -112
  28. package/dist/react/index.es.js +57 -91
  29. package/dist/solid/index.cjs +1 -127
  30. package/dist/solid/index.es.js +34 -116
  31. package/dist/svelte/index.cjs +1 -398
  32. package/dist/svelte/index.es.js +85 -344
  33. package/dist/time-guard.cjs +3 -7359
  34. package/dist/time-guard.es.js +3412 -3625
  35. package/dist/time-guard.iife.js +3 -13549
  36. package/dist/time-guard.umd.js +3 -13550
  37. package/dist/vue/index.cjs +1 -143
  38. package/dist/vue/index.es.js +62 -116
  39. package/package.json +2 -3
  40. package/dist/chunk-BbtWAPZS.cjs +0 -36
  41. package/dist/core-BFdo248T.cjs +0 -1892
  42. package/dist/core-CyBR5PPd.js +0 -1809
  43. package/dist/locales-By7IK3Ep.js +0 -3514
@@ -1,143 +1 @@
1
- /*! time-guard v2.7.1 | (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-BFdo248T.cjs");
4
- let vue = require("vue");
5
- //#region src/vue.ts
6
- /**
7
- * Unique symbol key for injecting TimeGuard global configuration.
8
- */
9
- var TimeGuardConfigKey = Symbol("TimeGuardConfig");
10
- /**
11
- * Vue Directive for dynamically and reactively formatting dates.
12
- * Usage:
13
- * - `<span v-time-guard:format="date" data-pattern="YYYY-MM-DD"></span>`
14
- * - `<span v-time-guard:relative="date" data-locale="es"></span>`
15
- */
16
- /** Internal WeakMap to track interval timers per element (avoids `any` casts). */
17
- var directiveTimerMap = /* @__PURE__ */ new WeakMap();
18
- var vTimeGuard = {
19
- mounted(el, binding) {
20
- updateDirective(el, binding);
21
- },
22
- updated(el, binding) {
23
- updateDirective(el, binding);
24
- },
25
- unmounted(el) {
26
- const timer = directiveTimerMap.get(el);
27
- if (timer) {
28
- clearInterval(timer);
29
- directiveTimerMap.delete(el);
30
- }
31
- }
32
- };
33
- function updateDirective(el, binding) {
34
- const existingTimer = directiveTimerMap.get(el);
35
- if (existingTimer) {
36
- clearInterval(existingTimer);
37
- directiveTimerMap.delete(el);
38
- }
39
- const value = binding.value;
40
- if (value === void 0 || value === null) {
41
- el.textContent = "";
42
- return;
43
- }
44
- const mode = binding.arg || "format";
45
- const pattern = el.getAttribute("data-pattern") || "YYYY-MM-DD HH:mm:ss";
46
- const locale = el.getAttribute("data-locale") || void 0;
47
- const intervalMs = parseInt(el.getAttribute("data-interval") || "60000", 10);
48
- const numeric = el.getAttribute("data-numeric") || void 0;
49
- const render = () => {
50
- try {
51
- const tg = require_core.TimeGuard.from(value);
52
- if (mode === "relative") {
53
- const now = require_core.TimeGuard.now();
54
- el.textContent = tg.since(now).humanize({
55
- locale,
56
- numeric
57
- });
58
- } else el.textContent = locale ? tg.locale(locale).format(pattern) : tg.format(pattern);
59
- } catch {
60
- el.textContent = String(value);
61
- }
62
- };
63
- render();
64
- if (mode === "relative" || el.getAttribute("data-live") === "true") directiveTimerMap.set(el, setInterval(render, intervalMs));
65
- }
66
- /**
67
- * Vue Plugin to register a global TimeGuard configuration and register v-time-guard directive.
68
- */
69
- var TimeGuardVuePlugin = { install(app, options) {
70
- app.provide(TimeGuardConfigKey, options);
71
- app.directive("time-guard", vTimeGuard);
72
- } };
73
- /**
74
- * Vue Composable to create a reactive Ref of a TimeGuard instance.
75
- * Automatically updates when input or configuration changes.
76
- * Inherits global injected configuration as fallback.
77
- */
78
- function useTimeGuard(input, config) {
79
- const globalConfig = (0, vue.inject)(TimeGuardConfigKey, void 0);
80
- const activeConfig = config ?? globalConfig;
81
- const tg = (0, vue.ref)(require_core.TimeGuard.from(input, activeConfig));
82
- (0, vue.watch)([() => input, () => activeConfig ? JSON.stringify(activeConfig) : void 0], () => {
83
- tg.value = require_core.TimeGuard.from(input, activeConfig);
84
- }, { deep: true });
85
- return tg;
86
- }
87
- /**
88
- * Vue Composable to get a reactive TimeGuard Ref representing the current time.
89
- * Automatically updates on a specified interval (default: 1000ms).
90
- * Inherits global injected configuration as fallback.
91
- */
92
- function useCurrentTime(options) {
93
- const globalConfig = (0, vue.inject)(TimeGuardConfigKey, void 0);
94
- const activeConfig = options?.config ?? globalConfig;
95
- const interval = options?.interval ?? 1e3;
96
- const time = (0, vue.ref)(require_core.TimeGuard.now(activeConfig));
97
- const timer = setInterval(() => {
98
- time.value = require_core.TimeGuard.now(activeConfig);
99
- }, interval);
100
- (0, vue.onUnmounted)(() => {
101
- clearInterval(timer);
102
- });
103
- return time;
104
- }
105
- /**
106
- * Vue Composable that returns a reactive relative time Ref updating periodically.
107
- * Inherits global injected configuration as fallback.
108
- */
109
- function useRelativeTime(date, options) {
110
- const globalConfig = (0, vue.inject)(TimeGuardConfigKey, void 0);
111
- const interval = options?.interval ?? 6e4;
112
- const locale = options?.locale ?? globalConfig?.locale;
113
- const numeric = options?.numeric;
114
- const relative = (0, vue.ref)("");
115
- const update = () => {
116
- const tgDate = require_core.TimeGuard.from(date);
117
- const now = require_core.TimeGuard.now();
118
- relative.value = tgDate.since(now).humanize({
119
- locale,
120
- numeric
121
- });
122
- };
123
- update();
124
- const timer = setInterval(update, interval);
125
- (0, vue.watch)([
126
- () => date,
127
- () => locale,
128
- () => numeric
129
- ], () => {
130
- update();
131
- }, { deep: true });
132
- (0, vue.onUnmounted)(() => {
133
- clearInterval(timer);
134
- });
135
- return relative;
136
- }
137
- //#endregion
138
- exports.TimeGuardConfigKey = TimeGuardConfigKey;
139
- exports.TimeGuardVuePlugin = TimeGuardVuePlugin;
140
- exports.useCurrentTime = useCurrentTime;
141
- exports.useRelativeTime = useRelativeTime;
142
- exports.useTimeGuard = useTimeGuard;
143
- exports.vTimeGuard = vTimeGuard;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../core-TqmHKXY1.cjs");let t=require("vue");var n=Symbol(`TimeGuardConfig`),r=new WeakMap,i={mounted(e,t){a(e,t)},updated(e,t){a(e,t)},unmounted(e){let t=r.get(e);t&&(clearInterval(t),r.delete(e))}};function a(t,n){let i=r.get(t);i&&(clearInterval(i),r.delete(t));let a=n.value;if(a==null){t.textContent=``;return}let o=n.arg||`format`,s=t.getAttribute(`data-pattern`)||`YYYY-MM-DD HH:mm:ss`,c=t.getAttribute(`data-locale`)||void 0,l=parseInt(t.getAttribute(`data-interval`)||`60000`,10),u=t.getAttribute(`data-numeric`)||void 0,d=()=>{try{let n=e.i.from(a);if(o===`relative`){let r=e.i.now();t.textContent=n.since(r).humanize({locale:c,numeric:u})}else t.textContent=c?n.locale(c).format(s):n.format(s)}catch{t.textContent=String(a)}};d(),(o===`relative`||t.getAttribute(`data-live`)===`true`)&&r.set(t,setInterval(d,l))}var o={install(e,t){e.provide(n,t),e.directive(`time-guard`,i)}};function s(r,i){let a=(0,t.inject)(n,void 0),o=i??a,s=(0,t.ref)(e.i.from(r,o));return(0,t.watch)([()=>r,()=>o?.locale,()=>o?.timezone,()=>o?.strict],()=>{s.value=e.i.from(r,o)}),s}function c(r){let i=(0,t.inject)(n,void 0),a=r?.config??i,o=r?.interval??1e3,s=(0,t.ref)(e.i.now(a)),c=setInterval(()=>{s.value=e.i.now(a)},o);return(0,t.onUnmounted)(()=>{clearInterval(c)}),s}function l(r,i){let a=(0,t.inject)(n,void 0),o=i?.interval??6e4,s=i?.locale??a?.locale,c=i?.numeric,l=(0,t.ref)(``),u=()=>{l.value=e.o(r,{locale:s,numeric:c})};u();let d=setInterval(u,o);return(0,t.watch)([()=>r,()=>s,()=>c],()=>{u()},{deep:!0}),(0,t.onUnmounted)(()=>{clearInterval(d)}),l}exports.TimeGuardConfigKey=n,exports.TimeGuardVuePlugin=o,exports.useCurrentTime=c,exports.useRelativeTime=l,exports.useTimeGuard=s,exports.vTimeGuard=i;
@@ -1,137 +1,83 @@
1
- /*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- import { n as TimeGuard } from "../core-CyBR5PPd.js";
3
- import { inject, onUnmounted, ref, watch } from "vue";
1
+ /*! time-guard v2.8.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
+ import { i as e, o as t } from "../core-Dxn1aRFk.js";
3
+ import { inject as n, onUnmounted as r, ref as i, watch as a } from "vue";
4
4
  //#region src/vue.ts
5
- /**
6
- * Unique symbol key for injecting TimeGuard global configuration.
7
- */
8
- var TimeGuardConfigKey = Symbol("TimeGuardConfig");
9
- /**
10
- * Vue Directive for dynamically and reactively formatting dates.
11
- * Usage:
12
- * - `<span v-time-guard:format="date" data-pattern="YYYY-MM-DD"></span>`
13
- * - `<span v-time-guard:relative="date" data-locale="es"></span>`
14
- */
15
- /** Internal WeakMap to track interval timers per element (avoids `any` casts). */
16
- var directiveTimerMap = /* @__PURE__ */ new WeakMap();
17
- var vTimeGuard = {
18
- mounted(el, binding) {
19
- updateDirective(el, binding);
5
+ var o = Symbol("TimeGuardConfig"), s = /* @__PURE__ */ new WeakMap(), c = {
6
+ mounted(e, t) {
7
+ l(e, t);
20
8
  },
21
- updated(el, binding) {
22
- updateDirective(el, binding);
9
+ updated(e, t) {
10
+ l(e, t);
23
11
  },
24
- unmounted(el) {
25
- const timer = directiveTimerMap.get(el);
26
- if (timer) {
27
- clearInterval(timer);
28
- directiveTimerMap.delete(el);
29
- }
12
+ unmounted(e) {
13
+ let t = s.get(e);
14
+ t && (clearInterval(t), s.delete(e));
30
15
  }
31
16
  };
32
- function updateDirective(el, binding) {
33
- const existingTimer = directiveTimerMap.get(el);
34
- if (existingTimer) {
35
- clearInterval(existingTimer);
36
- directiveTimerMap.delete(el);
37
- }
38
- const value = binding.value;
39
- if (value === void 0 || value === null) {
40
- el.textContent = "";
17
+ function l(t, n) {
18
+ let r = s.get(t);
19
+ r && (clearInterval(r), s.delete(t));
20
+ let i = n.value;
21
+ if (i == null) {
22
+ t.textContent = "";
41
23
  return;
42
24
  }
43
- const mode = binding.arg || "format";
44
- const pattern = el.getAttribute("data-pattern") || "YYYY-MM-DD HH:mm:ss";
45
- const locale = el.getAttribute("data-locale") || void 0;
46
- const intervalMs = parseInt(el.getAttribute("data-interval") || "60000", 10);
47
- const numeric = el.getAttribute("data-numeric") || void 0;
48
- const render = () => {
25
+ let a = n.arg || "format", o = t.getAttribute("data-pattern") || "YYYY-MM-DD HH:mm:ss", c = t.getAttribute("data-locale") || void 0, l = parseInt(t.getAttribute("data-interval") || "60000", 10), u = t.getAttribute("data-numeric") || void 0, d = () => {
49
26
  try {
50
- const tg = TimeGuard.from(value);
51
- if (mode === "relative") {
52
- const now = TimeGuard.now();
53
- el.textContent = tg.since(now).humanize({
54
- locale,
55
- numeric
27
+ let n = e.from(i);
28
+ if (a === "relative") {
29
+ let r = e.now();
30
+ t.textContent = n.since(r).humanize({
31
+ locale: c,
32
+ numeric: u
56
33
  });
57
- } else el.textContent = locale ? tg.locale(locale).format(pattern) : tg.format(pattern);
34
+ } else t.textContent = c ? n.locale(c).format(o) : n.format(o);
58
35
  } catch {
59
- el.textContent = String(value);
36
+ t.textContent = String(i);
60
37
  }
61
38
  };
62
- render();
63
- if (mode === "relative" || el.getAttribute("data-live") === "true") directiveTimerMap.set(el, setInterval(render, intervalMs));
39
+ d(), (a === "relative" || t.getAttribute("data-live") === "true") && s.set(t, setInterval(d, l));
64
40
  }
65
- /**
66
- * Vue Plugin to register a global TimeGuard configuration and register v-time-guard directive.
67
- */
68
- var TimeGuardVuePlugin = { install(app, options) {
69
- app.provide(TimeGuardConfigKey, options);
70
- app.directive("time-guard", vTimeGuard);
41
+ var u = { install(e, t) {
42
+ e.provide(o, t), e.directive("time-guard", c);
71
43
  } };
72
- /**
73
- * Vue Composable to create a reactive Ref of a TimeGuard instance.
74
- * Automatically updates when input or configuration changes.
75
- * Inherits global injected configuration as fallback.
76
- */
77
- function useTimeGuard(input, config) {
78
- const globalConfig = inject(TimeGuardConfigKey, void 0);
79
- const activeConfig = config ?? globalConfig;
80
- const tg = ref(TimeGuard.from(input, activeConfig));
81
- watch([() => input, () => activeConfig ? JSON.stringify(activeConfig) : void 0], () => {
82
- tg.value = TimeGuard.from(input, activeConfig);
83
- }, { deep: true });
84
- return tg;
44
+ function d(t, r) {
45
+ let s = n(o, void 0), c = r ?? s, l = i(e.from(t, c));
46
+ return a([
47
+ () => t,
48
+ () => c?.locale,
49
+ () => c?.timezone,
50
+ () => c?.strict
51
+ ], () => {
52
+ l.value = e.from(t, c);
53
+ }), l;
85
54
  }
86
- /**
87
- * Vue Composable to get a reactive TimeGuard Ref representing the current time.
88
- * Automatically updates on a specified interval (default: 1000ms).
89
- * Inherits global injected configuration as fallback.
90
- */
91
- function useCurrentTime(options) {
92
- const globalConfig = inject(TimeGuardConfigKey, void 0);
93
- const activeConfig = options?.config ?? globalConfig;
94
- const interval = options?.interval ?? 1e3;
95
- const time = ref(TimeGuard.now(activeConfig));
96
- const timer = setInterval(() => {
97
- time.value = TimeGuard.now(activeConfig);
98
- }, interval);
99
- onUnmounted(() => {
100
- clearInterval(timer);
101
- });
102
- return time;
55
+ function f(t) {
56
+ let a = n(o, void 0), s = t?.config ?? a, c = t?.interval ?? 1e3, l = i(e.now(s)), u = setInterval(() => {
57
+ l.value = e.now(s);
58
+ }, c);
59
+ return r(() => {
60
+ clearInterval(u);
61
+ }), l;
103
62
  }
104
- /**
105
- * Vue Composable that returns a reactive relative time Ref updating periodically.
106
- * Inherits global injected configuration as fallback.
107
- */
108
- function useRelativeTime(date, options) {
109
- const globalConfig = inject(TimeGuardConfigKey, void 0);
110
- const interval = options?.interval ?? 6e4;
111
- const locale = options?.locale ?? globalConfig?.locale;
112
- const numeric = options?.numeric;
113
- const relative = ref("");
114
- const update = () => {
115
- const tgDate = TimeGuard.from(date);
116
- const now = TimeGuard.now();
117
- relative.value = tgDate.since(now).humanize({
118
- locale,
119
- numeric
63
+ function p(e, s) {
64
+ let c = n(o, void 0), l = s?.interval ?? 6e4, u = s?.locale ?? c?.locale, d = s?.numeric, f = i(""), p = () => {
65
+ f.value = t(e, {
66
+ locale: u,
67
+ numeric: d
120
68
  });
121
69
  };
122
- update();
123
- const timer = setInterval(update, interval);
124
- watch([
125
- () => date,
126
- () => locale,
127
- () => numeric
70
+ p();
71
+ let m = setInterval(p, l);
72
+ return a([
73
+ () => e,
74
+ () => u,
75
+ () => d
128
76
  ], () => {
129
- update();
130
- }, { deep: true });
131
- onUnmounted(() => {
132
- clearInterval(timer);
133
- });
134
- return relative;
77
+ p();
78
+ }, { deep: !0 }), r(() => {
79
+ clearInterval(m);
80
+ }), f;
135
81
  }
136
82
  //#endregion
137
- export { TimeGuardConfigKey, TimeGuardVuePlugin, useCurrentTime, useRelativeTime, useTimeGuard, vTimeGuard };
83
+ export { o as TimeGuardConfigKey, u as TimeGuardVuePlugin, f as useCurrentTime, p as useRelativeTime, d as useTimeGuard, c as vTimeGuard };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bereasoftware/time-guard",
3
3
  "private": false,
4
- "version": "2.7.1",
4
+ "version": "2.8.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/time-guard.cjs",
@@ -168,8 +168,7 @@
168
168
  "prepare": "husky"
169
169
  },
170
170
  "dependencies": {
171
- "@js-temporal/polyfill": "^0.5.1",
172
- "vue-icons-plus": "^0.1.9"
171
+ "@js-temporal/polyfill": "^0.5.1"
173
172
  },
174
173
  "peerDependencies": {
175
174
  "@angular/core": ">=21.2.14",
@@ -1,36 +0,0 @@
1
- /*! time-guard v2.7.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
- value: mod,
22
- enumerable: true
23
- }) : target, mod));
24
- //#endregion
25
- Object.defineProperty(exports, "__commonJSMin", {
26
- enumerable: true,
27
- get: function() {
28
- return __commonJSMin;
29
- }
30
- });
31
- Object.defineProperty(exports, "__toESM", {
32
- enumerable: true,
33
- get: function() {
34
- return __toESM;
35
- }
36
- });