@bereasoftware/time-guard 2.6.1 → 2.7.1

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/angular/index.cjs +148 -0
  4. package/dist/angular/index.d.ts +2 -0
  5. package/dist/angular/index.es.js +143 -0
  6. package/dist/angular.d.ts +59 -0
  7. package/dist/calendars/index.cjs +357 -2
  8. package/dist/calendars/index.es.js +99 -68
  9. package/dist/chunk-BbtWAPZS.cjs +36 -0
  10. package/dist/core-BFdo248T.cjs +1892 -0
  11. package/dist/core-CyBR5PPd.js +1809 -0
  12. package/dist/core.d.ts +224 -0
  13. package/dist/index.d.ts +9 -0
  14. package/dist/locales/african.locale.d.ts +7 -0
  15. package/dist/locales/index.cjs +7 -1
  16. package/dist/{types/locales → locales}/index.d.ts +2 -2
  17. package/dist/locales/index.es.js +3 -3
  18. package/dist/locales/south-american.locale.d.ts +7 -0
  19. package/dist/locales-B1mDDyn_.cjs +3537 -0
  20. package/dist/{locales-DSBvgSaw.js → locales-By7IK3Ep.js} +749 -33
  21. package/dist/native/index.cjs +48 -0
  22. package/dist/native/index.d.ts +2 -0
  23. package/dist/native/index.es.js +18 -0
  24. package/dist/native.d.ts +9 -0
  25. package/dist/plugins/advanced-format.cjs +105 -2
  26. package/dist/plugins/advanced-format.es.js +63 -45
  27. package/dist/plugins/duration.cjs +258 -2
  28. package/dist/plugins/duration.es.js +165 -61
  29. package/dist/plugins/relative-time.cjs +166 -2
  30. package/dist/plugins/relative-time.es.js +74 -37
  31. package/dist/qwik/index.cjs +104 -0
  32. package/dist/qwik/index.d.ts +2 -0
  33. package/dist/qwik/index.es.js +100 -0
  34. package/dist/qwik.d.ts +32 -0
  35. package/dist/react/index.cjs +112 -0
  36. package/dist/react/index.d.ts +2 -0
  37. package/dist/react/index.es.js +103 -0
  38. package/dist/react.d.ts +46 -0
  39. package/dist/solid/index.cjs +127 -0
  40. package/dist/solid/index.d.ts +2 -0
  41. package/dist/solid/index.es.js +122 -0
  42. package/dist/solid.d.ts +53 -0
  43. package/dist/svelte/index.cjs +398 -0
  44. package/dist/svelte/index.d.ts +2 -0
  45. package/dist/svelte/index.es.js +393 -0
  46. package/dist/svelte.d.ts +88 -0
  47. package/dist/time-guard.cjs +7359 -4
  48. package/dist/time-guard.es.js +3625 -8085
  49. package/dist/time-guard.iife.js +13549 -4
  50. package/dist/time-guard.umd.js +13550 -4
  51. package/dist/types/index.d.ts +651 -127
  52. package/dist/vue/index.cjs +143 -0
  53. package/dist/vue/index.d.ts +2 -0
  54. package/dist/vue/index.es.js +137 -0
  55. package/dist/vue.d.ts +35 -0
  56. package/package.json +107 -27
  57. package/dist/calendars/index.cjs.map +0 -1
  58. package/dist/calendars/index.es.js.map +0 -1
  59. package/dist/locales-DSBvgSaw.js.map +0 -1
  60. package/dist/locales-ybx7jS8G.cjs +0 -2
  61. package/dist/locales-ybx7jS8G.cjs.map +0 -1
  62. package/dist/plugins/advanced-format.cjs.map +0 -1
  63. package/dist/plugins/advanced-format.es.js.map +0 -1
  64. package/dist/plugins/duration.cjs.map +0 -1
  65. package/dist/plugins/duration.es.js.map +0 -1
  66. package/dist/plugins/relative-time.cjs.map +0 -1
  67. package/dist/plugins/relative-time.es.js.map +0 -1
  68. package/dist/time-guard.cjs.map +0 -1
  69. package/dist/time-guard.es.js.map +0 -1
  70. package/dist/time-guard.iife.js.map +0 -1
  71. package/dist/time-guard.umd.js.map +0 -1
  72. package/dist/types/types/index.d.ts +0 -641
  73. /package/dist/{types/adapters → adapters}/temporal.adapter.d.ts +0 -0
  74. /package/dist/{types/calendars → calendars}/calendar.manager.d.ts +0 -0
  75. /package/dist/{types/calendars → calendars}/index.d.ts +0 -0
  76. /package/dist/{types/formatters → formatters}/date.formatter.d.ts +0 -0
  77. /package/dist/{types/locales → locales}/additional.locale.d.ts +0 -0
  78. /package/dist/{types/locales → locales}/asian.locale.d.ts +0 -0
  79. /package/dist/{types/locales → locales}/english.locale.d.ts +0 -0
  80. /package/dist/{types/locales → locales}/european.locale.d.ts +0 -0
  81. /package/dist/{types/locales → locales}/locale.manager.d.ts +0 -0
  82. /package/dist/{types/locales → locales}/middle-eastern.locale.d.ts +0 -0
  83. /package/dist/{types/locales → locales}/nordic.locale.d.ts +0 -0
  84. /package/dist/{types/locales → locales}/romance.locale.d.ts +0 -0
  85. /package/dist/{types/locales → locales}/slavic.locale.d.ts +0 -0
  86. /package/dist/{types/locales → locales}/spanish.locale.d.ts +0 -0
  87. /package/dist/{types/plugins → plugins}/advanced-format/index.d.ts +0 -0
  88. /package/dist/{types/plugins → plugins}/advanced-format.d.ts +0 -0
  89. /package/dist/{types/plugins → plugins}/duration/index.d.ts +0 -0
  90. /package/dist/{types/plugins → plugins}/duration/types.d.ts +0 -0
  91. /package/dist/{types/plugins → plugins}/duration.d.ts +0 -0
  92. /package/dist/{types/plugins → plugins}/index.d.ts +0 -0
  93. /package/dist/{types/plugins → plugins}/manager.d.ts +0 -0
  94. /package/dist/{types/plugins → plugins}/relative-time/index.d.ts +0 -0
  95. /package/dist/{types/plugins → plugins}/relative-time/types.d.ts +0 -0
  96. /package/dist/{types/plugins → plugins}/relative-time.d.ts +0 -0
  97. /package/dist/{types/time-guard.d.ts → time-guard.d.ts} +0 -0
  98. /package/dist/{types/utils → utils}/duration-locale.d.ts +0 -0
@@ -0,0 +1,148 @@
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 _angular_core = require("@angular/core");
5
+ let rxjs = require("rxjs");
6
+ //#region src/angular.ts
7
+ /**
8
+ * Angular Injection Token to register global/default TimeGuard configurations.
9
+ */
10
+ var TIME_GUARD_CONFIG = new _angular_core.InjectionToken("TIME_GUARD_CONFIG");
11
+ /**
12
+ * Angular Pipe to format a date/time using TimeGuard.
13
+ * Supports global configuration overrides via DI.
14
+ * Usage: `{{ date | timeGuardFormat:'YYYY-MM-DD':'es' }}`
15
+ */
16
+ var TimeGuardFormatPipe = class {
17
+ globalConfig = (0, _angular_core.inject)(TIME_GUARD_CONFIG, { optional: true });
18
+ transform(value, pattern = "YYYY-MM-DD HH:mm:ss", locale) {
19
+ if (!value) return "";
20
+ try {
21
+ const tg = require_core.TimeGuard.from(value);
22
+ const activeLocale = locale || this.globalConfig?.locale;
23
+ if (activeLocale) return tg.locale(activeLocale).format(pattern);
24
+ return tg.format(pattern);
25
+ } catch {
26
+ return String(value);
27
+ }
28
+ }
29
+ };
30
+ /**
31
+ * Angular Pipe for dynamic relative time humanization.
32
+ * Supports global configuration overrides via DI.
33
+ * Usage: `{{ date | timeGuardRelative:'es':'auto' }}`
34
+ */
35
+ var TimeGuardRelativePipe = class {
36
+ globalConfig = (0, _angular_core.inject)(TIME_GUARD_CONFIG, { optional: true });
37
+ transform(value, locale, numeric) {
38
+ if (!value) return "";
39
+ try {
40
+ const tg = require_core.TimeGuard.from(value);
41
+ const now = require_core.TimeGuard.now();
42
+ const activeLocale = locale || this.globalConfig?.locale;
43
+ return tg.since(now).humanize({
44
+ locale: activeLocale,
45
+ numeric
46
+ });
47
+ } catch {
48
+ return String(value);
49
+ }
50
+ }
51
+ };
52
+ /**
53
+ * Injectable Service to interact with TimeGuard.
54
+ * Provides a high-performance reactive Observable of the current time
55
+ * running outside Angular zone to optimize change detection ticks.
56
+ * Supports global configuration overrides via DI.
57
+ */
58
+ var TimeGuardService = class {
59
+ ngZone = (0, _angular_core.inject)(_angular_core.NgZone);
60
+ globalConfig = (0, _angular_core.inject)(TIME_GUARD_CONFIG, { optional: true });
61
+ /**
62
+ * Get an Observable of the current time, ticking on the specified interval.
63
+ */
64
+ getCurrentTime(intervalMs = 1e3, config) {
65
+ const activeConfig = config ?? this.globalConfig ?? void 0;
66
+ return new rxjs.Observable((subscriber) => {
67
+ return this.ngZone.runOutsideAngular(() => {
68
+ subscriber.next(require_core.TimeGuard.now(activeConfig));
69
+ const intervalId = setInterval(() => {
70
+ this.ngZone.run(() => {
71
+ subscriber.next(require_core.TimeGuard.now(activeConfig));
72
+ });
73
+ }, intervalMs);
74
+ return () => {
75
+ clearInterval(intervalId);
76
+ };
77
+ });
78
+ }).pipe((0, rxjs.shareReplay)(1));
79
+ }
80
+ };
81
+ /**
82
+ * Angular Pipe to dynamically tick and format dates at a custom interval.
83
+ * Highly optimized, impure pipe utilizing TimeGuardService and ChangeDetectorRef.
84
+ * Usage:
85
+ * - Real-time clock: `{{ 'now' | timeGuardLiveFormat:'HH:mm:ss':1000 }}`
86
+ * - Ticking static date: `{{ date | timeGuardLiveFormat:'YYYY-MM-DD HH:mm:ss':5000 }}`
87
+ */
88
+ var TimeGuardLiveFormatPipe = class {
89
+ latestValue = "";
90
+ subscription;
91
+ lastInput;
92
+ lastPattern;
93
+ lastInterval;
94
+ lastLocale;
95
+ cdr = (0, _angular_core.inject)(_angular_core.ChangeDetectorRef);
96
+ timeGuardService = (0, _angular_core.inject)(TimeGuardService);
97
+ globalConfig = (0, _angular_core.inject)(TIME_GUARD_CONFIG, { optional: true });
98
+ transform(value, pattern = "YYYY-MM-DD HH:mm:ss", intervalMs = 1e3, locale) {
99
+ if (!value) return "";
100
+ if (value !== this.lastInput || pattern !== this.lastPattern || intervalMs !== this.lastInterval || locale !== this.lastLocale) {
101
+ this.ngOnDestroy();
102
+ this.lastInput = value;
103
+ this.lastPattern = pattern;
104
+ this.lastInterval = intervalMs;
105
+ this.lastLocale = locale;
106
+ const activeLocale = locale || this.globalConfig?.locale;
107
+ if (value === "now") this.subscription = this.timeGuardService.getCurrentTime(intervalMs).subscribe((now) => {
108
+ this.latestValue = activeLocale ? now.locale(activeLocale).format(pattern) : now.format(pattern);
109
+ this.cdr.markForCheck();
110
+ });
111
+ else this.subscription = this.timeGuardService.getCurrentTime(intervalMs).subscribe(() => {
112
+ try {
113
+ const tg = require_core.TimeGuard.from(value);
114
+ this.latestValue = activeLocale ? tg.locale(activeLocale).format(pattern) : tg.format(pattern);
115
+ this.cdr.markForCheck();
116
+ } catch {
117
+ this.latestValue = String(value);
118
+ }
119
+ });
120
+ }
121
+ return this.latestValue;
122
+ }
123
+ ngOnDestroy() {
124
+ if (this.subscription) {
125
+ this.subscription.unsubscribe();
126
+ this.subscription = void 0;
127
+ }
128
+ }
129
+ };
130
+ (0, _angular_core.Pipe)({
131
+ name: "timeGuardFormat",
132
+ pure: true
133
+ })(TimeGuardFormatPipe);
134
+ (0, _angular_core.Pipe)({
135
+ name: "timeGuardRelative",
136
+ pure: false
137
+ })(TimeGuardRelativePipe);
138
+ (0, _angular_core.Injectable)({ providedIn: "root" })(TimeGuardService);
139
+ (0, _angular_core.Pipe)({
140
+ name: "timeGuardLiveFormat",
141
+ pure: false
142
+ })(TimeGuardLiveFormatPipe);
143
+ //#endregion
144
+ exports.TIME_GUARD_CONFIG = TIME_GUARD_CONFIG;
145
+ exports.TimeGuardFormatPipe = TimeGuardFormatPipe;
146
+ exports.TimeGuardLiveFormatPipe = TimeGuardLiveFormatPipe;
147
+ exports.TimeGuardRelativePipe = TimeGuardRelativePipe;
148
+ exports.TimeGuardService = TimeGuardService;
@@ -0,0 +1,2 @@
1
+ export * from '../angular'
2
+ export {}
@@ -0,0 +1,143 @@
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 { ChangeDetectorRef, Injectable, InjectionToken, NgZone, Pipe, inject } from "@angular/core";
4
+ import { Observable, shareReplay } from "rxjs";
5
+ //#region src/angular.ts
6
+ /**
7
+ * Angular Injection Token to register global/default TimeGuard configurations.
8
+ */
9
+ var TIME_GUARD_CONFIG = new InjectionToken("TIME_GUARD_CONFIG");
10
+ /**
11
+ * Angular Pipe to format a date/time using TimeGuard.
12
+ * Supports global configuration overrides via DI.
13
+ * Usage: `{{ date | timeGuardFormat:'YYYY-MM-DD':'es' }}`
14
+ */
15
+ var TimeGuardFormatPipe = class {
16
+ globalConfig = inject(TIME_GUARD_CONFIG, { optional: true });
17
+ transform(value, pattern = "YYYY-MM-DD HH:mm:ss", locale) {
18
+ if (!value) return "";
19
+ try {
20
+ const tg = TimeGuard.from(value);
21
+ const activeLocale = locale || this.globalConfig?.locale;
22
+ if (activeLocale) return tg.locale(activeLocale).format(pattern);
23
+ return tg.format(pattern);
24
+ } catch {
25
+ return String(value);
26
+ }
27
+ }
28
+ };
29
+ /**
30
+ * Angular Pipe for dynamic relative time humanization.
31
+ * Supports global configuration overrides via DI.
32
+ * Usage: `{{ date | timeGuardRelative:'es':'auto' }}`
33
+ */
34
+ var TimeGuardRelativePipe = class {
35
+ globalConfig = inject(TIME_GUARD_CONFIG, { optional: true });
36
+ transform(value, locale, numeric) {
37
+ if (!value) return "";
38
+ try {
39
+ const tg = TimeGuard.from(value);
40
+ const now = TimeGuard.now();
41
+ const activeLocale = locale || this.globalConfig?.locale;
42
+ return tg.since(now).humanize({
43
+ locale: activeLocale,
44
+ numeric
45
+ });
46
+ } catch {
47
+ return String(value);
48
+ }
49
+ }
50
+ };
51
+ /**
52
+ * Injectable Service to interact with TimeGuard.
53
+ * Provides a high-performance reactive Observable of the current time
54
+ * running outside Angular zone to optimize change detection ticks.
55
+ * Supports global configuration overrides via DI.
56
+ */
57
+ var TimeGuardService = class {
58
+ ngZone = inject(NgZone);
59
+ globalConfig = inject(TIME_GUARD_CONFIG, { optional: true });
60
+ /**
61
+ * Get an Observable of the current time, ticking on the specified interval.
62
+ */
63
+ getCurrentTime(intervalMs = 1e3, config) {
64
+ const activeConfig = config ?? this.globalConfig ?? void 0;
65
+ return new Observable((subscriber) => {
66
+ return this.ngZone.runOutsideAngular(() => {
67
+ subscriber.next(TimeGuard.now(activeConfig));
68
+ const intervalId = setInterval(() => {
69
+ this.ngZone.run(() => {
70
+ subscriber.next(TimeGuard.now(activeConfig));
71
+ });
72
+ }, intervalMs);
73
+ return () => {
74
+ clearInterval(intervalId);
75
+ };
76
+ });
77
+ }).pipe(shareReplay(1));
78
+ }
79
+ };
80
+ /**
81
+ * Angular Pipe to dynamically tick and format dates at a custom interval.
82
+ * Highly optimized, impure pipe utilizing TimeGuardService and ChangeDetectorRef.
83
+ * Usage:
84
+ * - Real-time clock: `{{ 'now' | timeGuardLiveFormat:'HH:mm:ss':1000 }}`
85
+ * - Ticking static date: `{{ date | timeGuardLiveFormat:'YYYY-MM-DD HH:mm:ss':5000 }}`
86
+ */
87
+ var TimeGuardLiveFormatPipe = class {
88
+ latestValue = "";
89
+ subscription;
90
+ lastInput;
91
+ lastPattern;
92
+ lastInterval;
93
+ lastLocale;
94
+ cdr = inject(ChangeDetectorRef);
95
+ timeGuardService = inject(TimeGuardService);
96
+ globalConfig = inject(TIME_GUARD_CONFIG, { optional: true });
97
+ transform(value, pattern = "YYYY-MM-DD HH:mm:ss", intervalMs = 1e3, locale) {
98
+ if (!value) return "";
99
+ if (value !== this.lastInput || pattern !== this.lastPattern || intervalMs !== this.lastInterval || locale !== this.lastLocale) {
100
+ this.ngOnDestroy();
101
+ this.lastInput = value;
102
+ this.lastPattern = pattern;
103
+ this.lastInterval = intervalMs;
104
+ this.lastLocale = locale;
105
+ const activeLocale = locale || this.globalConfig?.locale;
106
+ if (value === "now") this.subscription = this.timeGuardService.getCurrentTime(intervalMs).subscribe((now) => {
107
+ this.latestValue = activeLocale ? now.locale(activeLocale).format(pattern) : now.format(pattern);
108
+ this.cdr.markForCheck();
109
+ });
110
+ else this.subscription = this.timeGuardService.getCurrentTime(intervalMs).subscribe(() => {
111
+ try {
112
+ const tg = TimeGuard.from(value);
113
+ this.latestValue = activeLocale ? tg.locale(activeLocale).format(pattern) : tg.format(pattern);
114
+ this.cdr.markForCheck();
115
+ } catch {
116
+ this.latestValue = String(value);
117
+ }
118
+ });
119
+ }
120
+ return this.latestValue;
121
+ }
122
+ ngOnDestroy() {
123
+ if (this.subscription) {
124
+ this.subscription.unsubscribe();
125
+ this.subscription = void 0;
126
+ }
127
+ }
128
+ };
129
+ Pipe({
130
+ name: "timeGuardFormat",
131
+ pure: true
132
+ })(TimeGuardFormatPipe);
133
+ Pipe({
134
+ name: "timeGuardRelative",
135
+ pure: false
136
+ })(TimeGuardRelativePipe);
137
+ Injectable({ providedIn: "root" })(TimeGuardService);
138
+ Pipe({
139
+ name: "timeGuardLiveFormat",
140
+ pure: false
141
+ })(TimeGuardLiveFormatPipe);
142
+ //#endregion
143
+ export { TIME_GUARD_CONFIG, TimeGuardFormatPipe, TimeGuardLiveFormatPipe, TimeGuardRelativePipe, TimeGuardService };
@@ -0,0 +1,59 @@
1
+ import { PipeTransform, InjectionToken, OnDestroy } from '@angular/core';
2
+ import { Observable } from 'rxjs';
3
+ import { TimeGuard, FormatPreset, ITimeGuardConfig } from './core';
4
+ /**
5
+ * Angular Injection Token to register global/default TimeGuard configurations.
6
+ */
7
+ export declare const TIME_GUARD_CONFIG: InjectionToken<ITimeGuardConfig>;
8
+ /**
9
+ * Angular Pipe to format a date/time using TimeGuard.
10
+ * Supports global configuration overrides via DI.
11
+ * Usage: `{{ date | timeGuardFormat:'YYYY-MM-DD':'es' }}`
12
+ */
13
+ export declare class TimeGuardFormatPipe implements PipeTransform {
14
+ private globalConfig;
15
+ transform(value: unknown, pattern?: string | FormatPreset, locale?: string): string;
16
+ }
17
+ /**
18
+ * Angular Pipe for dynamic relative time humanization.
19
+ * Supports global configuration overrides via DI.
20
+ * Usage: `{{ date | timeGuardRelative:'es':'auto' }}`
21
+ */
22
+ export declare class TimeGuardRelativePipe implements PipeTransform {
23
+ private globalConfig;
24
+ transform(value: unknown, locale?: string, numeric?: 'always' | 'auto'): string;
25
+ }
26
+ /**
27
+ * Injectable Service to interact with TimeGuard.
28
+ * Provides a high-performance reactive Observable of the current time
29
+ * running outside Angular zone to optimize change detection ticks.
30
+ * Supports global configuration overrides via DI.
31
+ */
32
+ export declare class TimeGuardService {
33
+ private ngZone;
34
+ private globalConfig;
35
+ /**
36
+ * Get an Observable of the current time, ticking on the specified interval.
37
+ */
38
+ getCurrentTime(intervalMs?: number, config?: ITimeGuardConfig): Observable<TimeGuard>;
39
+ }
40
+ /**
41
+ * Angular Pipe to dynamically tick and format dates at a custom interval.
42
+ * Highly optimized, impure pipe utilizing TimeGuardService and ChangeDetectorRef.
43
+ * Usage:
44
+ * - Real-time clock: `{{ 'now' | timeGuardLiveFormat:'HH:mm:ss':1000 }}`
45
+ * - Ticking static date: `{{ date | timeGuardLiveFormat:'YYYY-MM-DD HH:mm:ss':5000 }}`
46
+ */
47
+ export declare class TimeGuardLiveFormatPipe implements PipeTransform, OnDestroy {
48
+ private latestValue;
49
+ private subscription?;
50
+ private lastInput?;
51
+ private lastPattern?;
52
+ private lastInterval?;
53
+ private lastLocale?;
54
+ private cdr;
55
+ private timeGuardService;
56
+ private globalConfig;
57
+ transform(value: unknown, pattern?: string | FormatPreset, intervalMs?: number, locale?: string): string;
58
+ ngOnDestroy(): void;
59
+ }