@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
@@ -1,6 +1,9 @@
1
- /*! time-guard v2.6.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.7.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
2
  //#region src/plugins/duration/index.ts
3
- var e = class e {
3
+ /**
4
+ * Duration class - represents time span following ISO 8601 standard
5
+ */
6
+ var Duration = class Duration {
4
7
  years = 0;
5
8
  months = 0;
6
9
  weeks = 0;
@@ -9,48 +12,79 @@ var e = class e {
9
12
  minutes = 0;
10
13
  seconds = 0;
11
14
  milliseconds = 0;
12
- constructor(e) {
13
- this.years = e.years || 0, this.months = e.months || 0, this.weeks = e.weeks || 0, this.days = e.days || 0, this.hours = e.hours || 0, this.minutes = e.minutes || 0, this.seconds = e.seconds || 0, this.milliseconds = e.milliseconds || 0;
14
- }
15
- static fromISO(t) {
16
- let n = t.match(/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:([\d.]+)S)?)?$/);
17
- if (!n) throw Error(`Invalid ISO 8601 duration: ${t}`);
18
- let [, r, i, a, , o, s, c, l] = n, u = r ? -1 : 1;
19
- return new e({
20
- years: parseInt(i || "0", 10) * u,
21
- months: parseInt(a || "0", 10) * u,
22
- days: parseInt(o || "0", 10) * u,
23
- hours: parseInt(s || "0", 10) * u,
24
- minutes: parseInt(c || "0", 10) * u,
25
- seconds: parseFloat(l || "0") * u
15
+ constructor(input) {
16
+ this.years = input.years || 0;
17
+ this.months = input.months || 0;
18
+ this.weeks = input.weeks || 0;
19
+ this.days = input.days || 0;
20
+ this.hours = input.hours || 0;
21
+ this.minutes = input.minutes || 0;
22
+ this.seconds = input.seconds || 0;
23
+ this.milliseconds = input.milliseconds || 0;
24
+ }
25
+ /**
26
+ * Create Duration from ISO 8601 string
27
+ * @example Duration.fromISO("P3Y6M4DT12H30M5S")
28
+ */
29
+ static fromISO(iso) {
30
+ const match = iso.match(/^(-)?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:([\d.]+)S)?)?$/);
31
+ if (!match) throw new Error(`Invalid ISO 8601 duration: ${iso}`);
32
+ const [, negative, years, months, , days, hours, minutes, seconds] = match;
33
+ const multiplier = negative ? -1 : 1;
34
+ return new Duration({
35
+ years: parseInt(years || "0", 10) * multiplier,
36
+ months: parseInt(months || "0", 10) * multiplier,
37
+ days: parseInt(days || "0", 10) * multiplier,
38
+ hours: parseInt(hours || "0", 10) * multiplier,
39
+ minutes: parseInt(minutes || "0", 10) * multiplier,
40
+ seconds: parseFloat(seconds || "0") * multiplier
26
41
  });
27
42
  }
28
- static between(t, n) {
29
- let r = t.toTemporal(), i = n.toTemporal().since(r);
30
- return new e({
31
- years: i.years || 0,
32
- months: i.months || 0,
43
+ /**
44
+ * Create a Duration between this date and another
45
+ */
46
+ static between(from, to) {
47
+ const fromDT = from.toTemporal();
48
+ const duration = to.toTemporal().since(fromDT);
49
+ return new Duration({
50
+ years: duration.years || 0,
51
+ months: duration.months || 0,
33
52
  weeks: 0,
34
- days: i.days || 0,
35
- hours: i.hours || 0,
36
- minutes: i.minutes || 0,
37
- seconds: i.seconds || 0,
38
- milliseconds: i.milliseconds || 0
53
+ days: duration.days || 0,
54
+ hours: duration.hours || 0,
55
+ minutes: duration.minutes || 0,
56
+ seconds: duration.seconds || 0,
57
+ milliseconds: duration.milliseconds || 0
39
58
  });
40
59
  }
41
- static fromMilliseconds(t) {
42
- let n = t < 0, r = Math.abs(t), i = Math.floor(r / (1e3 * 60 * 60 * 24 * 365)), a = Math.floor(r % (1e3 * 60 * 60 * 24 * 365) / (1e3 * 60 * 60 * 24 * 30)), o = Math.floor(r % (1e3 * 60 * 60 * 24 * 30) / (1e3 * 60 * 60 * 24)), s = Math.floor(r % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)), c = Math.floor(r % (1e3 * 60 * 60) / (1e3 * 60)), l = Math.floor(r % (1e3 * 60) / 1e3), u = Math.floor(r % 1e3), d = n ? -1 : 1;
43
- return new e({
44
- years: i * d,
45
- months: a * d,
46
- days: o * d,
47
- hours: s * d,
48
- minutes: c * d,
49
- seconds: l * d,
50
- milliseconds: u * d
60
+ /**
61
+ * Create Duration from milliseconds
62
+ */
63
+ static fromMilliseconds(ms) {
64
+ const isNegative = ms < 0;
65
+ const absMilhs = Math.abs(ms);
66
+ const years = Math.floor(absMilhs / (1e3 * 60 * 60 * 24 * 365));
67
+ const months = Math.floor(absMilhs % (1e3 * 60 * 60 * 24 * 365) / (1e3 * 60 * 60 * 24 * 30));
68
+ const days = Math.floor(absMilhs % (1e3 * 60 * 60 * 24 * 30) / (1e3 * 60 * 60 * 24));
69
+ const hours = Math.floor(absMilhs % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60));
70
+ const minutes = Math.floor(absMilhs % (1e3 * 60 * 60) / (1e3 * 60));
71
+ const seconds = Math.floor(absMilhs % (1e3 * 60) / 1e3);
72
+ const milliseconds = Math.floor(absMilhs % 1e3);
73
+ const multiplier = isNegative ? -1 : 1;
74
+ return new Duration({
75
+ years: years * multiplier,
76
+ months: months * multiplier,
77
+ days: days * multiplier,
78
+ hours: hours * multiplier,
79
+ minutes: minutes * multiplier,
80
+ seconds: seconds * multiplier,
81
+ milliseconds: milliseconds * multiplier
51
82
  });
52
83
  }
53
- as(e) {
84
+ /**
85
+ * Get duration in specific unit
86
+ */
87
+ as(unit) {
54
88
  return this.asMilliseconds() / {
55
89
  milliseconds: 1,
56
90
  seconds: 1e3,
@@ -60,32 +94,59 @@ var e = class e {
60
94
  weeks: 1e3 * 60 * 60 * 24 * 7,
61
95
  months: 1e3 * 60 * 60 * 24 * 30,
62
96
  years: 1e3 * 60 * 60 * 24 * 365
63
- }[e];
97
+ }[unit];
64
98
  }
99
+ /**
100
+ * Get duration as milliseconds
101
+ */
65
102
  asMilliseconds() {
66
103
  return this.years * 1e3 * 60 * 60 * 24 * 365 + this.months * 1e3 * 60 * 60 * 24 * 30 + this.weeks * 1e3 * 60 * 60 * 24 * 7 + this.days * 1e3 * 60 * 60 * 24 + this.hours * 1e3 * 60 * 60 + this.minutes * 1e3 * 60 + this.seconds * 1e3 + this.milliseconds;
67
104
  }
105
+ /**
106
+ * Get duration as seconds
107
+ */
68
108
  asSeconds() {
69
109
  return this.asMilliseconds() / 1e3;
70
110
  }
111
+ /**
112
+ * Get duration as minutes
113
+ */
71
114
  asMinutes() {
72
115
  return this.asSeconds() / 60;
73
116
  }
117
+ /**
118
+ * Get duration as hours
119
+ */
74
120
  asHours() {
75
121
  return this.asMinutes() / 60;
76
122
  }
123
+ /**
124
+ * Get duration as days
125
+ */
77
126
  asDays() {
78
127
  return this.asHours() / 24;
79
128
  }
129
+ /**
130
+ * Get duration as weeks
131
+ */
80
132
  asWeeks() {
81
133
  return this.asDays() / 7;
82
134
  }
135
+ /**
136
+ * Get duration as months
137
+ */
83
138
  asMonths() {
84
139
  return this.asDays() / 30;
85
140
  }
141
+ /**
142
+ * Get duration as years
143
+ */
86
144
  asYears() {
87
145
  return this.asDays() / 365;
88
146
  }
147
+ /**
148
+ * Get all components
149
+ */
89
150
  toObject() {
90
151
  return {
91
152
  years: this.years,
@@ -98,23 +159,49 @@ var e = class e {
98
159
  milliseconds: this.milliseconds
99
160
  };
100
161
  }
162
+ /**
163
+ * Get ISO 8601 string representation
164
+ * @example "P3Y6M4DT12H30M5S"
165
+ */
101
166
  toISO() {
102
- let e = "";
103
- this.years && (e += `${this.years}Y`), this.months && (e += `${this.months}M`), (this.weeks || this.days) && (e += `${this.weeks * 7 + this.days}D`);
104
- let t = "";
105
- return this.hours && (t += `${this.hours}H`), this.minutes && (t += `${this.minutes}M`), (this.seconds || this.milliseconds) && (t += `${this.seconds + this.milliseconds / 1e3}S`), `${this.isNegative() ? "-" : ""}P${e}${t ? `T${t}` : ""}`;
106
- }
167
+ let datePart = "";
168
+ if (this.years) datePart += `${this.years}Y`;
169
+ if (this.months) datePart += `${this.months}M`;
170
+ if (this.weeks || this.days) datePart += `${this.weeks * 7 + this.days}D`;
171
+ let timePart = "";
172
+ if (this.hours) timePart += `${this.hours}H`;
173
+ if (this.minutes) timePart += `${this.minutes}M`;
174
+ if (this.seconds || this.milliseconds) timePart += `${this.seconds + this.milliseconds / 1e3}S`;
175
+ return `${this.isNegative() ? "-" : ""}P${datePart}${timePart ? `T${timePart}` : ""}`;
176
+ }
177
+ /**
178
+ * Get human-readable string
179
+ */
107
180
  humanize() {
108
- let e = [];
109
- if (this.years && e.push(`${Math.abs(this.years)} year${Math.abs(this.years) === 1 ? "" : "s"}`), this.months && e.push(`${Math.abs(this.months)} month${Math.abs(this.months) === 1 ? "" : "s"}`), this.weeks && e.push(`${Math.abs(this.weeks)} week${Math.abs(this.weeks) === 1 ? "" : "s"}`), this.days && e.push(`${Math.abs(this.days)} day${Math.abs(this.days) === 1 ? "" : "s"}`), this.hours && e.push(`${Math.abs(this.hours)} hour${Math.abs(this.hours) === 1 ? "" : "s"}`), this.minutes && e.push(`${Math.abs(this.minutes)} minute${Math.abs(this.minutes) === 1 ? "" : "s"}`), this.seconds && e.push(`${Math.abs(this.seconds)} second${Math.abs(this.seconds) === 1 ? "" : "s"}`), this.milliseconds && e.push(`${Math.abs(this.milliseconds)} ms`), e.length === 0) return "0 seconds";
110
- let t = e.join(", ");
111
- return this.isNegative() ? `-${t}` : t;
112
- }
181
+ const parts = [];
182
+ if (this.years) parts.push(`${Math.abs(this.years)} year${Math.abs(this.years) !== 1 ? "s" : ""}`);
183
+ if (this.months) parts.push(`${Math.abs(this.months)} month${Math.abs(this.months) !== 1 ? "s" : ""}`);
184
+ if (this.weeks) parts.push(`${Math.abs(this.weeks)} week${Math.abs(this.weeks) !== 1 ? "s" : ""}`);
185
+ if (this.days) parts.push(`${Math.abs(this.days)} day${Math.abs(this.days) !== 1 ? "s" : ""}`);
186
+ if (this.hours) parts.push(`${Math.abs(this.hours)} hour${Math.abs(this.hours) !== 1 ? "s" : ""}`);
187
+ if (this.minutes) parts.push(`${Math.abs(this.minutes)} minute${Math.abs(this.minutes) !== 1 ? "s" : ""}`);
188
+ if (this.seconds) parts.push(`${Math.abs(this.seconds)} second${Math.abs(this.seconds) !== 1 ? "s" : ""}`);
189
+ if (this.milliseconds) parts.push(`${Math.abs(this.milliseconds)} ms`);
190
+ if (parts.length === 0) return "0 seconds";
191
+ const text = parts.join(", ");
192
+ return this.isNegative() ? `-${text}` : text;
193
+ }
194
+ /**
195
+ * Check if duration is negative
196
+ */
113
197
  isNegative() {
114
198
  return this.years < 0 || this.months < 0 || this.weeks < 0 || this.days < 0 || this.hours < 0 || this.minutes < 0 || this.seconds < 0 || this.milliseconds < 0;
115
199
  }
200
+ /**
201
+ * Get absolute duration
202
+ */
116
203
  abs() {
117
- return new e({
204
+ return new Duration({
118
205
  years: Math.abs(this.years),
119
206
  months: Math.abs(this.months),
120
207
  weeks: Math.abs(this.weeks),
@@ -125,23 +212,40 @@ var e = class e {
125
212
  milliseconds: Math.abs(this.milliseconds)
126
213
  });
127
214
  }
215
+ /**
216
+ * String representation
217
+ */
128
218
  toString() {
129
219
  return this.toISO();
130
220
  }
131
- }, t = class {
221
+ };
222
+ /**
223
+ * Duration Plugin
224
+ */
225
+ var DurationPlugin = class {
132
226
  name = "duration";
133
227
  version = "1.0.0";
134
- install(t) {
135
- t.prototype.duration = function(t) {
136
- return e.between(this, t);
137
- }, t.Duration = e, t.duration = {
138
- fromISO: (t) => e.fromISO(t),
139
- between: (t, n) => e.between(t, n),
140
- fromMilliseconds: (t) => e.fromMilliseconds(t)
228
+ /**
229
+ * Install plugin into TimeGuard
230
+ */
231
+ install(TimeGuardClass) {
232
+ /**
233
+ * Create a Duration between this date and another
234
+ */
235
+ TimeGuardClass.prototype.duration = function(other) {
236
+ return Duration.between(this, other);
237
+ };
238
+ TimeGuardClass.Duration = Duration;
239
+ TimeGuardClass.duration = {
240
+ fromISO: (iso) => Duration.fromISO(iso),
241
+ between: (from, to) => Duration.between(from, to),
242
+ fromMilliseconds: (ms) => Duration.fromMilliseconds(ms)
141
243
  };
142
244
  }
143
- }, n = new t();
245
+ };
246
+ /**
247
+ * Create and export default instance
248
+ */
249
+ var durationPlugin = new DurationPlugin();
144
250
  //#endregion
145
- export { e as Duration, t as DurationPlugin, n as default, n as durationPlugin };
146
-
147
- //# sourceMappingURL=duration.es.js.map
251
+ export { Duration, DurationPlugin, durationPlugin as default, durationPlugin };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * TimeGuard Plugins
3
+ * Central export point for all plugins
4
+ */
5
+ export { PluginManager } from './manager';
6
+ export { RelativeTimePlugin, default as relativeTimePlugin, } from './relative-time';
7
+ export { DurationPlugin, Duration, default as durationPlugin, } from './duration';
8
+ export { AdvancedFormatPlugin, default as advancedFormatPlugin, } from './advanced-format';
9
+ export type { RelativeTimeConfig, RelativeTimeFormats, RelativeTimeThreshold, } from './relative-time/types';
10
+ export type { IDuration, DurationInput, DurationObject, DurationUnit, } from './duration/types';
@@ -1,2 +1,166 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=[{l:`s`,r:44,d:`second`},{l:`m`,r:89},{l:`mm`,r:44,d:`minute`},{l:`h`,r:89},{l:`hh`,r:21,d:`hour`},{l:`d`,r:35},{l:`dd`,r:25,d:`day`},{l:`M`,r:45},{l:`MM`,r:10,d:`month`},{l:`y`,r:17},{l:`yy`,d:`year`}],t={future:`in %s`,past:`%s ago`,s:`a few seconds`,m:`a minute`,mm:`%d minutes`,h:`an hour`,hh:`%d hours`,d:`a day`,dd:`%d days`,M:`a month`,MM:`%d months`,y:`a year`,yy:`%d years`},n=class{name=`relative-time`;version=`1.0.0`;config;formats;constructor(n){this.config={thresholds:n?.thresholds||e,rounding:n?.rounding||Math.round},this.formats=t}install(e){let t=this;e.prototype.fromNow=function(e){return t.formatRelativeTime(this,!1,e)},e.prototype.toNow=function(e){return t.formatRelativeTime(this,!0,e)},e.prototype.humanize=function(e,n){return e?t.formatRelativeTime(this,e.isAfter(this),n):t.formatRelativeTime(this,!1,n)}}formatRelativeTime(e,t,n){let r=e.constructor.now().diff(e,`millisecond`),i=Math.abs(r),a=t??!(r>0),o=this.getRelativeTimeString(i);return n?o:(a?this.formats.future:this.formats.past).replace(`%s`,o)}getRelativeTimeString(t){let n=this.config.thresholds||e,r=this.config.rounding||Math.round;for(let e=0;e<n.length;e++){let i=n[e];if(e+1<n.length&&n[e+1]&&i.r&&t<i.r*1e3)continue;let a;a=i.d?r(t/this.getUnitMilliseconds(i.d)):1;let o=i.l,s=this.formats[o]||o;return typeof s==`string`&&s.includes(`%d`)?s.replace(`%d`,String(a)):s}return`${r(t/1e3)} seconds`}getUnitMilliseconds(e){return{second:1e3,minute:1e3*60,hour:1e3*60*60,day:1e3*60*60*24,month:1e3*60*60*24*30,year:1e3*60*60*24*365}[e]||1}setFormats(e){Object.assign(this.formats,e)}getFormats(){return{...this.formats}}},r=new n;exports.RelativeTimePlugin=n,exports.default=r;
2
- //# sourceMappingURL=relative-time.cjs.map
1
+ /*! time-guard v2.7.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ //#region src/plugins/relative-time/index.ts
7
+ var DEFAULT_THRESHOLDS = [
8
+ {
9
+ l: "s",
10
+ r: 44,
11
+ d: "second"
12
+ },
13
+ {
14
+ l: "m",
15
+ r: 89
16
+ },
17
+ {
18
+ l: "mm",
19
+ r: 44,
20
+ d: "minute"
21
+ },
22
+ {
23
+ l: "h",
24
+ r: 89
25
+ },
26
+ {
27
+ l: "hh",
28
+ r: 21,
29
+ d: "hour"
30
+ },
31
+ {
32
+ l: "d",
33
+ r: 35
34
+ },
35
+ {
36
+ l: "dd",
37
+ r: 25,
38
+ d: "day"
39
+ },
40
+ {
41
+ l: "M",
42
+ r: 45
43
+ },
44
+ {
45
+ l: "MM",
46
+ r: 10,
47
+ d: "month"
48
+ },
49
+ {
50
+ l: "y",
51
+ r: 17
52
+ },
53
+ {
54
+ l: "yy",
55
+ d: "year"
56
+ }
57
+ ];
58
+ var DEFAULT_FORMATS = {
59
+ future: "in %s",
60
+ past: "%s ago",
61
+ s: "a few seconds",
62
+ m: "a minute",
63
+ mm: "%d minutes",
64
+ h: "an hour",
65
+ hh: "%d hours",
66
+ d: "a day",
67
+ dd: "%d days",
68
+ M: "a month",
69
+ MM: "%d months",
70
+ y: "a year",
71
+ yy: "%d years"
72
+ };
73
+ var RelativeTimePlugin = class {
74
+ name = "relative-time";
75
+ version = "1.0.0";
76
+ config;
77
+ formats;
78
+ constructor(config) {
79
+ this.config = {
80
+ thresholds: config?.thresholds || DEFAULT_THRESHOLDS,
81
+ rounding: config?.rounding || Math.round
82
+ };
83
+ this.formats = DEFAULT_FORMATS;
84
+ }
85
+ /**
86
+ * Install plugin into TimeGuard
87
+ */
88
+ install(TimeGuardClass) {
89
+ const plugin = this;
90
+ /**
91
+ * Get relative time string (e.g., "2 hours ago")
92
+ */
93
+ TimeGuardClass.prototype.fromNow = function(withoutSuffix) {
94
+ return plugin.formatRelativeTime(this, false, withoutSuffix);
95
+ };
96
+ TimeGuardClass.prototype.toNow = function(withoutSuffix) {
97
+ return plugin.formatRelativeTime(this, true, withoutSuffix);
98
+ };
99
+ TimeGuardClass.prototype.humanize = function(other, withoutSuffix) {
100
+ if (other) return plugin.formatRelativeTime(this, other.isAfter(this), withoutSuffix);
101
+ return plugin.formatRelativeTime(this, false, withoutSuffix);
102
+ };
103
+ }
104
+ /**
105
+ * Format relative time
106
+ */
107
+ formatRelativeTime(date, isFuture, withoutSuffix) {
108
+ const diff = date.constructor.now().diff(date, "millisecond");
109
+ const absDiff = Math.abs(diff);
110
+ const actualIsFuture = isFuture ?? !(diff > 0);
111
+ const result = this.getRelativeTimeString(absDiff);
112
+ if (withoutSuffix) return result;
113
+ return (actualIsFuture ? this.formats.future : this.formats.past).replace("%s", result);
114
+ }
115
+ /**
116
+ * Get relative time string based on milliseconds
117
+ */
118
+ getRelativeTimeString(milliseconds) {
119
+ const thresholds = this.config.thresholds || DEFAULT_THRESHOLDS;
120
+ const rounding = this.config.rounding || Math.round;
121
+ for (let i = 0; i < thresholds.length; i++) {
122
+ const threshold = thresholds[i];
123
+ if ((i + 1 < thresholds.length ? thresholds[i + 1] : null) && threshold.r && milliseconds < threshold.r * 1e3) continue;
124
+ let value;
125
+ if (threshold.d) value = rounding(milliseconds / this.getUnitMilliseconds(threshold.d));
126
+ else value = 1;
127
+ const label = threshold.l;
128
+ const format = this.formats[label] || label;
129
+ if (typeof format === "string") return format.includes("%d") ? format.replace("%d", String(value)) : format;
130
+ return format;
131
+ }
132
+ return `${rounding(milliseconds / 1e3)} seconds`;
133
+ }
134
+ /**
135
+ * Get milliseconds per unit
136
+ */
137
+ getUnitMilliseconds(unit) {
138
+ return {
139
+ second: 1e3,
140
+ minute: 1e3 * 60,
141
+ hour: 1e3 * 60 * 60,
142
+ day: 1e3 * 60 * 60 * 24,
143
+ month: 1e3 * 60 * 60 * 24 * 30,
144
+ year: 1e3 * 60 * 60 * 24 * 365
145
+ }[unit] || 1;
146
+ }
147
+ /**
148
+ * Set format strings
149
+ */
150
+ setFormats(formats) {
151
+ Object.assign(this.formats, formats);
152
+ }
153
+ /**
154
+ * Get current formats
155
+ */
156
+ getFormats() {
157
+ return { ...this.formats };
158
+ }
159
+ };
160
+ /**
161
+ * Create and export default instance
162
+ */
163
+ var relative_time_default = new RelativeTimePlugin();
164
+ //#endregion
165
+ exports.RelativeTimePlugin = RelativeTimePlugin;
166
+ exports.default = relative_time_default;
@@ -1,6 +1,6 @@
1
- /*! time-guard v2.6.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.7.0 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
2
  //#region src/plugins/relative-time/index.ts
3
- var e = [
3
+ var DEFAULT_THRESHOLDS = [
4
4
  {
5
5
  l: "s",
6
6
  r: 44,
@@ -50,7 +50,8 @@ var e = [
50
50
  l: "yy",
51
51
  d: "year"
52
52
  }
53
- ], t = {
53
+ ];
54
+ var DEFAULT_FORMATS = {
54
55
  future: "in %s",
55
56
  past: "%s ago",
56
57
  s: "a few seconds",
@@ -64,44 +65,72 @@ var e = [
64
65
  MM: "%d months",
65
66
  y: "a year",
66
67
  yy: "%d years"
67
- }, n = class {
68
+ };
69
+ var RelativeTimePlugin = class {
68
70
  name = "relative-time";
69
71
  version = "1.0.0";
70
72
  config;
71
73
  formats;
72
- constructor(n) {
74
+ constructor(config) {
73
75
  this.config = {
74
- thresholds: n?.thresholds || e,
75
- rounding: n?.rounding || Math.round
76
- }, this.formats = t;
76
+ thresholds: config?.thresholds || DEFAULT_THRESHOLDS,
77
+ rounding: config?.rounding || Math.round
78
+ };
79
+ this.formats = DEFAULT_FORMATS;
77
80
  }
78
- install(e) {
79
- let t = this;
80
- e.prototype.fromNow = function(e) {
81
- return t.formatRelativeTime(this, !1, e);
82
- }, e.prototype.toNow = function(e) {
83
- return t.formatRelativeTime(this, !0, e);
84
- }, e.prototype.humanize = function(e, n) {
85
- return e ? t.formatRelativeTime(this, e.isAfter(this), n) : t.formatRelativeTime(this, !1, n);
81
+ /**
82
+ * Install plugin into TimeGuard
83
+ */
84
+ install(TimeGuardClass) {
85
+ const plugin = this;
86
+ /**
87
+ * Get relative time string (e.g., "2 hours ago")
88
+ */
89
+ TimeGuardClass.prototype.fromNow = function(withoutSuffix) {
90
+ return plugin.formatRelativeTime(this, false, withoutSuffix);
91
+ };
92
+ TimeGuardClass.prototype.toNow = function(withoutSuffix) {
93
+ return plugin.formatRelativeTime(this, true, withoutSuffix);
94
+ };
95
+ TimeGuardClass.prototype.humanize = function(other, withoutSuffix) {
96
+ if (other) return plugin.formatRelativeTime(this, other.isAfter(this), withoutSuffix);
97
+ return plugin.formatRelativeTime(this, false, withoutSuffix);
86
98
  };
87
99
  }
88
- formatRelativeTime(e, t, n) {
89
- let r = e.constructor.now().diff(e, "millisecond"), i = Math.abs(r), a = t ?? !(r > 0), o = this.getRelativeTimeString(i);
90
- return n ? o : (a ? this.formats.future : this.formats.past).replace("%s", o);
100
+ /**
101
+ * Format relative time
102
+ */
103
+ formatRelativeTime(date, isFuture, withoutSuffix) {
104
+ const diff = date.constructor.now().diff(date, "millisecond");
105
+ const absDiff = Math.abs(diff);
106
+ const actualIsFuture = isFuture ?? !(diff > 0);
107
+ const result = this.getRelativeTimeString(absDiff);
108
+ if (withoutSuffix) return result;
109
+ return (actualIsFuture ? this.formats.future : this.formats.past).replace("%s", result);
91
110
  }
92
- getRelativeTimeString(t) {
93
- let n = this.config.thresholds || e, r = this.config.rounding || Math.round;
94
- for (let e = 0; e < n.length; e++) {
95
- let i = n[e];
96
- if (e + 1 < n.length && n[e + 1] && i.r && t < i.r * 1e3) continue;
97
- let a;
98
- a = i.d ? r(t / this.getUnitMilliseconds(i.d)) : 1;
99
- let o = i.l, s = this.formats[o] || o;
100
- return typeof s == "string" && s.includes("%d") ? s.replace("%d", String(a)) : s;
111
+ /**
112
+ * Get relative time string based on milliseconds
113
+ */
114
+ getRelativeTimeString(milliseconds) {
115
+ const thresholds = this.config.thresholds || DEFAULT_THRESHOLDS;
116
+ const rounding = this.config.rounding || Math.round;
117
+ for (let i = 0; i < thresholds.length; i++) {
118
+ const threshold = thresholds[i];
119
+ if ((i + 1 < thresholds.length ? thresholds[i + 1] : null) && threshold.r && milliseconds < threshold.r * 1e3) continue;
120
+ let value;
121
+ if (threshold.d) value = rounding(milliseconds / this.getUnitMilliseconds(threshold.d));
122
+ else value = 1;
123
+ const label = threshold.l;
124
+ const format = this.formats[label] || label;
125
+ if (typeof format === "string") return format.includes("%d") ? format.replace("%d", String(value)) : format;
126
+ return format;
101
127
  }
102
- return `${r(t / 1e3)} seconds`;
128
+ return `${rounding(milliseconds / 1e3)} seconds`;
103
129
  }
104
- getUnitMilliseconds(e) {
130
+ /**
131
+ * Get milliseconds per unit
132
+ */
133
+ getUnitMilliseconds(unit) {
105
134
  return {
106
135
  second: 1e3,
107
136
  minute: 1e3 * 60,
@@ -109,16 +138,24 @@ var e = [
109
138
  day: 1e3 * 60 * 60 * 24,
110
139
  month: 1e3 * 60 * 60 * 24 * 30,
111
140
  year: 1e3 * 60 * 60 * 24 * 365
112
- }[e] || 1;
141
+ }[unit] || 1;
113
142
  }
114
- setFormats(e) {
115
- Object.assign(this.formats, e);
143
+ /**
144
+ * Set format strings
145
+ */
146
+ setFormats(formats) {
147
+ Object.assign(this.formats, formats);
116
148
  }
149
+ /**
150
+ * Get current formats
151
+ */
117
152
  getFormats() {
118
153
  return { ...this.formats };
119
154
  }
120
- }, r = new n();
155
+ };
156
+ /**
157
+ * Create and export default instance
158
+ */
159
+ var relative_time_default = new RelativeTimePlugin();
121
160
  //#endregion
122
- export { n as RelativeTimePlugin, r as default };
123
-
124
- //# sourceMappingURL=relative-time.es.js.map
161
+ export { RelativeTimePlugin, relative_time_default as default };