@bereasoftware/time-guard 2.5.2 → 2.5.3

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 (50) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/calendars/index.es.js +1 -1
  4. package/dist/plugins/advanced-format.cjs.map +1 -1
  5. package/dist/plugins/advanced-format.es.js +1 -1
  6. package/dist/plugins/advanced-format.es.js.map +1 -1
  7. package/dist/plugins/duration.cjs.map +1 -1
  8. package/dist/plugins/duration.es.js +1 -1
  9. package/dist/plugins/duration.es.js.map +1 -1
  10. package/dist/plugins/relative-time.cjs.map +1 -1
  11. package/dist/plugins/relative-time.es.js +1 -1
  12. package/dist/plugins/relative-time.es.js.map +1 -1
  13. package/dist/time-guard.cjs +1 -1
  14. package/dist/time-guard.cjs.map +1 -1
  15. package/dist/time-guard.es.js +3586 -3587
  16. package/dist/time-guard.es.js.map +1 -1
  17. package/dist/time-guard.iife.js +1 -1
  18. package/dist/time-guard.iife.js.map +1 -1
  19. package/dist/time-guard.umd.js +1 -1
  20. package/dist/time-guard.umd.js.map +1 -1
  21. package/dist/types/calendars/index.d.ts +1 -81
  22. package/dist/types/index.d.ts +1 -20
  23. package/dist/types/locales/index.d.ts +1 -17
  24. package/dist/types/plugins/advanced-format.d.ts +1 -0
  25. package/dist/types/plugins/duration.d.ts +1 -0
  26. package/dist/types/plugins/relative-time.d.ts +1 -0
  27. package/package.json +6 -6
  28. package/dist/types/adapters/temporal.adapter.d.ts +0 -66
  29. package/dist/types/calendars/calendar.manager.d.ts +0 -52
  30. package/dist/types/formatters/date.formatter.d.ts +0 -21
  31. package/dist/types/locales/additional.locale.d.ts +0 -5
  32. package/dist/types/locales/asian.locale.d.ts +0 -9
  33. package/dist/types/locales/english.locale.d.ts +0 -6
  34. package/dist/types/locales/european.locale.d.ts +0 -9
  35. package/dist/types/locales/locale.manager.d.ts +0 -42
  36. package/dist/types/locales/middle-eastern.locale.d.ts +0 -5
  37. package/dist/types/locales/nordic.locale.d.ts +0 -6
  38. package/dist/types/locales/romance.locale.d.ts +0 -7
  39. package/dist/types/locales/slavic.locale.d.ts +0 -6
  40. package/dist/types/locales/spanish.locale.d.ts +0 -5
  41. package/dist/types/plugins/advanced-format/index.d.ts +0 -15
  42. package/dist/types/plugins/duration/index.d.ts +0 -107
  43. package/dist/types/plugins/duration/types.d.ts +0 -85
  44. package/dist/types/plugins/index.d.ts +0 -10
  45. package/dist/types/plugins/manager.d.ts +0 -58
  46. package/dist/types/plugins/relative-time/index.d.ts +0 -39
  47. package/dist/types/plugins/relative-time/types.d.ts +0 -27
  48. package/dist/types/time-guard.d.ts +0 -270
  49. package/dist/types/types/index.d.ts +0 -586
  50. package/dist/types/utils/duration-locale.d.ts +0 -33
@@ -1,58 +0,0 @@
1
- import { ITimeGuardPlugin } from '../types';
2
- import { TimeGuard } from '../time-guard';
3
- /**
4
- * Plugin Manager - handles plugin registration and initialization
5
- * Uses Singleton pattern to ensure single instance across application
6
- */
7
- export declare class PluginManager {
8
- private static instance;
9
- private plugins;
10
- /**
11
- * Get singleton instance
12
- */
13
- static getInstance(): PluginManager;
14
- /**
15
- * Register a plugin
16
- * @param plugin - The plugin to register
17
- * @param timeGuardClass - Reference to TimeGuard class
18
- * @param config - Optional plugin configuration
19
- */
20
- static use(plugin: ITimeGuardPlugin, timeGuardClass: typeof TimeGuard, config?: unknown): void;
21
- /**
22
- * Register multiple plugins at once
23
- * @param plugins - Array of plugins to register
24
- * @param timeGuardClass - Reference to TimeGuard class
25
- * @param config - Optional plugin configuration
26
- */
27
- static useMultiple(plugins: ITimeGuardPlugin[], timeGuardClass: typeof TimeGuard, config?: unknown): void;
28
- /**
29
- * Get registered plugin by name
30
- * @param name - Plugin name
31
- * @returns Plugin instance or undefined
32
- */
33
- static getPlugin(name: string): ITimeGuardPlugin | undefined;
34
- /**
35
- * Check if plugin is registered
36
- * @param name - Plugin name
37
- * @returns True if plugin is registered
38
- */
39
- static hasPlugin(name: string): boolean;
40
- /**
41
- * Get all registered plugins
42
- * @returns Array of registered plugin names
43
- */
44
- static listPlugins(): string[];
45
- /**
46
- * Unregister a plugin
47
- * @param name - Plugin name
48
- */
49
- static unuse(name: string): boolean;
50
- /**
51
- * Clear all plugins
52
- */
53
- static clear(): void;
54
- /**
55
- * Internal register method
56
- */
57
- private register;
58
- }
@@ -1,39 +0,0 @@
1
- import { ITimeGuardPlugin } from '../../types';
2
- import { TimeGuard } from '../../time-guard';
3
- import { RelativeTimeConfig, RelativeTimeFormats } from './types';
4
- export declare class RelativeTimePlugin implements ITimeGuardPlugin {
5
- name: string;
6
- version: string;
7
- private config;
8
- private formats;
9
- constructor(config?: RelativeTimeConfig);
10
- /**
11
- * Install plugin into TimeGuard
12
- */
13
- install(TimeGuardClass: typeof TimeGuard): void;
14
- /**
15
- * Format relative time
16
- */
17
- private formatRelativeTime;
18
- /**
19
- * Get relative time string based on milliseconds
20
- */
21
- private getRelativeTimeString;
22
- /**
23
- * Get milliseconds per unit
24
- */
25
- private getUnitMilliseconds;
26
- /**
27
- * Set format strings
28
- */
29
- setFormats(formats: Partial<RelativeTimeFormats>): void;
30
- /**
31
- * Get current formats
32
- */
33
- getFormats(): RelativeTimeFormats;
34
- }
35
- /**
36
- * Create and export default instance
37
- */
38
- declare const _default: RelativeTimePlugin;
39
- export default _default;
@@ -1,27 +0,0 @@
1
- /**
2
- * RelativeTime Plugin Types
3
- */
4
- export interface RelativeTimeConfig {
5
- thresholds?: RelativeTimeThreshold[];
6
- rounding?: (value: number) => number;
7
- }
8
- export interface RelativeTimeThreshold {
9
- l: string;
10
- r?: number;
11
- d?: string;
12
- }
13
- export interface RelativeTimeFormats {
14
- future: string;
15
- past: string;
16
- s: string;
17
- m: string;
18
- mm: string;
19
- h: string;
20
- hh: string;
21
- d: string;
22
- dd: string;
23
- M: string;
24
- MM: string;
25
- y: string;
26
- yy: string;
27
- }
@@ -1,270 +0,0 @@
1
- import { ITimeGuard, ITimeGuardConfig, Unit, FormatPreset, IRoundOptions, IDurationOptions, IDiffResult, IDiffOptions, DurationParts, IDurationExplanation, IFormattableDuration } from './types';
2
- /**
3
- * Diff result object that allows chaining with .as()
4
- *
5
- * Supports two modes:
6
- * - 'exact': Returns precise time differences
7
- * - 'calendar': Returns calendar-aware breakdown
8
- */
9
- declare class DiffResult implements IDiffResult, IFormattableDuration {
10
- private _value;
11
- private _tg1;
12
- private _tg2;
13
- private _mode;
14
- private _breakdownData;
15
- private _locale;
16
- constructor(value: number, tg1: TimeGuard, tg2: TimeGuard, mode?: 'calendar' | 'exact', breakdownData?: DurationParts, locale?: string);
17
- as(unit: Unit): number;
18
- breakdown(): DurationParts | null;
19
- format(locale?: string): string;
20
- getMode(): 'calendar' | 'exact';
21
- valueOf(): number;
22
- toString(): string;
23
- toJSON(): number;
24
- }
25
- /**
26
- * DurationResult class - Represents a duration breakdown with humanize support
27
- * Returned by until(), since(), and between() methods
28
- */
29
- export declare class DurationResult implements DurationParts, IFormattableDuration {
30
- years: number;
31
- months: number;
32
- weeks: number;
33
- days: number;
34
- hours: number;
35
- minutes: number;
36
- seconds: number;
37
- milliseconds: number;
38
- private _locale;
39
- private _startDate?;
40
- private _endDate?;
41
- private _steps;
42
- private _mode;
43
- private _leapYearFlags;
44
- private _calculationTimeMs;
45
- constructor(parts: DurationParts, locale?: string, metadata?: {
46
- startDate?: string;
47
- endDate?: string;
48
- steps?: string[];
49
- mode?: 'exact' | 'estimated';
50
- leapYearFlags?: Array<{
51
- year: number;
52
- isLeap: boolean;
53
- daysInFebruary: number;
54
- }>;
55
- calculationTimeMs?: number;
56
- });
57
- humanize(options?: {
58
- locale?: string;
59
- fullBreakdown?: boolean;
60
- numeric?: 'always' | 'auto';
61
- }): string;
62
- total(unit: Unit): number;
63
- toString(): string;
64
- toJSON(): Record<string, number>;
65
- explain(): IDurationExplanation;
66
- private generateExplanationSteps;
67
- private pluralizeUnit;
68
- }
69
- /**
70
- * TimeGuard implementation - Main facade class
71
- */
72
- /**
73
- * TimeRange - Fluent API for date range operations
74
- *
75
- * @example
76
- * TimeGuard.range('2024-01-15', '2024-03-20')
77
- * .toDuration().humanize() // "2 months and 5 days"
78
- * .inMonths() // 2.1355 (precise decimal)
79
- */
80
- export declare class TimeRange {
81
- private _start;
82
- private _end;
83
- constructor(start: TimeGuard, end: TimeGuard);
84
- toDuration(): DurationResult;
85
- inMonths(): number;
86
- humanize(options?: {
87
- locale?: string;
88
- fullBreakdown?: boolean;
89
- numeric?: 'always' | 'auto';
90
- }): string;
91
- in(unit: Unit): number;
92
- }
93
- export declare class TimeGuard implements ITimeGuard {
94
- private temporal;
95
- private config;
96
- private formatterInstance;
97
- private static readonly ZERO_DURATION;
98
- private static isLeapYearValue;
99
- private static toDurationParts;
100
- constructor(input?: unknown, config?: ITimeGuardConfig);
101
- static now(config?: ITimeGuardConfig): TimeGuard;
102
- static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
103
- static fromTemporal(temporal: any, // Temporal.PlainDateTime | Temporal.ZonedDateTime
104
- config?: ITimeGuardConfig): TimeGuard;
105
- /**
106
- * Calculate duration between two dates - always returns positive duration
107
- *
108
- * @example
109
- * TimeGuard.between(start, end).humanize() // "2 months and 5 days"
110
- * TimeGuard.between(end, start).humanize() // "2 months and 5 days" (still positive)
111
- */
112
- static between(date1: TimeGuard, date2: TimeGuard): DurationResult;
113
- /**
114
- * Create a TimeRange for fluent duration calculations
115
- *
116
- * @example
117
- * TimeGuard.range("2024-01-15", "2024-03-20").humanize() // "2 months and 5 days"
118
- */
119
- static range(start: unknown, end: unknown): TimeRange;
120
- toTemporal(): any;
121
- toDate(): Date;
122
- toISOString(): string;
123
- valueOf(): number;
124
- unix(): number;
125
- toJSON(): string;
126
- toString(): string;
127
- locale(): string;
128
- locale(locale: string): TimeGuard;
129
- timezone(): string | null;
130
- timezone(timezone: string): TimeGuard;
131
- format(pattern: string | FormatPreset): string;
132
- get(component: Unit): number;
133
- add(units: Partial<Record<Unit, number>>): TimeGuard;
134
- subtract(units: Partial<Record<Unit, number>>): TimeGuard;
135
- /**
136
- * Calculate difference between two TimeGuard instances
137
- *
138
- * Supports multiple modes:
139
- * 1. diff(other) - Returns DiffResult with fluent API (default: exact mode)
140
- * 2. diff(other, unit) - Returns number (backward compatible)
141
- * 3. diff(other, options) - Returns DiffResult with calendar or exact mode
142
- *
143
- * @example
144
- * // Exact mode (default)
145
- * tg1.diff(tg2).as('day') // 65
146
- * // Calendar mode
147
- * tg1.diff(tg2, { mode: 'calendar' }).format('en') // "2 months and 5 days"
148
- */
149
- diff(other: TimeGuard): DiffResult;
150
- diff(other: TimeGuard, unit: Unit): number;
151
- diff(other: TimeGuard, options: IDiffOptions): DiffResult;
152
- isBefore(other: TimeGuard): boolean;
153
- isAfter(other: TimeGuard): boolean;
154
- isSame(other: TimeGuard, unit?: Unit): boolean;
155
- isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
156
- clone(): TimeGuard;
157
- startOf(unit: Unit): TimeGuard;
158
- endOf(unit: Unit): TimeGuard;
159
- set(values: Partial<Record<Unit, number>>): TimeGuard;
160
- year(): number;
161
- month(): number;
162
- day(): number;
163
- hour(): number;
164
- minute(): number;
165
- second(): number;
166
- millisecond(): number;
167
- dayOfWeek(): number;
168
- dayOfYear(): number;
169
- weekOfYear(): number;
170
- daysInMonth(): number;
171
- daysInYear(): number;
172
- inLeapYear(): boolean;
173
- /**
174
- * Calculate duration until another TimeGuard
175
- * @returns Duration object with .humanize() and other methods
176
- * @example
177
- * start.until(end).humanize() // "2 months and 5 days"
178
- * start.until(end).humanize({ fullBreakdown: true, locale: 'es' }) // "2 meses y 5 días"
179
- */
180
- until(other: TimeGuard, options?: IDurationOptions): DurationResult;
181
- /**
182
- * Generate explanation steps for until() calculation
183
- */
184
- private generateUntilSteps;
185
- /**
186
- * Round to a specific unit with optional rounding mode
187
- */
188
- round(options?: IRoundOptions): TimeGuard;
189
- /**
190
- * Convert to PlainDate (removes time information)
191
- */
192
- toPlainDate(): {
193
- year: number;
194
- month: number;
195
- day: number;
196
- dayOfWeek: number;
197
- };
198
- /**
199
- * Convert to PlainTime (removes date information)
200
- */
201
- toPlainTime(): {
202
- hour: number;
203
- minute: number;
204
- second: number;
205
- millisecond: number;
206
- };
207
- /**
208
- * Create new TimeGuard with only date, keeping time from parameter
209
- */
210
- withDate(year: number, month: number, day: number): TimeGuard;
211
- /**
212
- * Create new TimeGuard with only time, keeping date
213
- */
214
- withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
215
- /**
216
- * Get timezone offset in format ±HH:mm
217
- */
218
- getOffset(): string;
219
- /**
220
- * Get timezone offset in nanoseconds
221
- */
222
- getOffsetNanoseconds(): number;
223
- /**
224
- * Get timezone ID
225
- */
226
- getTimeZoneId(): string | null;
227
- /**
228
- * Start of the day in current timezone
229
- */
230
- startOfDay(): TimeGuard;
231
- /**
232
- * End of the day in current timezone
233
- */
234
- endOfDay(): TimeGuard;
235
- /**
236
- * Calculate duration from another TimeGuard (inverse of until)
237
- * Returns negative values if other is before this
238
- * @returns Duration object with .humanize() and other methods
239
- * @example
240
- * end.since(start).humanize() // "2 months and 5 days"
241
- * end.since(start).humanize({ locale: 'es' }) // "2 meses y 5 días"
242
- */
243
- since(other: TimeGuard, options?: IDurationOptions): DurationResult;
244
- /**
245
- * Get ISO 8601 duration string
246
- * Example: P1Y2M3DT4H5M6S
247
- */
248
- toDurationString(other?: TimeGuard): string;
249
- /**
250
- * Check if this date is in the past
251
- */
252
- isPast(): boolean;
253
- /**
254
- * Check if this date is in the future
255
- */
256
- isFuture(): boolean;
257
- /**
258
- * Check if this date is today
259
- */
260
- isToday(): boolean;
261
- /**
262
- * Check if this date is tomorrow
263
- */
264
- isTomorrow(): boolean;
265
- /**
266
- * Check if this date is yesterday
267
- */
268
- isYesterday(): boolean;
269
- }
270
- export { PluginManager } from './plugins/manager';