@bereasoftware/time-guard 2.5.1 → 2.5.2

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.
package/README.en.md CHANGED
@@ -894,8 +894,10 @@ console.log(formatUserDate(date, "ja")); // 水曜日、2024年3月13日 14:30
894
894
  #### Getting Available Locales Programmatically
895
895
 
896
896
  ```typescript
897
+ import { getAvailableLocales } from "@bereasoftware/time-guard";
898
+
897
899
  // Get all available locales
898
- const locales = TimeGuard.getAvailableLocales();
900
+ const locales = getAvailableLocales();
899
901
  // Returns: ['en', 'en-au', 'en-gb', 'en-ca', 'es', 'es-mx', 'es-us', ...]
900
902
 
901
903
  // Filter by prefix
@@ -907,7 +909,7 @@ const asianLocales = locales.filter((l) =>
907
909
 
908
910
  // Create locale selector UI
909
911
  function createLocaleSelector() {
910
- const locales = TimeGuard.getAvailableLocales();
912
+ const locales = getAvailableLocales();
911
913
  return locales.map((locale) => ({
912
914
  code: locale,
913
915
  label: new Intl.DisplayNames("en", { type: "language" }).of(locale),
@@ -1357,7 +1359,8 @@ inNYC.format("YYYY-MM-DD HH:mm:ss Z"); // 2024-03-13 10:30:00 -04:00
1357
1359
  inTokyo.format("YYYY-MM-DD HH:mm:ss Z"); // 2024-03-13 23:30:00 +09:00
1358
1360
 
1359
1361
  // Get all available locales
1360
- TimeGuard.getAvailableLocales(); // Array of 40+ locale codes
1362
+ import { getAvailableLocales } from "@bereasoftware/time-guard";
1363
+ getAvailableLocales(); // Array of 40+ locale codes
1361
1364
  ```
1362
1365
 
1363
1366
  ### 🎨 Format Patterns
package/README.md CHANGED
@@ -957,8 +957,10 @@ console.log(formatUserDate(date, 'ja')); // 水曜日、2024年3月13日 14:30
957
957
  #### Obtener Locales Disponibles Programáticamente
958
958
 
959
959
  ```typescript
960
+ import { getAvailableLocales } from "@bereasoftware/time-guard";
961
+
960
962
  // Get all available locales
961
- const locales = TimeGuard.getAvailableLocales();
963
+ const locales = getAvailableLocales();
962
964
  // Returns: ['en', 'en-au', 'en-gb', 'en-ca', 'es', 'es-mx', 'es-us', ...]
963
965
 
964
966
  // Filter by prefix
@@ -970,7 +972,7 @@ const asianLocales = locales.filter((l) =>
970
972
 
971
973
  // Create locale selector UI
972
974
  function createLocaleSelector() {
973
- const locales = TimeGuard.getAvailableLocales();
975
+ const locales = getAvailableLocales();
974
976
  return locales.map((locale) => ({
975
977
  code: locale,
976
978
  label: new Intl.DisplayNames('en', { type: 'language' }).of(locale),
@@ -1440,7 +1442,8 @@ inNYC.format('YYYY-MM-DD HH:mm:ss Z'); // 2024-03-13 10:30:00 -04:00
1440
1442
  inTokyo.format('YYYY-MM-DD HH:mm:ss Z'); // 2024-03-13 23:30:00 +09:00
1441
1443
 
1442
1444
  // Get all available locales
1443
- TimeGuard.getAvailableLocales(); // Array of 40+ locale codes
1445
+ import { getAvailableLocales } from "@bereasoftware/time-guard";
1446
+ getAvailableLocales(); // Array of 40+ locale codes
1444
1447
  ```
1445
1448
 
1446
1449
  ### 🎨 Format Patterns
@@ -1,4 +1,4 @@
1
- /*! time-guard v2.5.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.5.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
2
  //#region src/calendars/index.ts
3
3
  var e = class {
4
4
  id = "islamic";
@@ -1,2 +1,2 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=class{name=`advanced-format`;version=`1.0.0`;install(e){let t=e.prototype.format;e.prototype.format=function(e){if(!e||typeof e!=`string`||!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(e))return t.call(this,e);let n=this.toTemporal(),r=`toPlainDateTime`in n?n.toPlainDateTime():n,i=e=>{let t=[`th`,`st`,`nd`,`rd`],n=e%100;return e+(t[(n-20)%10]||t[n]||t[0])},a=(e,t)=>String(e).padStart(t,`0`),o=e=>{let t=new Date(e.year,0,4),n=new Date(t);n.setDate(t.getDate()-t.getDay()+(t.getDay()===0?-6:1));let r=new Date(e.year,e.month-1,e.day),i=Math.floor((r.getTime()-n.getTime())/(10080*60*1e3))+1;return Math.max(1,i)},s=e=>{let t=Math.ceil((e.day+new Date(e.year,e.month-1,1).getDay())/7);return Math.max(1,t)},c=e=>{let t=new Date(e.year,e.month-1,e.day),n=t.getTime()<new Date(e.year,0,1).getTime()?-1:+(t.getTime()>=new Date(e.year+1,0,1).getTime());return e.year+n},l=e=>{let t=e.month===1&&e.day<4?-1:+(e.month===12&&e.day>28);return e.year+t},u=e.replace(/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g,e=>{let t=``;switch(e){case`Q`:t=String(Math.ceil(r.month/3));break;case`Do`:t=i(r.day);break;case`W`:case`WW`:t=a(o(r),e===`W`?1:2);break;case`w`:case`ww`:t=a(s(r),e===`w`?1:2);break;case`GGGG`:t=String(c(r));break;case`gggg`:t=String(l(r));break;case`k`:case`kk`:t=a(r.hour===0?24:r.hour,e===`k`?1:2);break;case`X`:t=String(Math.floor(this.valueOf()/1e3));break;case`x`:t=String(this.valueOf());break;case`z`:t=`${this.getTimezoneOffset()}`;break;case`zzz`:t=`${this.getTimezoneOffsetLong()}`;break;default:return e}return`[${t}]`});return t.call(this,u)}}getOrdinal(e){let t=[`th`,`st`,`nd`,`rd`],n=e%100;return e+(t[(n-20)%10]||t[n]||t[0])}padNumber(e,t){return String(e).padStart(t,`0`)}getISOWeek(e){let t=new Date(e.year,0,4),n=new Date(t);n.setDate(t.getDate()-t.getDay()+(t.getDay()===0?-6:1));let r=new Date(e.year,e.month-1,e.day),i=Math.floor((r.getTime()-n.getTime())/(10080*60*1e3))+1;return Math.max(1,i)}getWeekOfYear(e){let t=Math.ceil((e.day+new Date(e.year,e.month-1,1).getDay())/7);return Math.max(1,t)}getISOWeekYear(e){let t=new Date(e.year,e.month-1,e.day),n=t.getTime()<new Date(e.year,0,1).getTime()?-1:+(t.getTime()>=new Date(e.year+1,0,1).getTime());return e.year+n}getWeekYear(e){let t=e.month===1&&e.day<4?-1:+(e.month===12&&e.day>28);return e.year+t}getTimezoneOffset(){try{let e=new Date;return new Intl.DateTimeFormat(`en-US`,{timeZone:`UTC`,timeZoneName:`short`}).formatToParts(e).find(e=>e.type===`timeZoneName`)?.value||`UTC`}catch{return`UTC`}}getTimezoneOffsetLong(){try{let e=new Date;return new Intl.DateTimeFormat(`en-US`,{timeZone:`UTC`,timeZoneName:`long`}).formatToParts(e).find(e=>e.type===`timeZoneName`)?.value||`Coordinated Universal Time`}catch{return`Coordinated Universal Time`}}},t=new e;exports.AdvancedFormatPlugin=e,exports.default=t;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=class{name=`advanced-format`;version=`1.0.0`;install(e){let t=e.prototype.format;e.prototype.format=function(e){if(!e||typeof e!=`string`||!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(e))return t.call(this,e);let n=this.toTemporal(),r=`toPlainDateTime`in n?n.toPlainDateTime():n,i=e=>{let t=[`th`,`st`,`nd`,`rd`],n=e%100;return e+(t[(n-20)%10]||t[n]||t[0])},a=(e,t)=>String(e).padStart(t,`0`),o=e=>{let t=new Date(e.year,0,4),n=new Date(t);n.setDate(t.getDate()-t.getDay()+(t.getDay()===0?-6:1));let r=new Date(e.year,e.month-1,e.day),i=Math.floor((r.getTime()-n.getTime())/(10080*60*1e3))+1;return Math.max(1,i)},s=e=>{let t=Math.ceil((e.day+new Date(e.year,e.month-1,1).getDay())/7);return Math.max(1,t)},c=e=>{let t=new Date(e.year,e.month-1,e.day),n=t.getTime()<new Date(e.year,0,1).getTime()?-1:+(t.getTime()>=new Date(e.year+1,0,1).getTime());return e.year+n},l=e=>{let t=e.month===1&&e.day<4?-1:+(e.month===12&&e.day>28);return e.year+t},u=e.replace(/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g,e=>{let t=``;switch(e){case`Q`:t=String(Math.ceil(r.month/3));break;case`Do`:t=i(r.day);break;case`W`:case`WW`:t=a(o(r),e===`W`?1:2);break;case`w`:case`ww`:t=a(s(r),e===`w`?1:2);break;case`GGGG`:t=String(c(r));break;case`gggg`:t=String(l(r));break;case`k`:case`kk`:t=a(r.hour===0?24:r.hour,e===`k`?1:2);break;case`X`:t=String(Math.floor(this.valueOf()/1e3));break;case`x`:t=String(this.valueOf());break;case`z`:t=`${this.getTimezoneOffset()}`;break;case`zzz`:t=`${this.getTimezoneOffsetLong()}`;break;default:return e}return`[${t}]`});return t.call(this,u)}}},t=new e;exports.AdvancedFormatPlugin=e,exports.default=t;
2
2
  //# sourceMappingURL=advanced-format.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"advanced-format.cjs","names":[],"sources":["../../src/plugins/advanced-format/index.ts"],"sourcesContent":["/**\r\n * TimeGuard Advanced Format Plugin\r\n * Adds advanced format tokens: Q (quarter), Do (ordinal), w (week), etc.\r\n * Follows SOLID principles and extends core formatting capabilities\r\n */\r\n\r\nimport type { ITimeGuardPlugin } from '../../types';\r\nimport type { TimeGuard } from '../../time-guard';\r\nimport type { Temporal } from '@js-temporal/polyfill';\r\n\r\nexport class AdvancedFormatPlugin implements ITimeGuardPlugin {\r\n name = 'advanced-format';\r\n version = '1.0.0';\r\n\r\n /**\r\n * Install plugin into TimeGuard\r\n */\r\n install(TimeGuardClass: typeof TimeGuard): void {\r\n // Store original format method\r\n const originalFormat = TimeGuardClass.prototype.format;\r\n\r\n /**\r\n * Extended format method with advanced tokens\r\n */\r\n (TimeGuardClass.prototype as any).format = function (pattern: string) {\r\n if (!pattern || typeof pattern !== 'string') {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Check if pattern contains advanced tokens\r\n if (!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(pattern)) {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Get the underlying Temporal object\r\n const temporal = this.toTemporal();\r\n const temporal_dt =\r\n 'toPlainDateTime' in temporal\r\n ? (temporal as any).toPlainDateTime()\r\n : (temporal as Temporal.PlainDateTime);\r\n \r\n const ordinalFn = (n: number) => {\r\n const suffixes = ['th', 'st', 'nd', 'rd'];\r\n const v = n % 100;\r\n return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);\r\n };\r\n const padFn = (n: number, length: number) => String(n).padStart(length, '0');\r\n const getISOWeek = (temporal: any) => {\r\n const jan4 = new Date(temporal.year, 0, 4);\r\n const week1Start = new Date(jan4);\r\n week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const weekNum = Math.floor((currentDate.getTime() - week1Start.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;\r\n return Math.max(1, weekNum);\r\n };\r\n const getWeekOfYear = (temporal: any) => {\r\n const weekNum = Math.ceil(((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7));\r\n return Math.max(1, weekNum);\r\n };\r\n const getISOWeekYear = (temporal: any) => {\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const yearAdjust = currentDate.getTime() < new Date(temporal.year, 0, 1).getTime() ? -1 : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime() ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n const getWeekYear = (temporal: any) => {\r\n const yearAdjust = temporal.month === 1 && temporal.day < 4 ? -1 : temporal.month === 12 && temporal.day > 28 ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n\r\n // Replace advanced tokens - wrap results in brackets to protect from standard formatter\r\n let result = pattern.replace(\r\n /Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g,\r\n (match) => {\r\n let replacement = '';\r\n switch (match) {\r\n // Quarter\r\n case 'Q':\r\n replacement = String(Math.ceil((temporal_dt.month) / 3));\r\n break;\r\n\r\n // Ordinal day\r\n case 'Do':\r\n replacement = ordinalFn(temporal_dt.day);\r\n break;\r\n\r\n // Week of year (ISO)\r\n case 'W':\r\n case 'WW':\r\n replacement = padFn(getISOWeek(temporal_dt), match === 'W' ? 1 : 2);\r\n break;\r\n\r\n // Week of year (locale)\r\n case 'w':\r\n case 'ww':\r\n replacement = padFn(getWeekOfYear(temporal_dt), match === 'w' ? 1 : 2);\r\n break;\r\n\r\n // ISO week year\r\n case 'GGGG':\r\n replacement = String(getISOWeekYear(temporal_dt));\r\n break;\r\n\r\n // Week year\r\n case 'gggg':\r\n replacement = String(getWeekYear(temporal_dt));\r\n break;\r\n\r\n // Hour (1-24)\r\n case 'k':\r\n case 'kk':\r\n const hour = temporal_dt.hour === 0 ? 24 : temporal_dt.hour;\r\n replacement = padFn(hour, match === 'k' ? 1 : 2);\r\n break;\r\n\r\n // Unix seconds timestamp\r\n case 'X':\r\n replacement = String(Math.floor(this.valueOf() / 1000));\r\n break;\r\n\r\n // Unix milliseconds timestamp\r\n case 'x':\r\n replacement = String(this.valueOf());\r\n break;\r\n\r\n // Timezone offset\r\n case 'z':\r\n replacement = `${this.getTimezoneOffset()}`;\r\n break;\r\n\r\n case 'zzz':\r\n replacement = `${this.getTimezoneOffsetLong()}`;\r\n break;\r\n\r\n default:\r\n return match;\r\n }\r\n // Wrap in brackets to protect from standard formatter\r\n return `[${replacement}]`;\r\n },\r\n );\r\n\r\n // Apply standard format to the result\r\n return originalFormat.call(this, result);\r\n };\r\n }\r\n\r\n /**\r\n * Get ordinal suffix (1st, 2nd, 3rd, etc.)\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getOrdinal(n: number): string {\r\n const suffixes = ['th', 'st', 'nd', 'rd'];\r\n const v = n % 100;\r\n return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);\r\n }\r\n\r\n /**\r\n * Pad number with leading zeros\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private padNumber(n: number, length: number): string {\r\n return String(n).padStart(length, '0');\r\n }\r\n\r\n /**\r\n * Get ISO week number\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getISOWeek(temporal: Temporal.PlainDateTime): number {\r\n // Simple ISO week calculation\r\n const jan4 = new Date(temporal.year, 0, 4);\r\n const week1Start = new Date(jan4);\r\n week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));\r\n\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const weekNum = Math.floor(\r\n (currentDate.getTime() - week1Start.getTime()) / (7 * 24 * 60 * 60 * 1000),\r\n ) + 1;\r\n\r\n return Math.max(1, weekNum);\r\n }\r\n\r\n /**\r\n * Get week of year (locale-based)\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getWeekOfYear(temporal: Temporal.PlainDateTime): number {\r\n const weekNum = Math.ceil(\r\n ((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7),\r\n );\r\n return Math.max(1, weekNum);\r\n }\r\n\r\n /**\r\n * Get ISO week year\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getISOWeekYear(temporal: Temporal.PlainDateTime): number {\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const yearAdjust =\r\n currentDate.getTime() < new Date(temporal.year, 0, 1).getTime()\r\n ? -1\r\n : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime()\r\n ? 1\r\n : 0;\r\n\r\n return temporal.year + yearAdjust;\r\n }\r\n\r\n /**\r\n * Get week year\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getWeekYear(temporal: Temporal.PlainDateTime): number {\r\n const yearAdjust =\r\n temporal.month === 1 && temporal.day < 4\r\n ? -1\r\n : temporal.month === 12 && temporal.day > 28\r\n ? 1\r\n : 0;\r\n return temporal.year + yearAdjust;\r\n }\r\n\r\n /**\r\n * Get timezone offset short form\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getTimezoneOffset(): string {\r\n try {\r\n const now = new Date();\r\n const formatter = new Intl.DateTimeFormat('en-US', {\r\n timeZone: 'UTC',\r\n timeZoneName: 'short',\r\n });\r\n return formatter.formatToParts(now).find(p => p.type === 'timeZoneName')?.value || 'UTC';\r\n } catch {\r\n return 'UTC';\r\n }\r\n }\r\n\r\n /**\r\n * Get timezone offset long form\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getTimezoneOffsetLong(): string {\r\n try {\r\n const now = new Date();\r\n const formatter = new Intl.DateTimeFormat('en-US', {\r\n timeZone: 'UTC',\r\n timeZoneName: 'long',\r\n });\r\n return formatter.formatToParts(now).find(p => p.type === 'timeZoneName')?.value || 'Coordinated Universal Time';\r\n } catch {\r\n return 'Coordinated Universal Time';\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Create and export default instance\r\n */\r\nexport default new AdvancedFormatPlugin();\r\n"],"mappings":"+FAUA,IAAa,EAAb,KAA8D,CAC5D,KAAO,kBACP,QAAU,QAKV,QAAQ,EAAwC,CAE9C,IAAM,EAAiB,EAAe,UAAU,OAK/C,EAAe,UAAkB,OAAS,SAAU,EAAiB,CAMpE,GALI,CAAC,GAAW,OAAO,GAAY,UAK/B,CAAC,qCAAqC,KAAK,EAAQ,CACrD,OAAO,EAAe,KAAK,KAAM,EAAQ,CAI3C,IAAM,EAAW,KAAK,YAAY,CAC5B,EACJ,oBAAqB,EAChB,EAAiB,iBAAiB,CAClC,EAED,EAAa,GAAc,CAC/B,IAAM,EAAW,CAAC,KAAM,KAAM,KAAM,KAAK,CACnC,EAAI,EAAI,IACd,OAAO,GAAK,GAAU,EAAI,IAAM,KAAO,EAAS,IAAM,EAAS,KAE3D,GAAS,EAAW,IAAmB,OAAO,EAAE,CAAC,SAAS,EAAQ,IAAI,CACtE,EAAc,GAAkB,CACpC,IAAM,EAAO,IAAI,KAAK,EAAS,KAAM,EAAG,EAAE,CACpC,EAAa,IAAI,KAAK,EAAK,CACjC,EAAW,QAAQ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AAS,KAAM,EAAS,MAAQ,EAAG,EAAE,CAAC,QAAQ,EAAI,EAC7E,CACD,OAAO,KAAK,IAAI,EAAG,EAAQ,CAO7B,eAAuB,EAA0C,CAC/D,IAAM,EAAc,IAAI,KAAK,EAAS,KAAM,EAAS,MAAQ,EAAG,EAAS,IAAI,CACvE,EACJ,EAAY,SAAS,CAAG,IAAI,KAAK,EAAS,KAAM,EAAG,EAAE,CAAC,SAAS,CAC3D,GACA,IAAY,SAAS,EAAI,IAAI,KAAK,EAAS,KAAO,EAAG,EAAG,EAAE,CAAC,SAAS,EAI1E,OAAO,EAAS,KAAO,EAOzB,YAAoB,EAA0C,CAC5D,IAAM,EACJ,EAAS,QAAU,GAAK,EAAS,IAAM,EACnC,GACA,IAAS,QAAU,IAAM,EAAS,IAAM,IAG9C,OAAO,EAAS,KAAO,EAOzB,mBAAoC,CAClC,GAAI,CACF,IAAM,EAAM,IAAI,KAKhB,OAJkB,IAAI,KAAK,eAAe,QAAS,CACjD,SAAU,MACV,aAAc,QACf,CAAC,CACe,cAAc,EAAI,CAAC,KAAK,GAAK,EAAE,OAAS,eAAe,EAAE,OAAS,WAC7E,CACN,MAAO,OAQX,uBAAwC,CACtC,GAAI,CACF,IAAM,EAAM,IAAI,KAKhB,OAJkB,IAAI,KAAK,eAAe,QAAS,CACjD,SAAU,MACV,aAAc,OACf,CAAC,CACe,cAAc,EAAI,CAAC,KAAK,GAAK,EAAE,OAAS,eAAe,EAAE,OAAS,kCAC7E,CACN,MAAO,gCAQb,EAAe,IAAI"}
1
+ {"version":3,"file":"advanced-format.cjs","names":[],"sources":["../../src/plugins/advanced-format/index.ts"],"sourcesContent":["/**\r\n * TimeGuard Advanced Format Plugin\r\n * Adds advanced format tokens: Q (quarter), Do (ordinal), w (week), etc.\r\n * Follows SOLID principles and extends core formatting capabilities\r\n */\r\n\r\nimport type { ITimeGuardPlugin } from '../../types';\r\nimport type { TimeGuard } from '../../time-guard';\r\nimport { Temporal } from '@js-temporal/polyfill';\r\n\r\nexport class AdvancedFormatPlugin implements ITimeGuardPlugin {\r\n name = 'advanced-format';\r\n version = '1.0.0';\r\n\r\n /**\r\n * Install plugin into TimeGuard\r\n */\r\n install(TimeGuardClass: typeof TimeGuard): void {\r\n // Store original format method\r\n const originalFormat = TimeGuardClass.prototype.format;\r\n\r\n /**\r\n * Extended format method with advanced tokens\r\n */\r\n (TimeGuardClass.prototype as any).format = function (pattern: string) {\r\n if (!pattern || typeof pattern !== 'string') {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Check if pattern contains advanced tokens\r\n if (!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(pattern)) {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Get the underlying Temporal object\r\n const temporal = this.toTemporal();\r\n const temporal_dt =\r\n 'toPlainDateTime' in temporal\r\n ? (temporal as any).toPlainDateTime()\r\n : (temporal as Temporal.PlainDateTime);\r\n \r\n const ordinalFn = (n: number) => {\r\n const suffixes = ['th', 'st', 'nd', 'rd'];\r\n const v = n % 100;\r\n return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);\r\n };\r\n const padFn = (n: number, length: number) => String(n).padStart(length, '0');\r\n const getISOWeek = (temporal: any) => {\r\n const jan4 = new Date(temporal.year, 0, 4);\r\n const week1Start = new Date(jan4);\r\n week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const weekNum = Math.floor((currentDate.getTime() - week1Start.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;\r\n return Math.max(1, weekNum);\r\n };\r\n const getWeekOfYear = (temporal: any) => {\r\n const weekNum = Math.ceil(((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7));\r\n return Math.max(1, weekNum);\r\n };\r\n const getISOWeekYear = (temporal: any) => {\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const yearAdjust = currentDate.getTime() < new Date(temporal.year, 0, 1).getTime() ? -1 : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime() ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n const getWeekYear = (temporal: any) => {\r\n const yearAdjust = temporal.month === 1 && temporal.day < 4 ? -1 : temporal.month === 12 && temporal.day > 28 ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n\r\n // Replace advanced tokens - wrap results in brackets to protect from standard formatter\r\n let result = pattern.replace(\r\n /Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g,\r\n (match) => {\r\n let replacement = '';\r\n switch (match) {\r\n // Quarter\r\n case 'Q':\r\n replacement = String(Math.ceil((temporal_dt.month) / 3));\r\n break;\r\n\r\n // Ordinal day\r\n case 'Do':\r\n replacement = ordinalFn(temporal_dt.day);\r\n break;\r\n\r\n // Week of year (ISO)\r\n case 'W':\r\n case 'WW':\r\n replacement = padFn(getISOWeek(temporal_dt), match === 'W' ? 1 : 2);\r\n break;\r\n\r\n // Week of year (locale)\r\n case 'w':\r\n case 'ww':\r\n replacement = padFn(getWeekOfYear(temporal_dt), match === 'w' ? 1 : 2);\r\n break;\r\n\r\n // ISO week year\r\n case 'GGGG':\r\n replacement = String(getISOWeekYear(temporal_dt));\r\n break;\r\n\r\n // Week year\r\n case 'gggg':\r\n replacement = String(getWeekYear(temporal_dt));\r\n break;\r\n\r\n // Hour (1-24)\r\n case 'k':\r\n case 'kk':\r\n const hour = temporal_dt.hour === 0 ? 24 : temporal_dt.hour;\r\n replacement = padFn(hour, match === 'k' ? 1 : 2);\r\n break;\r\n\r\n // Unix seconds timestamp\r\n case 'X':\r\n replacement = String(Math.floor(this.valueOf() / 1000));\r\n break;\r\n\r\n // Unix milliseconds timestamp\r\n case 'x':\r\n replacement = String(this.valueOf());\r\n break;\r\n\r\n // Timezone offset\r\n case 'z':\r\n replacement = `${this.getTimezoneOffset()}`;\r\n break;\r\n\r\n case 'zzz':\r\n replacement = `${this.getTimezoneOffsetLong()}`;\r\n break;\r\n\r\n default:\r\n return match;\r\n }\r\n // Wrap in brackets to protect from standard formatter\r\n return `[${replacement}]`;\r\n },\r\n );\r\n\r\n // Apply standard format to the result\r\n return originalFormat.call(this, result);\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Create and export default instance\r\n */\r\nexport default new AdvancedFormatPlugin();\r\n"],"mappings":"+FAUA,IAAa,EAAb,KAA8D,CAC5D,KAAO,kBACP,QAAU,QAKV,QAAQ,EAAwC,CAE9C,IAAM,EAAiB,EAAe,UAAU,OAK/C,EAAe,UAAkB,OAAS,SAAU,EAAiB,CAMpE,GALI,CAAC,GAAW,OAAO,GAAY,UAK/B,CAAC,qCAAqC,KAAK,EAAQ,CACrD,OAAO,EAAe,KAAK,KAAM,EAAQ,CAI3C,IAAM,EAAW,KAAK,YAAY,CAC5B,EACJ,oBAAqB,EAChB,EAAiB,iBAAiB,CAClC,EAED,EAAa,GAAc,CAC/B,IAAM,EAAW,CAAC,KAAM,KAAM,KAAM,KAAK,CACnC,EAAI,EAAI,IACd,OAAO,GAAK,GAAU,EAAI,IAAM,KAAO,EAAS,IAAM,EAAS,KAE3D,GAAS,EAAW,IAAmB,OAAO,EAAE,CAAC,SAAS,EAAQ,IAAI,CACtE,EAAc,GAAkB,CACpC,IAAM,EAAO,IAAI,KAAK,EAAS,KAAM,EAAG,EAAE,CACpC,EAAa,IAAI,KAAK,EAAK,CACjC,EAAW,QAAQ,EAAK,SAAS,CAAG,EAAK,QAAQ,EAAI,EAAK,QAAQ,GAAK,EAAI,GAAK,GAAG,CACnF,IAAM,EAAc,IAAI,KAAK,EAAS,KAAM,EAAS,MAAQ,EAAG,EAAS,IAAI,CACvE,EAAU,KAAK,OAAO,EAAY,SAAS,CAAG,EAAW,SAAS,GAAK,MAAc,GAAK,KAAM,CAAG,EACzG,OAAO,KAAK,IAAI,EAAG,EAAQ,EAEvB,EAAiB,GAAkB,CACvC,IAAM,EAAU,KAA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,OAAO,KAAK,SAAS,CAAC,CACpC,MAGF,IAAK,IACH,EAAc,GAAG,KAAK,mBAAmB,GACzC,MAEF,IAAK,MACH,EAAc,GAAG,KAAK,uBAAuB,GAC7C,MAEF,QACE,OAAO,EAGX,MAAO,IAAI,EAAY,IAE1B,CAGD,OAAO,EAAe,KAAK,KAAM,EAAO,IAQ9C,EAAe,IAAI"}
@@ -1,4 +1,4 @@
1
- /*! time-guard v2.5.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.5.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
2
  //#region src/plugins/advanced-format/index.ts
3
3
  var e = class {
4
4
  name = "advanced-format";
@@ -75,58 +75,6 @@ var e = class {
75
75
  return t.call(this, u);
76
76
  };
77
77
  }
78
- getOrdinal(e) {
79
- let t = [
80
- "th",
81
- "st",
82
- "nd",
83
- "rd"
84
- ], n = e % 100;
85
- return e + (t[(n - 20) % 10] || t[n] || t[0]);
86
- }
87
- padNumber(e, t) {
88
- return String(e).padStart(t, "0");
89
- }
90
- getISOWeek(e) {
91
- let t = new Date(e.year, 0, 4), n = new Date(t);
92
- n.setDate(t.getDate() - t.getDay() + (t.getDay() === 0 ? -6 : 1));
93
- let r = new Date(e.year, e.month - 1, e.day), i = Math.floor((r.getTime() - n.getTime()) / (10080 * 60 * 1e3)) + 1;
94
- return Math.max(1, i);
95
- }
96
- getWeekOfYear(e) {
97
- let t = Math.ceil((e.day + new Date(e.year, e.month - 1, 1).getDay()) / 7);
98
- return Math.max(1, t);
99
- }
100
- getISOWeekYear(e) {
101
- let t = new Date(e.year, e.month - 1, e.day), n = t.getTime() < new Date(e.year, 0, 1).getTime() ? -1 : +(t.getTime() >= new Date(e.year + 1, 0, 1).getTime());
102
- return e.year + n;
103
- }
104
- getWeekYear(e) {
105
- let t = e.month === 1 && e.day < 4 ? -1 : +(e.month === 12 && e.day > 28);
106
- return e.year + t;
107
- }
108
- getTimezoneOffset() {
109
- try {
110
- let e = /* @__PURE__ */ new Date();
111
- return new Intl.DateTimeFormat("en-US", {
112
- timeZone: "UTC",
113
- timeZoneName: "short"
114
- }).formatToParts(e).find((e) => e.type === "timeZoneName")?.value || "UTC";
115
- } catch {
116
- return "UTC";
117
- }
118
- }
119
- getTimezoneOffsetLong() {
120
- try {
121
- let e = /* @__PURE__ */ new Date();
122
- return new Intl.DateTimeFormat("en-US", {
123
- timeZone: "UTC",
124
- timeZoneName: "long"
125
- }).formatToParts(e).find((e) => e.type === "timeZoneName")?.value || "Coordinated Universal Time";
126
- } catch {
127
- return "Coordinated Universal Time";
128
- }
129
- }
130
78
  }, t = new e();
131
79
  //#endregion
132
80
  export { e as AdvancedFormatPlugin, t as default };
@@ -1 +1 @@
1
- {"version":3,"file":"advanced-format.es.js","names":[],"sources":["../../src/plugins/advanced-format/index.ts"],"sourcesContent":["/**\r\n * TimeGuard Advanced Format Plugin\r\n * Adds advanced format tokens: Q (quarter), Do (ordinal), w (week), etc.\r\n * Follows SOLID principles and extends core formatting capabilities\r\n */\r\n\r\nimport type { ITimeGuardPlugin } from '../../types';\r\nimport type { TimeGuard } from '../../time-guard';\r\nimport type { Temporal } from '@js-temporal/polyfill';\r\n\r\nexport class AdvancedFormatPlugin implements ITimeGuardPlugin {\r\n name = 'advanced-format';\r\n version = '1.0.0';\r\n\r\n /**\r\n * Install plugin into TimeGuard\r\n */\r\n install(TimeGuardClass: typeof TimeGuard): void {\r\n // Store original format method\r\n const originalFormat = TimeGuardClass.prototype.format;\r\n\r\n /**\r\n * Extended format method with advanced tokens\r\n */\r\n (TimeGuardClass.prototype as any).format = function (pattern: string) {\r\n if (!pattern || typeof pattern !== 'string') {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Check if pattern contains advanced tokens\r\n if (!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(pattern)) {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Get the underlying Temporal object\r\n const temporal = this.toTemporal();\r\n const temporal_dt =\r\n 'toPlainDateTime' in temporal\r\n ? (temporal as any).toPlainDateTime()\r\n : (temporal as Temporal.PlainDateTime);\r\n \r\n const ordinalFn = (n: number) => {\r\n const suffixes = ['th', 'st', 'nd', 'rd'];\r\n const v = n % 100;\r\n return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);\r\n };\r\n const padFn = (n: number, length: number) => String(n).padStart(length, '0');\r\n const getISOWeek = (temporal: any) => {\r\n const jan4 = new Date(temporal.year, 0, 4);\r\n const week1Start = new Date(jan4);\r\n week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const weekNum = Math.floor((currentDate.getTime() - week1Start.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;\r\n return Math.max(1, weekNum);\r\n };\r\n const getWeekOfYear = (temporal: any) => {\r\n const weekNum = Math.ceil(((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7));\r\n return Math.max(1, weekNum);\r\n };\r\n const getISOWeekYear = (temporal: any) => {\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const yearAdjust = currentDate.getTime() < new Date(temporal.year, 0, 1).getTime() ? -1 : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime() ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n const getWeekYear = (temporal: any) => {\r\n const yearAdjust = temporal.month === 1 && temporal.day < 4 ? -1 : temporal.month === 12 && temporal.day > 28 ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n\r\n // Replace advanced tokens - wrap results in brackets to protect from standard formatter\r\n let result = pattern.replace(\r\n /Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g,\r\n (match) => {\r\n let replacement = '';\r\n switch (match) {\r\n // Quarter\r\n case 'Q':\r\n replacement = String(Math.ceil((temporal_dt.month) / 3));\r\n break;\r\n\r\n // Ordinal day\r\n case 'Do':\r\n replacement = ordinalFn(temporal_dt.day);\r\n break;\r\n\r\n // Week of year (ISO)\r\n case 'W':\r\n case 'WW':\r\n replacement = padFn(getISOWeek(temporal_dt), match === 'W' ? 1 : 2);\r\n break;\r\n\r\n // Week of year (locale)\r\n case 'w':\r\n case 'ww':\r\n replacement = padFn(getWeekOfYear(temporal_dt), match === 'w' ? 1 : 2);\r\n break;\r\n\r\n // ISO week year\r\n case 'GGGG':\r\n replacement = String(getISOWeekYear(temporal_dt));\r\n break;\r\n\r\n // Week year\r\n case 'gggg':\r\n replacement = String(getWeekYear(temporal_dt));\r\n break;\r\n\r\n // Hour (1-24)\r\n case 'k':\r\n case 'kk':\r\n const hour = temporal_dt.hour === 0 ? 24 : temporal_dt.hour;\r\n replacement = padFn(hour, match === 'k' ? 1 : 2);\r\n break;\r\n\r\n // Unix seconds timestamp\r\n case 'X':\r\n replacement = String(Math.floor(this.valueOf() / 1000));\r\n break;\r\n\r\n // Unix milliseconds timestamp\r\n case 'x':\r\n replacement = String(this.valueOf());\r\n break;\r\n\r\n // Timezone offset\r\n case 'z':\r\n replacement = `${this.getTimezoneOffset()}`;\r\n break;\r\n\r\n case 'zzz':\r\n replacement = `${this.getTimezoneOffsetLong()}`;\r\n break;\r\n\r\n default:\r\n return match;\r\n }\r\n // Wrap in brackets to protect from standard formatter\r\n return `[${replacement}]`;\r\n },\r\n );\r\n\r\n // Apply standard format to the result\r\n return originalFormat.call(this, result);\r\n };\r\n }\r\n\r\n /**\r\n * Get ordinal suffix (1st, 2nd, 3rd, etc.)\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getOrdinal(n: number): string {\r\n const suffixes = ['th', 'st', 'nd', 'rd'];\r\n const v = n % 100;\r\n return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);\r\n }\r\n\r\n /**\r\n * Pad number with leading zeros\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private padNumber(n: number, length: number): string {\r\n return String(n).padStart(length, '0');\r\n }\r\n\r\n /**\r\n * Get ISO week number\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getISOWeek(temporal: Temporal.PlainDateTime): number {\r\n // Simple ISO week calculation\r\n const jan4 = new Date(temporal.year, 0, 4);\r\n const week1Start = new Date(jan4);\r\n week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));\r\n\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const weekNum = Math.floor(\r\n (currentDate.getTime() - week1Start.getTime()) / (7 * 24 * 60 * 60 * 1000),\r\n ) + 1;\r\n\r\n return Math.max(1, weekNum);\r\n }\r\n\r\n /**\r\n * Get week of year (locale-based)\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getWeekOfYear(temporal: Temporal.PlainDateTime): number {\r\n const weekNum = Math.ceil(\r\n ((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7),\r\n );\r\n return Math.max(1, weekNum);\r\n }\r\n\r\n /**\r\n * Get ISO week year\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getISOWeekYear(temporal: Temporal.PlainDateTime): number {\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const yearAdjust =\r\n currentDate.getTime() < new Date(temporal.year, 0, 1).getTime()\r\n ? -1\r\n : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime()\r\n ? 1\r\n : 0;\r\n\r\n return temporal.year + yearAdjust;\r\n }\r\n\r\n /**\r\n * Get week year\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getWeekYear(temporal: Temporal.PlainDateTime): number {\r\n const yearAdjust =\r\n temporal.month === 1 && temporal.day < 4\r\n ? -1\r\n : temporal.month === 12 && temporal.day > 28\r\n ? 1\r\n : 0;\r\n return temporal.year + yearAdjust;\r\n }\r\n\r\n /**\r\n * Get timezone offset short form\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getTimezoneOffset(): string {\r\n try {\r\n const now = new Date();\r\n const formatter = new Intl.DateTimeFormat('en-US', {\r\n timeZone: 'UTC',\r\n timeZoneName: 'short',\r\n });\r\n return formatter.formatToParts(now).find(p => p.type === 'timeZoneName')?.value || 'UTC';\r\n } catch {\r\n return 'UTC';\r\n }\r\n }\r\n\r\n /**\r\n * Get timezone offset long form\r\n */\r\n // @ts-expect-error - Method called dynamically within replace callback\r\n private getTimezoneOffsetLong(): string {\r\n try {\r\n const now = new Date();\r\n const formatter = new Intl.DateTimeFormat('en-US', {\r\n timeZone: 'UTC',\r\n timeZoneName: 'long',\r\n });\r\n return formatter.formatToParts(now).find(p => p.type === 'timeZoneName')?.value || 'Coordinated Universal Time';\r\n } catch {\r\n return 'Coordinated Universal Time';\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Create and export default instance\r\n */\r\nexport default new AdvancedFormatPlugin();\r\n"],"mappings":";;AAUA,IAAa,IAAb,MAA8D;CAC5D,OAAO;CACP,UAAU;CAKV,QAAQ,GAAwC;EAE9C,IAAM,IAAiB,EAAe,UAAU;AAK/C,IAAe,UAAkB,SAAS,SAAU,GAAiB;AAMpE,OALI,CAAC,KAAW,OAAO,KAAY,YAK/B,CAAC,qCAAqC,KAAK,EAAQ,CACrD,QAAO,EAAe,KAAK,MAAM,EAAQ;GAI3C,IAAM,IAAW,KAAK,YAAY,EAC5B,IACJ,qBAAqB,IAChB,EAAiB,iBAAiB,GAClC,GAED,KAAa,MAAc;IAC/B,IAAM,IAAW;KAAC;KAAM;KAAM;KAAM;KAAK,EACnC,IAAI,IAAI;AACd,WAAO,KAAK,GAAU,IAAI,MAAM,OAAO,EAAS,MAAM,EAAS;MAE3D,KAAS,GAAW,MAAmB,OAAO,EAAE,CAAC,SAAS,GAAQ,IAAI,EACtE,KAAc,MAAkB;IACpC,IAAM,IAAO,IAAI,KAAK,EAAS,MAAM,GAAG,EAAE,EACpC,IAAa,IAAI,KA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K,MACjB,EAAS,MAAM,IAAI,KAAK,EAAS,MAAM,EAAS,QAAQ,GAAG,EAAE,CAAC,QAAQ,IAAI,EAC7E;AACD,SAAO,KAAK,IAAI,GAAG,EAAQ;;CAO7B,eAAuB,GAA0C;EAC/D,IAAM,IAAc,IAAI,KAAK,EAAS,MAAM,EAAS,QAAQ,GAAG,EAAS,IAAI,EACvE,IACJ,EAAY,SAAS,GAAG,IAAI,KAAK,EAAS,MAAM,GAAG,EAAE,CAAC,SAAS,GAC3D,KACA,IAAY,SAAS,IAAI,IAAI,KAAK,EAAS,OAAO,GAAG,GAAG,EAAE,CAAC,SAAS;AAI1E,SAAO,EAAS,OAAO;;CAOzB,YAAoB,GAA0C;EAC5D,IAAM,IACJ,EAAS,UAAU,KAAK,EAAS,MAAM,IACnC,KACA,IAAS,UAAU,MAAM,EAAS,MAAM;AAG9C,SAAO,EAAS,OAAO;;CAOzB,oBAAoC;AAClC,MAAI;GACF,IAAM,oBAAM,IAAI,MAAM;AAKtB,UAJkB,IAAI,KAAK,eAAe,SAAS;IACjD,UAAU;IACV,cAAc;IACf,CAAC,CACe,cAAc,EAAI,CAAC,MAAK,MAAK,EAAE,SAAS,eAAe,EAAE,SAAS;UAC7E;AACN,UAAO;;;CAQX,wBAAwC;AACtC,MAAI;GACF,IAAM,oBAAM,IAAI,MAAM;AAKtB,UAJkB,IAAI,KAAK,eAAe,SAAS;IACjD,UAAU;IACV,cAAc;IACf,CAAC,CACe,cAAc,EAAI,CAAC,MAAK,MAAK,EAAE,SAAS,eAAe,EAAE,SAAS;UAC7E;AACN,UAAO;;;GAQb,IAAe,IAAI,GAAsB"}
1
+ {"version":3,"file":"advanced-format.es.js","names":[],"sources":["../../src/plugins/advanced-format/index.ts"],"sourcesContent":["/**\r\n * TimeGuard Advanced Format Plugin\r\n * Adds advanced format tokens: Q (quarter), Do (ordinal), w (week), etc.\r\n * Follows SOLID principles and extends core formatting capabilities\r\n */\r\n\r\nimport type { ITimeGuardPlugin } from '../../types';\r\nimport type { TimeGuard } from '../../time-guard';\r\nimport { Temporal } from '@js-temporal/polyfill';\r\n\r\nexport class AdvancedFormatPlugin implements ITimeGuardPlugin {\r\n name = 'advanced-format';\r\n version = '1.0.0';\r\n\r\n /**\r\n * Install plugin into TimeGuard\r\n */\r\n install(TimeGuardClass: typeof TimeGuard): void {\r\n // Store original format method\r\n const originalFormat = TimeGuardClass.prototype.format;\r\n\r\n /**\r\n * Extended format method with advanced tokens\r\n */\r\n (TimeGuardClass.prototype as any).format = function (pattern: string) {\r\n if (!pattern || typeof pattern !== 'string') {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Check if pattern contains advanced tokens\r\n if (!/Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/.test(pattern)) {\r\n return originalFormat.call(this, pattern);\r\n }\r\n\r\n // Get the underlying Temporal object\r\n const temporal = this.toTemporal();\r\n const temporal_dt =\r\n 'toPlainDateTime' in temporal\r\n ? (temporal as any).toPlainDateTime()\r\n : (temporal as Temporal.PlainDateTime);\r\n \r\n const ordinalFn = (n: number) => {\r\n const suffixes = ['th', 'st', 'nd', 'rd'];\r\n const v = n % 100;\r\n return n + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);\r\n };\r\n const padFn = (n: number, length: number) => String(n).padStart(length, '0');\r\n const getISOWeek = (temporal: any) => {\r\n const jan4 = new Date(temporal.year, 0, 4);\r\n const week1Start = new Date(jan4);\r\n week1Start.setDate(jan4.getDate() - jan4.getDay() + (jan4.getDay() === 0 ? -6 : 1));\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const weekNum = Math.floor((currentDate.getTime() - week1Start.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1;\r\n return Math.max(1, weekNum);\r\n };\r\n const getWeekOfYear = (temporal: any) => {\r\n const weekNum = Math.ceil(((temporal.day + new Date(temporal.year, temporal.month - 1, 1).getDay()) / 7));\r\n return Math.max(1, weekNum);\r\n };\r\n const getISOWeekYear = (temporal: any) => {\r\n const currentDate = new Date(temporal.year, temporal.month - 1, temporal.day);\r\n const yearAdjust = currentDate.getTime() < new Date(temporal.year, 0, 1).getTime() ? -1 : currentDate.getTime() >= new Date(temporal.year + 1, 0, 1).getTime() ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n const getWeekYear = (temporal: any) => {\r\n const yearAdjust = temporal.month === 1 && temporal.day < 4 ? -1 : temporal.month === 12 && temporal.day > 28 ? 1 : 0;\r\n return temporal.year + yearAdjust;\r\n };\r\n\r\n // Replace advanced tokens - wrap results in brackets to protect from standard formatter\r\n let result = pattern.replace(\r\n /Q|Do|w|W|gggg|GGGG|k{1,2}|X|x|zzz?/g,\r\n (match) => {\r\n let replacement = '';\r\n switch (match) {\r\n // Quarter\r\n case 'Q':\r\n replacement = String(Math.ceil((temporal_dt.month) / 3));\r\n break;\r\n\r\n // Ordinal day\r\n case 'Do':\r\n replacement = ordinalFn(temporal_dt.day);\r\n break;\r\n\r\n // Week of year (ISO)\r\n case 'W':\r\n case 'WW':\r\n replacement = padFn(getISOWeek(temporal_dt), match === 'W' ? 1 : 2);\r\n break;\r\n\r\n // Week of year (locale)\r\n case 'w':\r\n case 'ww':\r\n replacement = padFn(getWeekOfYear(temporal_dt), match === 'w' ? 1 : 2);\r\n break;\r\n\r\n // ISO week year\r\n case 'GGGG':\r\n replacement = String(getISOWeekYear(temporal_dt));\r\n break;\r\n\r\n // Week year\r\n case 'gggg':\r\n replacement = String(getWeekYear(temporal_dt));\r\n break;\r\n\r\n // Hour (1-24)\r\n case 'k':\r\n case 'kk':\r\n const hour = temporal_dt.hour === 0 ? 24 : temporal_dt.hour;\r\n replacement = padFn(hour, match === 'k' ? 1 : 2);\r\n break;\r\n\r\n // Unix seconds timestamp\r\n case 'X':\r\n replacement = String(Math.floor(this.valueOf() / 1000));\r\n break;\r\n\r\n // Unix milliseconds timestamp\r\n case 'x':\r\n replacement = String(this.valueOf());\r\n break;\r\n\r\n // Timezone offset\r\n case 'z':\r\n replacement = `${this.getTimezoneOffset()}`;\r\n break;\r\n\r\n case 'zzz':\r\n replacement = `${this.getTimezoneOffsetLong()}`;\r\n break;\r\n\r\n default:\r\n return match;\r\n }\r\n // Wrap in brackets to protect from standard formatter\r\n return `[${replacement}]`;\r\n },\r\n );\r\n\r\n // Apply standard format to the result\r\n return originalFormat.call(this, result);\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Create and export default instance\r\n */\r\nexport default new AdvancedFormatPlugin();\r\n"],"mappings":";;AAUA,IAAa,IAAb,MAA8D;CAC5D,OAAO;CACP,UAAU;CAKV,QAAQ,GAAwC;EAE9C,IAAM,IAAiB,EAAe,UAAU;AAK/C,IAAe,UAAkB,SAAS,SAAU,GAAiB;AAMpE,OALI,CAAC,KAAW,OAAO,KAAY,YAK/B,CAAC,qCAAqC,KAAK,EAAQ,CACrD,QAAO,EAAe,KAAK,MAAM,EAAQ;GAI3C,IAAM,IAAW,KAAK,YAAY,EAC5B,IACJ,qBAAqB,IAChB,EAAiB,iBAAiB,GAClC,GAED,KAAa,MAAc;IAC/B,IAAM,IAAW;KAAC;KAAM;KAAM;KAAM;KAAK,EACnC,IAAI,IAAI;AACd,WAAO,KAAK,GAAU,IAAI,MAAM,OAAO,EAAS,MAAM,EAAS;MAE3D,KAAS,GAAW,MAAmB,OAAO,EAAE,CAAC,SAAS,GAAQ,IAAI,EACtE,KAAc,MAAkB;IACpC,IAAM,IAAO,IAAI,KAAK,EAAS,MAAM,GAAG,EAAE,EACpC,IAAa,IAAI,KAAK,EAAK;AACjC,MAAW,QAAQ,EAAK,SAAS,GAAG,EAAK,QAAQ,IAAI,EAAK,QAAQ,KAAK,IAAI,KAAK,GAAG;IACnF,IAAM,IAAc,IAAI,KAAK,EAAS,MAAM,EAAS,QAAQ,GAAG,EAAS,IAAI,EACvE,IAAU,KAAK,OAAO,EAAY,SAAS,GAAG,EAAW,SAAS,KAAK,QAAc,KAAK,KAAM,GAAG;AACzG,WAAO,KAAK,IA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M,KAAK,SAAS,GAAG,IAAK,CAAC;AACvD;KAGF,KAAK;AACH,UAAc,OAAO,KAAK,SAAS,CAAC;AACpC;KAGF,KAAK;AACH,UAAc,GAAG,KAAK,mBAAmB;AACzC;KAEF,KAAK;AACH,UAAc,GAAG,KAAK,uBAAuB;AAC7C;KAEF,QACE,QAAO;;AAGX,WAAO,IAAI,EAAY;KAE1B;AAGD,UAAO,EAAe,KAAK,MAAM,EAAO;;;GAQ9C,IAAe,IAAI,GAAsB"}
@@ -1,4 +1,4 @@
1
- /*! time-guard v2.5.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.5.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
2
  //#region src/plugins/duration/index.ts
3
3
  var e = class e {
4
4
  years = 0;
@@ -1,4 +1,4 @@
1
- /*! time-guard v2.5.1 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
1
+ /*! time-guard v2.5.2 | (c) 2026 Berea-Soft | MIT License | https://github.com/Berea-Soft/time-guard */
2
2
  //#region src/plugins/relative-time/index.ts
3
3
  var e = [
4
4
  {