@intlayer/core 8.5.2 → 8.6.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 (113) hide show
  1. package/dist/cjs/formatters/compact.cjs +1 -1
  2. package/dist/cjs/formatters/compact.cjs.map +1 -1
  3. package/dist/cjs/formatters/currency.cjs +1 -1
  4. package/dist/cjs/formatters/currency.cjs.map +1 -1
  5. package/dist/cjs/formatters/date.cjs +1 -1
  6. package/dist/cjs/formatters/date.cjs.map +1 -1
  7. package/dist/cjs/formatters/index.cjs +1 -1
  8. package/dist/cjs/formatters/list.cjs +1 -1
  9. package/dist/cjs/formatters/list.cjs.map +1 -1
  10. package/dist/cjs/formatters/number.cjs +1 -1
  11. package/dist/cjs/formatters/number.cjs.map +1 -1
  12. package/dist/cjs/formatters/percentage.cjs +2 -2
  13. package/dist/cjs/formatters/percentage.cjs.map +1 -1
  14. package/dist/cjs/formatters/relativeTime.cjs +1 -1
  15. package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
  16. package/dist/cjs/formatters/units.cjs +1 -1
  17. package/dist/cjs/formatters/units.cjs.map +1 -1
  18. package/dist/cjs/index.cjs +16 -9
  19. package/dist/cjs/interpreter/getContent/getContent.cjs +8 -8
  20. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  21. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +10 -35
  22. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
  23. package/dist/cjs/localization/generateSitemap.cjs +111 -0
  24. package/dist/cjs/localization/generateSitemap.cjs.map +1 -0
  25. package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
  26. package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
  27. package/dist/cjs/localization/getLocale.cjs +2 -2
  28. package/dist/cjs/localization/getLocale.cjs.map +1 -1
  29. package/dist/cjs/localization/getLocalizedUrl.cjs +1 -1
  30. package/dist/cjs/localization/getPrefix.cjs +1 -1
  31. package/dist/cjs/localization/index.cjs +8 -7
  32. package/dist/cjs/localization/localeMapper.cjs +1 -1
  33. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +2 -3
  34. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
  35. package/dist/cjs/utils/index.cjs +9 -3
  36. package/dist/cjs/utils/intl.cjs +88 -72
  37. package/dist/cjs/utils/intl.cjs.map +1 -1
  38. package/dist/cjs/utils/localeStorage.cjs +191 -64
  39. package/dist/cjs/utils/localeStorage.cjs.map +1 -1
  40. package/dist/esm/formatters/compact.mjs +2 -2
  41. package/dist/esm/formatters/compact.mjs.map +1 -1
  42. package/dist/esm/formatters/currency.mjs +2 -2
  43. package/dist/esm/formatters/currency.mjs.map +1 -1
  44. package/dist/esm/formatters/date.mjs +2 -2
  45. package/dist/esm/formatters/date.mjs.map +1 -1
  46. package/dist/esm/formatters/index.mjs +2 -2
  47. package/dist/esm/formatters/list.mjs +2 -2
  48. package/dist/esm/formatters/list.mjs.map +1 -1
  49. package/dist/esm/formatters/number.mjs +2 -2
  50. package/dist/esm/formatters/number.mjs.map +1 -1
  51. package/dist/esm/formatters/percentage.mjs +3 -3
  52. package/dist/esm/formatters/percentage.mjs.map +1 -1
  53. package/dist/esm/formatters/relativeTime.mjs +2 -2
  54. package/dist/esm/formatters/relativeTime.mjs.map +1 -1
  55. package/dist/esm/formatters/units.mjs +2 -2
  56. package/dist/esm/formatters/units.mjs.map +1 -1
  57. package/dist/esm/index.mjs +10 -10
  58. package/dist/esm/interpreter/getContent/getContent.mjs +8 -8
  59. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  60. package/dist/esm/interpreter/splitAndJoinInsertion.mjs +10 -35
  61. package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
  62. package/dist/esm/localization/generateSitemap.mjs +109 -0
  63. package/dist/esm/localization/generateSitemap.mjs.map +1 -0
  64. package/dist/esm/localization/getBrowserLocale.mjs +2 -2
  65. package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
  66. package/dist/esm/localization/getLocale.mjs +3 -3
  67. package/dist/esm/localization/getLocale.mjs.map +1 -1
  68. package/dist/esm/localization/getLocalizedUrl.mjs +1 -1
  69. package/dist/esm/localization/getPrefix.mjs +1 -1
  70. package/dist/esm/localization/index.mjs +7 -7
  71. package/dist/esm/localization/localeMapper.mjs +1 -1
  72. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +2 -4
  73. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
  74. package/dist/esm/utils/index.mjs +4 -4
  75. package/dist/esm/utils/intl.mjs +87 -72
  76. package/dist/esm/utils/intl.mjs.map +1 -1
  77. package/dist/esm/utils/localeStorage.mjs +186 -65
  78. package/dist/esm/utils/localeStorage.mjs.map +1 -1
  79. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +10 -10
  80. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
  81. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +10 -10
  82. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
  83. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +10 -10
  84. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
  85. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
  86. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
  87. package/dist/types/formatters/index.d.ts +2 -2
  88. package/dist/types/formatters/number.d.ts +4 -1
  89. package/dist/types/formatters/number.d.ts.map +1 -1
  90. package/dist/types/formatters/percentage.d.ts +4 -1
  91. package/dist/types/formatters/percentage.d.ts.map +1 -1
  92. package/dist/types/index.d.ts +4 -4
  93. package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
  94. package/dist/types/interpreter/splitAndJoinInsertion.d.ts +0 -17
  95. package/dist/types/interpreter/splitAndJoinInsertion.d.ts.map +1 -1
  96. package/dist/types/localization/generateSitemap.d.ts +93 -0
  97. package/dist/types/localization/generateSitemap.d.ts.map +1 -0
  98. package/dist/types/localization/getBrowserLocale.d.ts +2 -2
  99. package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
  100. package/dist/types/localization/index.d.ts +2 -2
  101. package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -1
  102. package/dist/types/utils/index.d.ts +3 -3
  103. package/dist/types/utils/intl.d.ts +15 -11
  104. package/dist/types/utils/intl.d.ts.map +1 -1
  105. package/dist/types/utils/localeStorage.d.ts +85 -68
  106. package/dist/types/utils/localeStorage.d.ts.map +1 -1
  107. package/package.json +8 -8
  108. package/dist/cjs/getStorageAttributes.cjs +0 -135
  109. package/dist/cjs/getStorageAttributes.cjs.map +0 -1
  110. package/dist/esm/getStorageAttributes.mjs +0 -133
  111. package/dist/esm/getStorageAttributes.mjs.map +0 -1
  112. package/dist/types/getStorageAttributes.d.ts +0 -29
  113. package/dist/types/getStorageAttributes.d.ts.map +0 -1
@@ -16,7 +16,7 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
16
16
  * compact("1000000", { locale: Locales.FRENCH, compactDisplay: "long" });
17
17
  * // "1 million"
18
18
  */
19
- const compact = (value, options) => new require_utils_intl.CachedIntl.NumberFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
19
+ const compact = (value, options) => require_utils_intl.getCachedIntl(Intl.NumberFormat, options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
20
20
  ...options,
21
21
  notation: "compact"
22
22
  }).format(Number(value));
@@ -1 +1 @@
1
- {"version":3,"file":"compact.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/compact.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using compact notation (e.g., 1K, 1M, 1B)\n * based on locale and formatting options.\n *\n * @example\n * compact(1200); // \"1.2K\"\n *\n * @example\n * compact(\"1000000\", { locale: Locales.FRENCH, compactDisplay: \"long\" });\n * // \"1 million\"\n */\nexport const compact = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new CachedIntl.NumberFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n ...options,\n notation: 'compact',\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,WACX,OACA,YAEA,IAAIA,8BAAW,aACb,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,GAAG;CACH,UAAU;CACX,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
1
+ {"version":3,"file":"compact.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/compact.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using compact notation (e.g., 1K, 1M, 1B)\n * based on locale and formatting options.\n *\n * @example\n * compact(1200); // \"1.2K\"\n *\n * @example\n * compact(\"1000000\", { locale: Locales.FRENCH, compactDisplay: \"long\" });\n * // \"1 million\"\n */\nexport const compact = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n ...options,\n notation: 'compact',\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,WACX,OACA,YAEAA,iCACE,KAAK,cACL,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,GAAG;CACH,UAAU;CACX,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
@@ -16,7 +16,7 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
16
16
  * currency("5000", { locale: Locales.FRENCH, currency: "CAD", currencyDisplay: "code" });
17
17
  * // "5 000,00 CAD"
18
18
  */
19
- const currency = (value, options) => new require_utils_intl.CachedIntl.NumberFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
19
+ const currency = (value, options) => require_utils_intl.getCachedIntl(Intl.NumberFormat, options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
20
20
  style: "currency",
21
21
  currency: options?.currency ?? "USD",
22
22
  currencyDisplay: options?.currencyDisplay ?? "symbol",
@@ -1 +1 @@
1
- {"version":3,"file":"currency.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/currency.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric or string value into a localized currency string using the Intl API.\n *\n * @example\n * currency(1234.5, { currency: 'EUR' });\n * // \"€1,234.50\"\n *\n * @example\n * currency(\"5000\", { locale: Locales.FRENCH, currency: \"CAD\", currencyDisplay: \"code\" });\n * // \"5 000,00 CAD\"\n */\nexport const currency = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new CachedIntl.NumberFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'currency',\n currency: options?.currency ?? 'USD',\n currencyDisplay: options?.currencyDisplay ?? 'symbol',\n minimumFractionDigits: options?.minimumFractionDigits ?? 2,\n maximumFractionDigits: options?.maximumFractionDigits ?? 2,\n ...options,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,YACX,OACA,YAEA,IAAIA,8BAAW,aACb,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,OAAO;CACP,UAAU,SAAS,YAAY;CAC/B,iBAAiB,SAAS,mBAAmB;CAC7C,uBAAuB,SAAS,yBAAyB;CACzD,uBAAuB,SAAS,yBAAyB;CACzD,GAAG;CACJ,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
1
+ {"version":3,"file":"currency.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/currency.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric or string value into a localized currency string using the Intl API.\n *\n * @example\n * currency(1234.5, { currency: 'EUR' });\n * // \"€1,234.50\"\n *\n * @example\n * currency(\"5000\", { locale: Locales.FRENCH, currency: \"CAD\", currencyDisplay: \"code\" });\n * // \"5 000,00 CAD\"\n */\nexport const currency = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'currency',\n currency: options?.currency ?? 'USD',\n currencyDisplay: options?.currencyDisplay ?? 'symbol',\n minimumFractionDigits: options?.minimumFractionDigits ?? 2,\n maximumFractionDigits: options?.maximumFractionDigits ?? 2,\n ...options,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,YACX,OACA,YAEAA,iCACE,KAAK,cACL,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,OAAO;CACP,UAAU,SAAS,YAAY;CAC/B,iBAAiB,SAAS,mBAAmB;CAC7C,uBAAuB,SAAS,yBAAyB;CACzD,uBAAuB,SAAS,yBAAyB;CACzD,GAAG;CACJ,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
@@ -54,7 +54,7 @@ const date = (date, options) => {
54
54
  const dateTime = new Date(date);
55
55
  const resolvedOptions = typeof options === "string" ? presets[options] ?? {} : options;
56
56
  const locale = (typeof options === "object" ? options?.locale : void 0) ?? _intlayer_config_built.default?.internationalization?.defaultLocale;
57
- return new require_utils_intl.CachedIntl.DateTimeFormat(locale, resolvedOptions).format(dateTime);
57
+ return require_utils_intl.getCachedIntl(Intl.DateTimeFormat, locale, resolvedOptions).format(dateTime);
58
58
  };
59
59
 
60
60
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"date.cjs","names":["configuration","CachedIntl"],"sources":["../../../src/formatters/date.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\nexport type DateTimePreset =\n | 'short'\n | 'long'\n | 'dateOnly'\n | 'timeOnly'\n | 'full';\n\nexport const presets: Record<DateTimePreset, Intl.DateTimeFormatOptions> = {\n short: {\n year: '2-digit',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n },\n long: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n },\n full: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n },\n dateOnly: {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n },\n timeOnly: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n};\n\n/**\n * Formats a date/time value into a localized string using Intl.DateTimeFormat.\n *\n * @example\n * date(new Date('2025-08-02T14:30:00Z'), { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });\n * // \"08/02/25, 14:30\"\n *\n * @example\n * date(\"2025-08-02T14:30:00Z\", { locale: Locales.FRENCH, month: \"long\", day: \"numeric\" });\n * // \"2 août\"\n */\nexport const date = (\n date: Date | string | number,\n options?:\n | (Intl.DateTimeFormatOptions & { locale?: LocalesValues })\n | DateTimePreset\n): string => {\n const dateTime = new Date(date);\n\n const resolvedOptions =\n typeof options === 'string' ? (presets[options] ?? {}) : options;\n\n const locale =\n (typeof options === 'object' ? options?.locale : undefined) ??\n configuration?.internationalization?.defaultLocale;\n\n const formatter = new CachedIntl.DateTimeFormat(locale, resolvedOptions);\n\n return formatter.format(dateTime);\n};\n"],"mappings":";;;;;;;AAWA,MAAa,UAA8D;CACzE,OAAO;EACL,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACT;CACD,MAAM;EACJ,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACT;CACD,MAAM;EACJ,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACR,QAAQ;EACT;CACD,UAAU;EACR,MAAM;EACN,OAAO;EACP,KAAK;EACN;CACD,UAAU;EACR,MAAM;EACN,QAAQ;EACR,QAAQ;EACT;CACF;;;;;;;;;;;;AAaD,MAAa,QACX,MACA,YAGW;CACX,MAAM,WAAW,IAAI,KAAK,KAAK;CAE/B,MAAM,kBACJ,OAAO,YAAY,WAAY,QAAQ,YAAY,EAAE,GAAI;CAE3D,MAAM,UACH,OAAO,YAAY,WAAW,SAAS,SAAS,WACjDA,gCAAe,sBAAsB;AAIvC,QAFkB,IAAIC,8BAAW,eAAe,QAAQ,gBAAgB,CAEvD,OAAO,SAAS"}
1
+ {"version":3,"file":"date.cjs","names":["configuration","getCachedIntl"],"sources":["../../../src/formatters/date.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\nexport type DateTimePreset =\n | 'short'\n | 'long'\n | 'dateOnly'\n | 'timeOnly'\n | 'full';\n\nexport const presets: Record<DateTimePreset, Intl.DateTimeFormatOptions> = {\n short: {\n year: '2-digit',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n },\n long: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n },\n full: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n },\n dateOnly: {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n },\n timeOnly: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n};\n\n/**\n * Formats a date/time value into a localized string using Intl.DateTimeFormat.\n *\n * @example\n * date(new Date('2025-08-02T14:30:00Z'), { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });\n * // \"08/02/25, 14:30\"\n *\n * @example\n * date(\"2025-08-02T14:30:00Z\", { locale: Locales.FRENCH, month: \"long\", day: \"numeric\" });\n * // \"2 août\"\n */\nexport const date = (\n date: Date | string | number,\n options?:\n | (Intl.DateTimeFormatOptions & { locale?: LocalesValues })\n | DateTimePreset\n): string => {\n const dateTime = new Date(date);\n\n const resolvedOptions =\n typeof options === 'string' ? (presets[options] ?? {}) : options;\n\n const locale =\n (typeof options === 'object' ? options?.locale : undefined) ??\n configuration?.internationalization?.defaultLocale;\n\n const formatter = getCachedIntl(Intl.DateTimeFormat, locale, resolvedOptions);\n\n return formatter.format(dateTime);\n};\n"],"mappings":";;;;;;;AAWA,MAAa,UAA8D;CACzE,OAAO;EACL,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACT;CACD,MAAM;EACJ,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACT;CACD,MAAM;EACJ,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACR,QAAQ;EACT;CACD,UAAU;EACR,MAAM;EACN,OAAO;EACP,KAAK;EACN;CACD,UAAU;EACR,MAAM;EACN,QAAQ;EACR,QAAQ;EACT;CACF;;;;;;;;;;;;AAaD,MAAa,QACX,MACA,YAGW;CACX,MAAM,WAAW,IAAI,KAAK,KAAK;CAE/B,MAAM,kBACJ,OAAO,YAAY,WAAY,QAAQ,YAAY,EAAE,GAAI;CAE3D,MAAM,UACH,OAAO,YAAY,WAAW,SAAS,SAAS,WACjDA,gCAAe,sBAAsB;AAIvC,QAFkBC,iCAAc,KAAK,gBAAgB,QAAQ,gBAAgB,CAE5D,OAAO,SAAS"}
@@ -13,9 +13,9 @@ exports.CachedIntl = require_utils_intl.CachedIntl;
13
13
  exports.Intl = require_utils_intl.CachedIntl;
14
14
  exports.bindIntl = require_utils_intl.bindIntl;
15
15
  exports.compact = require_formatters_compact.compact;
16
- exports.createCachedIntl = require_utils_intl.createCachedIntl;
17
16
  exports.currency = require_formatters_currency.currency;
18
17
  exports.date = require_formatters_date.date;
18
+ exports.getCachedIntl = require_utils_intl.getCachedIntl;
19
19
  exports.list = require_formatters_list.list;
20
20
  exports.number = require_formatters_number.number;
21
21
  exports.percentage = require_formatters_percentage.percentage;
@@ -20,7 +20,7 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
20
20
  * list([1, 2, 3], { type: 'unit' });
21
21
  * // "1, 2, 3"
22
22
  */
23
- const list = (values, options) => new require_utils_intl.CachedIntl.ListFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
23
+ const list = (values, options) => require_utils_intl.getCachedIntl(Intl.ListFormat, options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
24
24
  type: options?.type ?? "conjunction",
25
25
  style: options?.style ?? "long",
26
26
  ...options
@@ -1 +1 @@
1
- {"version":3,"file":"list.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/list.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\n/** Locally defined subset of Intl.ListFormatOptions so consumers don't need ES2021.Intl in their lib. */\ntype ListFormatOptions = {\n localeMatcher?: 'lookup' | 'best fit';\n type?: 'conjunction' | 'disjunction' | 'unit';\n style?: 'long' | 'short' | 'narrow';\n};\n\n/**\n * Formats an array of values into a localized list string using the Intl API.\n *\n * @example\n * list(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * @example\n * list(['red', 'green', 'blue'], { locale: Locales.FRENCH, type: 'disjunction' });\n * // \"rouge, vert ou bleu\"\n *\n * @example\n * list([1, 2, 3], { type: 'unit' });\n * // \"1, 2, 3\"\n */\nexport const list = (\n values: (string | number)[],\n options?: ListFormatOptions & { locale?: LocalesValues }\n): string =>\n new CachedIntl.ListFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n type: options?.type ?? 'conjunction',\n style: options?.style ?? 'long',\n ...options,\n }\n ).format(values.map(String));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,QACX,QACA,YAEA,IAAIA,8BAAW,WACb,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,MAAM,SAAS,QAAQ;CACvB,OAAO,SAAS,SAAS;CACzB,GAAG;CACJ,CACF,CAAC,OAAO,OAAO,IAAI,OAAO,CAAC"}
1
+ {"version":3,"file":"list.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/list.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/** Locally defined subset of Intl.ListFormatOptions so consumers don't need ES2021.Intl in their lib. */\ntype ListFormatOptions = {\n localeMatcher?: 'lookup' | 'best fit';\n type?: 'conjunction' | 'disjunction' | 'unit';\n style?: 'long' | 'short' | 'narrow';\n};\n\n/**\n * Formats an array of values into a localized list string using the Intl API.\n *\n * @example\n * list(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * @example\n * list(['red', 'green', 'blue'], { locale: Locales.FRENCH, type: 'disjunction' });\n * // \"rouge, vert ou bleu\"\n *\n * @example\n * list([1, 2, 3], { type: 'unit' });\n * // \"1, 2, 3\"\n */\nexport const list = (\n values: (string | number)[],\n options?: ListFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n (Intl as any).ListFormat,\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n type: options?.type ?? 'conjunction',\n style: options?.style ?? 'long',\n ...options,\n }\n ).format(values.map(String));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,QACX,QACA,YAEAA,iCACG,KAAa,YACd,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,MAAM,SAAS,QAAQ;CACvB,OAAO,SAAS,SAAS;CACzB,GAAG;CACJ,CACF,CAAC,OAAO,OAAO,IAAI,OAAO,CAAC"}
@@ -14,7 +14,7 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
14
14
  * @example
15
15
  * number("1000000", { locale: Locales.FRENCH }); // "1 000 000"
16
16
  */
17
- const number = (value, options) => new require_utils_intl.CachedIntl.NumberFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, options).format(Number(value));
17
+ const number = (value, { locale, ...options } = {}) => require_utils_intl.getCachedIntl(Intl.NumberFormat, locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, options).format(Number(value));
18
18
 
19
19
  //#endregion
20
20
  exports.number = number;
@@ -1 +1 @@
1
- {"version":3,"file":"number.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/number.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using locale-aware formatting.\n *\n * @example\n * number(123456.789); // \"123,456.789\"\n *\n * @example\n * number(\"1000000\", { locale: Locales.FRENCH }); // \"1 000 000\"\n */\nexport const number = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new CachedIntl.NumberFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n options\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAa,UACX,OACA,YAEA,IAAIA,8BAAW,aACb,SAAS,UAAUC,gCAAe,sBAAsB,eACxD,QACD,CAAC,OAAO,OAAO,MAAM,CAAC"}
1
+ {"version":3,"file":"number.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/number.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using locale-aware formatting.\n *\n * @example\n * number(123456.789); // \"123,456.789\"\n *\n * @example\n * number(\"1000000\", { locale: Locales.FRENCH }); // \"1 000 000\"\n */\nexport const number = (\n value: string | number,\n {\n locale,\n ...options\n }: Intl.NumberFormatOptions & { locale?: LocalesValues } = {}\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n locale ?? configuration?.internationalization?.defaultLocale,\n options\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAa,UACX,OACA,EACE,QACA,GAAG,YACsD,EAAE,KAE7DA,iCACE,KAAK,cACL,UAAUC,gCAAe,sBAAsB,eAC/C,QACD,CAAC,OAAO,OAAO,MAAM,CAAC"}
@@ -14,10 +14,10 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
14
14
  * @example
15
15
  * percentage(0.25, { minimumFractionDigits: 2 }); // "25.00%"
16
16
  */
17
- const percentage = (value, options) => {
17
+ const percentage = (value, { locale, ...options } = {}) => {
18
18
  let numericValue = Number(value);
19
19
  if (numericValue > 1) numericValue /= 100;
20
- return new require_utils_intl.CachedIntl.NumberFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
20
+ return require_utils_intl.getCachedIntl(Intl.NumberFormat, locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
21
21
  style: "percent",
22
22
  ...options
23
23
  }).format(Number(numericValue));
@@ -1 +1 @@
1
- {"version":3,"file":"percentage.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/percentage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\n/**\n * Formats a number as a percentage string (e.g., 0.25 → \"25%\").\n *\n * @example\n * percentage(0.25); // \"25%\"\n *\n * @example\n * percentage(0.25, { minimumFractionDigits: 2 }); // \"25.00%\"\n */\nexport const percentage = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string => {\n let numericValue = Number(value);\n\n // Normalize: if user passes 10, treat it as 10% instead of 1000%\n if (numericValue > 1) {\n numericValue /= 100;\n }\n\n const formatter = new CachedIntl.NumberFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'percent',\n ...options,\n }\n );\n\n return formatter.format(Number(numericValue));\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAa,cACX,OACA,YACW;CACX,IAAI,eAAe,OAAO,MAAM;AAGhC,KAAI,eAAe,EACjB,iBAAgB;AAWlB,QARkB,IAAIA,8BAAW,aAC/B,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;EACE,OAAO;EACP,GAAG;EACJ,CACF,CAEgB,OAAO,OAAO,aAAa,CAAC"}
1
+ {"version":3,"file":"percentage.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/percentage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a number as a percentage string (e.g., 0.25 → \"25%\").\n *\n * @example\n * percentage(0.25); // \"25%\"\n *\n * @example\n * percentage(0.25, { minimumFractionDigits: 2 }); // \"25.00%\"\n */\nexport const percentage = (\n value: string | number,\n {\n locale,\n ...options\n }: Intl.NumberFormatOptions & { locale?: LocalesValues } = {}\n): string => {\n let numericValue = Number(value);\n\n // Normalize: if user passes 10, treat it as 10% instead of 1000%\n if (numericValue > 1) {\n numericValue /= 100;\n }\n\n const formatter = getCachedIntl(\n Intl.NumberFormat,\n locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'percent',\n ...options,\n }\n );\n\n return formatter.format(Number(numericValue));\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAa,cACX,OACA,EACE,QACA,GAAG,YACsD,EAAE,KAClD;CACX,IAAI,eAAe,OAAO,MAAM;AAGhC,KAAI,eAAe,EACjB,iBAAgB;AAYlB,QATkBA,iCAChB,KAAK,cACL,UAAUC,gCAAe,sBAAsB,eAC/C;EACE,OAAO;EACP,GAAG;EACJ,CACF,CAEgB,OAAO,OAAO,aAAa,CAAC"}
@@ -36,7 +36,7 @@ const relativeTime = (from, to = /* @__PURE__ */ new Date(), options) => {
36
36
  const toDate = new Date(to);
37
37
  const unit = options?.unit ?? "second";
38
38
  const value = diffInUnit(fromDate, toDate, unit);
39
- return new require_utils_intl.CachedIntl.RelativeTimeFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, options).format(Math.round(value), unit);
39
+ return require_utils_intl.getCachedIntl(Intl.RelativeTimeFormat, options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, options).format(Math.round(value), unit);
40
40
  };
41
41
 
42
42
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"relativeTime.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/relativeTime.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\ntype RelativeTimeUnit = Intl.RelativeTimeFormatUnit;\n\n/**\n * Calculate the difference between 2 dates in the given unit.\n */\nconst diffInUnit = (from: Date, to: Date, unit: RelativeTimeUnit): number => {\n const msDiff = to.getTime() - from.getTime();\n const sec = msDiff / 1000;\n\n switch (unit) {\n case 'second':\n return sec;\n case 'minute':\n return sec / 60;\n case 'hour':\n return sec / 3600;\n case 'day':\n return sec / 86400;\n case 'month':\n return sec / (30 * 86400); // approx\n case 'quarter':\n return sec / (3 * 30 * 86400); // 3 months approx\n case 'year':\n return sec / (365 * 86400); // approx\n default:\n return sec;\n }\n};\n\n/**\n * Formats the difference between two dates as a localized relative time string.\n *\n * @example\n * relativeTime(new Date(Date.now() - 30000)); // \"30 seconds ago\"\n *\n * @example\n * relativeTime(\"2025-01-01\", new Date(), { locale: Locales.FRENCH, unit: \"day\" });\n * // \"il y a 443 jours\"\n */\nexport const relativeTime = (\n from: Date | string | number,\n to: Date | string | number = new Date(),\n options?: Intl.RelativeTimeFormatOptions & {\n locale?: LocalesValues;\n unit?: RelativeTimeUnit;\n }\n): string => {\n const fromDate = new Date(from);\n const toDate = new Date(to);\n const unit = options?.unit ?? 'second';\n\n const value = diffInUnit(fromDate, toDate, unit);\n\n return new CachedIntl.RelativeTimeFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n options\n ).format(Math.round(value), unit);\n};\n"],"mappings":";;;;;;;;;;AASA,MAAM,cAAc,MAAY,IAAU,SAAmC;CAE3E,MAAM,OADS,GAAG,SAAS,GAAG,KAAK,SAAS,IACvB;AAErB,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,SACH,QAAO,MAAM;EACf,KAAK,OACH,QAAO,MAAM;EACf,KAAK,MACH,QAAO,MAAM;EACf,KAAK,QACH,QAAO,OAAO,KAAK;EACrB,KAAK,UACH,QAAO,OAAO,KAAS;EACzB,KAAK,OACH,QAAO,OAAO,MAAM;EACtB,QACE,QAAO;;;;;;;;;;;;;AAcb,MAAa,gBACX,MACA,qBAA6B,IAAI,MAAM,EACvC,YAIW;CACX,MAAM,WAAW,IAAI,KAAK,KAAK;CAC/B,MAAM,SAAS,IAAI,KAAK,GAAG;CAC3B,MAAM,OAAO,SAAS,QAAQ;CAE9B,MAAM,QAAQ,WAAW,UAAU,QAAQ,KAAK;AAEhD,QAAO,IAAIA,8BAAW,mBACpB,SAAS,UAAUC,gCAAe,sBAAsB,eACxD,QACD,CAAC,OAAO,KAAK,MAAM,MAAM,EAAE,KAAK"}
1
+ {"version":3,"file":"relativeTime.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/relativeTime.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\ntype RelativeTimeUnit = Intl.RelativeTimeFormatUnit;\n\n/**\n * Calculate the difference between 2 dates in the given unit.\n */\nconst diffInUnit = (from: Date, to: Date, unit: RelativeTimeUnit): number => {\n const msDiff = to.getTime() - from.getTime();\n const sec = msDiff / 1000;\n\n switch (unit) {\n case 'second':\n return sec;\n case 'minute':\n return sec / 60;\n case 'hour':\n return sec / 3600;\n case 'day':\n return sec / 86400;\n case 'month':\n return sec / (30 * 86400); // approx\n case 'quarter':\n return sec / (3 * 30 * 86400); // 3 months approx\n case 'year':\n return sec / (365 * 86400); // approx\n default:\n return sec;\n }\n};\n\n/**\n * Formats the difference between two dates as a localized relative time string.\n *\n * @example\n * relativeTime(new Date(Date.now() - 30000)); // \"30 seconds ago\"\n *\n * @example\n * relativeTime(\"2025-01-01\", new Date(), { locale: Locales.FRENCH, unit: \"day\" });\n * // \"il y a 443 jours\"\n */\nexport const relativeTime = (\n from: Date | string | number,\n to: Date | string | number = new Date(),\n options?: Intl.RelativeTimeFormatOptions & {\n locale?: LocalesValues;\n unit?: RelativeTimeUnit;\n }\n): string => {\n const fromDate = new Date(from);\n const toDate = new Date(to);\n const unit = options?.unit ?? 'second';\n\n const value = diffInUnit(fromDate, toDate, unit);\n\n return getCachedIntl(\n Intl.RelativeTimeFormat,\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n options\n ).format(Math.round(value), unit);\n};\n"],"mappings":";;;;;;;;;;AASA,MAAM,cAAc,MAAY,IAAU,SAAmC;CAE3E,MAAM,OADS,GAAG,SAAS,GAAG,KAAK,SAAS,IACvB;AAErB,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,SACH,QAAO,MAAM;EACf,KAAK,OACH,QAAO,MAAM;EACf,KAAK,MACH,QAAO,MAAM;EACf,KAAK,QACH,QAAO,OAAO,KAAK;EACrB,KAAK,UACH,QAAO,OAAO,KAAS;EACzB,KAAK,OACH,QAAO,OAAO,MAAM;EACtB,QACE,QAAO;;;;;;;;;;;;;AAcb,MAAa,gBACX,MACA,qBAA6B,IAAI,MAAM,EACvC,YAIW;CACX,MAAM,WAAW,IAAI,KAAK,KAAK;CAC/B,MAAM,SAAS,IAAI,KAAK,GAAG;CAC3B,MAAM,OAAO,SAAS,QAAQ;CAE9B,MAAM,QAAQ,WAAW,UAAU,QAAQ,KAAK;AAEhD,QAAOA,iCACL,KAAK,oBACL,SAAS,UAAUC,gCAAe,sBAAsB,eACxD,QACD,CAAC,OAAO,KAAK,MAAM,MAAM,EAAE,KAAK"}
@@ -12,7 +12,7 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
12
12
  * units(5, { unit: "kilometer", unitDisplay: "long", locale: "en-GB" });
13
13
  * // "5 kilometers"
14
14
  */
15
- const units = (value, options) => new require_utils_intl.CachedIntl.NumberFormat(options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
15
+ const units = (value, options) => require_utils_intl.getCachedIntl(Intl.NumberFormat, options?.locale ?? _intlayer_config_built.default?.internationalization?.defaultLocale, {
16
16
  style: "unit",
17
17
  unit: options?.unit ?? "day",
18
18
  unitDisplay: options?.unitDisplay ?? "short",
@@ -1 +1 @@
1
- {"version":3,"file":"units.cjs","names":["CachedIntl","configuration"],"sources":["../../../src/formatters/units.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { Intl as CachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value as a localized unit string.\n *\n * @example\n * units(5, { unit: \"kilometer\", unitDisplay: \"long\", locale: \"en-GB\" });\n * // \"5 kilometers\"\n */\nexport const units = (\n value: number | string,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n new CachedIntl.NumberFormat(\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'unit',\n unit: options?.unit ?? 'day',\n unitDisplay: options?.unitDisplay ?? 'short',\n useGrouping: options?.useGrouping ?? false,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;AAWA,MAAa,SACX,OACA,YAEA,IAAIA,8BAAW,aACb,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,OAAO;CACP,MAAM,SAAS,QAAQ;CACvB,aAAa,SAAS,eAAe;CACrC,aAAa,SAAS,eAAe;CACtC,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
1
+ {"version":3,"file":"units.cjs","names":["getCachedIntl","configuration"],"sources":["../../../src/formatters/units.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value as a localized unit string.\n *\n * @example\n * units(5, { unit: \"kilometer\", unitDisplay: \"long\", locale: \"en-GB\" });\n * // \"5 kilometers\"\n */\nexport const units = (\n value: number | string,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? configuration?.internationalization?.defaultLocale,\n {\n style: 'unit',\n unit: options?.unit ?? 'day',\n unitDisplay: options?.unitDisplay ?? 'short',\n useGrouping: options?.useGrouping ?? false,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;AAWA,MAAa,SACX,OACA,YAEAA,iCACE,KAAK,cACL,SAAS,UAAUC,gCAAe,sBAAsB,eACxD;CACE,OAAO;CACP,MAAM,SAAS,QAAQ;CACvB,aAAa,SAAS,eAAe;CACrC,aAAa,SAAS,eAAe;CACtC,CACF,CAAC,OAAO,OAAO,MAAM,CAAC"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_getStorageAttributes = require('./getStorageAttributes.cjs');
3
2
  const require_interpreter_getCondition = require('./interpreter/getCondition.cjs');
4
3
  const require_interpreter_getContent_deepTransform = require('./interpreter/getContent/deepTransform.cjs');
5
4
  const require_interpreter_getEnumeration = require('./interpreter/getEnumeration.cjs');
@@ -57,6 +56,13 @@ const require_formatters_number = require('./formatters/number.cjs');
57
56
  const require_formatters_percentage = require('./formatters/percentage.cjs');
58
57
  const require_formatters_relativeTime = require('./formatters/relativeTime.cjs');
59
58
  const require_formatters_units = require('./formatters/units.cjs');
59
+ const require_utils_checkIsURLAbsolute = require('./utils/checkIsURLAbsolute.cjs');
60
+ const require_localization_getPathWithoutLocale = require('./localization/getPathWithoutLocale.cjs');
61
+ const require_localization_getPrefix = require('./localization/getPrefix.cjs');
62
+ const require_localization_rewriteUtils = require('./localization/rewriteUtils.cjs');
63
+ const require_localization_getLocalizedUrl = require('./localization/getLocalizedUrl.cjs');
64
+ const require_localization_getMultilingualUrls = require('./localization/getMultilingualUrls.cjs');
65
+ const require_localization_generateSitemap = require('./localization/generateSitemap.cjs');
60
66
  const require_utils_getCookie = require('./utils/getCookie.cjs');
61
67
  const require_utils_localeStorage = require('./utils/localeStorage.cjs');
62
68
  const require_localization_localeResolver = require('./localization/localeResolver.cjs');
@@ -64,15 +70,9 @@ const require_localization_localeDetector = require('./localization/localeDetect
64
70
  const require_localization_getBrowserLocale = require('./localization/getBrowserLocale.cjs');
65
71
  const require_localization_getHTMLTextDir = require('./localization/getHTMLTextDir.cjs');
66
72
  const require_localization_getLocale = require('./localization/getLocale.cjs');
67
- const require_utils_checkIsURLAbsolute = require('./utils/checkIsURLAbsolute.cjs');
68
- const require_localization_getPrefix = require('./localization/getPrefix.cjs');
69
73
  const require_localization_getLocaleFromPath = require('./localization/getLocaleFromPath.cjs');
70
74
  const require_localization_getLocaleLang = require('./localization/getLocaleLang.cjs');
71
75
  const require_localization_getLocaleName = require('./localization/getLocaleName.cjs');
72
- const require_localization_getPathWithoutLocale = require('./localization/getPathWithoutLocale.cjs');
73
- const require_localization_rewriteUtils = require('./localization/rewriteUtils.cjs');
74
- const require_localization_getLocalizedUrl = require('./localization/getLocalizedUrl.cjs');
75
- const require_localization_getMultilingualUrls = require('./localization/getMultilingualUrls.cjs');
76
76
  const require_localization_localeMapper = require('./localization/localeMapper.cjs');
77
77
  const require_localization_validatePrefix = require('./localization/validatePrefix.cjs');
78
78
  const require_markdown_constants = require('./markdown/constants.cjs');
@@ -127,6 +127,8 @@ exports.LINK_AUTOLINK_R = require_markdown_constants.LINK_AUTOLINK_R;
127
127
  exports.LIST_LOOKBEHIND_R = require_markdown_constants.LIST_LOOKBEHIND_R;
128
128
  exports.LOOKAHEAD = require_markdown_constants.LOOKAHEAD;
129
129
  exports.LocaleStorage = require_utils_localeStorage.LocaleStorage;
130
+ exports.LocaleStorageClient = require_utils_localeStorage.LocaleStorageClient;
131
+ exports.LocaleStorageServer = require_utils_localeStorage.LocaleStorageServer;
130
132
  exports.NAMED_CODES_TO_UNICODE = require_markdown_constants.NAMED_CODES_TO_UNICODE;
131
133
  exports.NP_TABLE_R = require_markdown_constants.NP_TABLE_R;
132
134
  exports.ORDERED = require_markdown_constants.ORDERED;
@@ -177,7 +179,6 @@ exports.compile = require_markdown_compiler.compile;
177
179
  exports.compileWithOptions = require_markdown_compiler.compileWithOptions;
178
180
  exports.cond = require_transpiler_condition_condition.cond;
179
181
  exports.conditionPlugin = require_interpreter_getContent_plugins.conditionPlugin;
180
- exports.createCachedIntl = require_utils_intl.createCachedIntl;
181
182
  exports.createCompiler = require_markdown_compiler.createCompiler;
182
183
  exports.createRenderer = require_markdown_renderer.createRenderer;
183
184
  exports.currency = require_formatters_currency.currency;
@@ -197,9 +198,12 @@ exports.generateListItemPrefix = require_markdown_constants.generateListItemPref
197
198
  exports.generateListItemPrefixRegex = require_markdown_constants.generateListItemPrefixRegex;
198
199
  exports.generateListItemRegex = require_markdown_constants.generateListItemRegex;
199
200
  exports.generateListRegex = require_markdown_constants.generateListRegex;
201
+ exports.generateSitemap = require_localization_generateSitemap.generateSitemap;
202
+ exports.generateSitemapUrl = require_localization_generateSitemap.generateSitemapUrl;
200
203
  exports.get = require_markdown_utils.get;
201
204
  exports.getBasePlugins = require_interpreter_getContent_getContent.getBasePlugins;
202
205
  exports.getBrowserLocale = require_localization_getBrowserLocale.getBrowserLocale;
206
+ exports.getCachedIntl = require_utils_intl.getCachedIntl;
203
207
  exports.getCanonicalPath = require_localization_rewriteUtils.getCanonicalPath;
204
208
  exports.getCondition = require_interpreter_getCondition.getCondition;
205
209
  exports.getContent = require_interpreter_getContent_getContent.getContent;
@@ -223,6 +227,8 @@ exports.getIntlayer = require_interpreter_getIntlayer.getIntlayer;
223
227
  exports.getLocale = require_localization_getLocale.getLocale;
224
228
  exports.getLocaleFromPath = require_localization_getLocaleFromPath.getLocaleFromPath;
225
229
  exports.getLocaleFromStorage = require_utils_localeStorage.getLocaleFromStorage;
230
+ exports.getLocaleFromStorageClient = require_utils_localeStorage.getLocaleFromStorageClient;
231
+ exports.getLocaleFromStorageServer = require_utils_localeStorage.getLocaleFromStorageServer;
226
232
  exports.getLocaleLang = require_localization_getLocaleLang.getLocaleLang;
227
233
  exports.getLocaleName = require_localization_getLocaleName.getLocaleName;
228
234
  exports.getLocalizedContent = require_deepTransformPlugins_getLocalizedContent.getLocalizedContent;
@@ -245,7 +251,6 @@ exports.getRewritePath = require_localization_rewriteUtils.getRewritePath;
245
251
  exports.getRewriteRules = require_localization_rewriteUtils.getRewriteRules;
246
252
  exports.getSplittedContent = require_deepTransformPlugins_getSplittedContent.getSplittedContent;
247
253
  exports.getSplittedDictionaryContent = require_deepTransformPlugins_getSplittedContent.getSplittedDictionaryContent;
248
- exports.getStorageAttributes = require_getStorageAttributes.getStorageAttributes;
249
254
  exports.getTranslation = require_interpreter_getTranslation.getTranslation;
250
255
  exports.html = require_transpiler_html_html.html;
251
256
  exports.i18nextToIntlayerFormatter = require_messageFormat_i18next.i18nextToIntlayerFormatter;
@@ -297,6 +302,8 @@ exports.renderFor = require_markdown_renderer.renderFor;
297
302
  exports.renderNothing = require_markdown_utils.renderNothing;
298
303
  exports.sanitizer = require_markdown_utils.sanitizer;
299
304
  exports.setLocaleInStorage = require_utils_localeStorage.setLocaleInStorage;
305
+ exports.setLocaleInStorageClient = require_utils_localeStorage.setLocaleInStorageClient;
306
+ exports.setLocaleInStorageServer = require_utils_localeStorage.setLocaleInStorageServer;
300
307
  exports.simpleInlineRegex = require_markdown_utils.simpleInlineRegex;
301
308
  exports.slugify = require_markdown_utils.slugify;
302
309
  exports.some = require_markdown_utils.some;
@@ -7,14 +7,14 @@ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
7
7
 
8
8
  //#region src/interpreter/getContent/getContent.ts
9
9
  const getBasePlugins = (locale, fallback = true) => [
10
- require_interpreter_getContent_plugins.translationPlugin(locale ?? _intlayer_config_built.default.internationalization.defaultLocale, fallback ? _intlayer_config_built.default.internationalization.defaultLocale : void 0),
11
- require_interpreter_getContent_plugins.enumerationPlugin,
12
- require_interpreter_getContent_plugins.conditionPlugin,
13
- require_interpreter_getContent_plugins.insertionPlugin,
14
- require_interpreter_getContent_plugins.nestedPlugin(locale ?? _intlayer_config_built.default.internationalization.defaultLocale),
15
- require_interpreter_getContent_plugins.filePlugin,
16
- require_interpreter_getContent_plugins.genderPlugin
17
- ];
10
+ process.env.INTLAYER_NODE_TYPE_TRANSLATION !== "false" && require_interpreter_getContent_plugins.translationPlugin(locale ?? _intlayer_config_built.default.internationalization.defaultLocale, fallback ? _intlayer_config_built.default.internationalization.defaultLocale : void 0),
11
+ process.env.INTLAYER_NODE_TYPE_ENUMERATION !== "false" && require_interpreter_getContent_plugins.enumerationPlugin,
12
+ process.env.INTLAYER_NODE_TYPE_CONDITION !== "false" && require_interpreter_getContent_plugins.conditionPlugin,
13
+ process.env.INTLAYER_NODE_TYPE_INSERTION !== "false" && require_interpreter_getContent_plugins.insertionPlugin,
14
+ process.env.INTLAYER_NODE_TYPE_NESTED !== "false" && require_interpreter_getContent_plugins.nestedPlugin(locale ?? _intlayer_config_built.default.internationalization.defaultLocale),
15
+ process.env.INTLAYER_NODE_TYPE_FILE !== "false" && require_interpreter_getContent_plugins.filePlugin,
16
+ process.env.INTLAYER_NODE_TYPE_GENDER !== "false" && require_interpreter_getContent_plugins.genderPlugin
17
+ ].filter(Boolean);
18
18
  /**
19
19
  * Transforms a node in a single pass, applying each plugin as needed.
20
20
  *
@@ -1 +1 @@
1
- {"version":3,"file":"getContent.cjs","names":["translationPlugin","configuration","enumerationPlugin","conditionPlugin","insertionPlugin","nestedPlugin","filePlugin","genderPlugin","deepTransformNode"],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => [\n translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n insertionPlugin,\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;;;;AAqBA,MAAa,kBACX,QACA,WAAoB,SACN;CACdA,yDACE,UAAUC,+BAAc,qBAAqB,eAC7C,WAAWA,+BAAc,qBAAqB,gBAAgB,OAC/D;CACDC;CACAC;CACAC;CACAC,oDAAa,UAAUJ,+BAAc,qBAAqB,cAAc;CACxEK;CACAC;CACD;;;;;;;AAQD,MAAa,cAIX,MACA,WACA,UAAqB,EAAE,KAEvBC,+DAAkB,MAAM;CACtB,GAAG;CACH;CACD,CAAC"}
1
+ {"version":3,"file":"getContent.cjs","names":["translationPlugin","configuration","enumerationPlugin","conditionPlugin","insertionPlugin","nestedPlugin","filePlugin","genderPlugin","deepTransformNode"],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] =>\n [\n process.env.INTLAYER_NODE_TYPE_TRANSLATION !== 'false' &&\n translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n process.env.INTLAYER_NODE_TYPE_ENUMERATION !== 'false' && enumerationPlugin,\n process.env.INTLAYER_NODE_TYPE_CONDITION !== 'false' && conditionPlugin,\n process.env.INTLAYER_NODE_TYPE_INSERTION !== 'false' && insertionPlugin,\n process.env.INTLAYER_NODE_TYPE_NESTED !== 'false' &&\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n process.env.INTLAYER_NODE_TYPE_FILE !== 'false' && filePlugin,\n process.env.INTLAYER_NODE_TYPE_GENDER !== 'false' && genderPlugin,\n ].filter(Boolean) as Plugins[];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;;;;AAqBA,MAAa,kBACX,QACA,WAAoB,SAEpB;CACE,QAAQ,IAAI,mCAAmC,WAC7CA,yDACE,UAAUC,+BAAc,qBAAqB,eAC7C,WAAWA,+BAAc,qBAAqB,gBAAgB,OAC/D;CACH,QAAQ,IAAI,mCAAmC,WAAWC;CAC1D,QAAQ,IAAI,iCAAiC,WAAWC;CACxD,QAAQ,IAAI,iCAAiC,WAAWC;CACxD,QAAQ,IAAI,8BAA8B,WACxCC,oDAAa,UAAUJ,+BAAc,qBAAqB,cAAc;CAC1E,QAAQ,IAAI,4BAA4B,WAAWK;CACnD,QAAQ,IAAI,8BAA8B,WAAWC;CACtD,CAAC,OAAO,QAAQ;;;;;;;AAQnB,MAAa,cAIX,MACA,WACA,UAAqB,EAAE,KAEvBC,+DAAkB,MAAM;CACtB,GAAG;CACH;CACD,CAAC"}
@@ -5,46 +5,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  * Check if a value is a complex object (not a primitive)
6
6
  * Used to determine if values need to be wrapped in fragments
7
7
  */
8
- const isComplexValue = (value) => {
9
- return value !== null && value !== void 0 && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean";
10
- };
11
- /**
12
- * Core logic for splitting insertion strings and joining with values.
13
- * Returns an array of parts that can be wrapped by framework-specific Fragment implementations.
14
- *
15
- * @param template - The template string with {{ placeholder }} syntax
16
- * @param values - Map of placeholder names to their replacement values
17
- * @returns Object with `isSimple` flag and `parts` array
18
- *
19
- * @example
20
- * ```ts
21
- * const result = splitInsertionTemplate('Hello {{ name }}!', { name: 'World' });
22
- * // { isSimple: true, parts: 'Hello World!' }
23
- *
24
- * const result = splitInsertionTemplate('Hello {{ name }}!', { name: <Component /> });
25
- * // { isSimple: false, parts: ['Hello ', <Component />, '!'] }
26
- * ```
27
- */
8
+ const isComplexValue = (value) => value != null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean";
9
+ const insertionRegex = /\{\{\s*(.*?)\s*\}\}/g;
28
10
  const splitInsertionTemplate = (template, values = {}) => {
29
- const safeValues = values ?? {};
30
- if (!Object.values(safeValues).some(isComplexValue)) return {
11
+ if (!Object.values(values).some(isComplexValue)) return {
31
12
  isSimple: true,
32
- parts: template.replace(/\{\{\s*(.*?)\s*\}\}/g, (_, key) => {
33
- return (safeValues[key.trim()] ?? "").toString();
34
- })
13
+ parts: template.replace(insertionRegex, (_, key) => (values[key.trim()] ?? "").toString())
35
14
  };
15
+ const chunks = template.split(insertionRegex);
36
16
  const parts = [];
37
- let lastIndex = 0;
38
- const regex = /\{\{\s*(.*?)\s*\}\}/g;
39
- let match = regex.exec(template);
40
- while (match !== null) {
41
- if (match.index > lastIndex) parts.push(template.substring(lastIndex, match.index));
42
- const value = safeValues[match[1].trim()];
43
- if (value !== void 0 && value !== null) parts.push(value);
44
- lastIndex = match.index + match[0].length;
45
- match = regex.exec(template);
17
+ for (let i = 0; i < chunks.length; i++) if (i % 2 === 0) {
18
+ if (chunks[i]) parts.push(chunks[i]);
19
+ } else {
20
+ const val = values[chunks[i].trim()];
21
+ if (val != null) parts.push(val);
46
22
  }
47
- if (lastIndex < template.length) parts.push(template.substring(lastIndex));
48
23
  return {
49
24
  isSimple: false,
50
25
  parts
@@ -1 +1 @@
1
- {"version":3,"file":"splitAndJoinInsertion.cjs","names":[],"sources":["../../../src/interpreter/splitAndJoinInsertion.ts"],"sourcesContent":["/**\n * Check if a value is a complex object (not a primitive)\n * Used to determine if values need to be wrapped in fragments\n */\nconst isComplexValue = (value: any): boolean => {\n return (\n value !== null &&\n value !== undefined &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean'\n );\n};\n\n/**\n * Core logic for splitting insertion strings and joining with values.\n * Returns an array of parts that can be wrapped by framework-specific Fragment implementations.\n *\n * @param template - The template string with {{ placeholder }} syntax\n * @param values - Map of placeholder names to their replacement values\n * @returns Object with `isSimple` flag and `parts` array\n *\n * @example\n * ```ts\n * const result = splitInsertionTemplate('Hello {{ name }}!', { name: 'World' });\n * // { isSimple: true, parts: 'Hello World!' }\n *\n * const result = splitInsertionTemplate('Hello {{ name }}!', { name: <Component /> });\n * // { isSimple: false, parts: ['Hello ', <Component />, '!'] }\n * ```\n */\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n const safeValues = values ?? {};\n\n // Check if any value is a complex object (React/Vue node, etc.)\n const hasComplexValue = Object.values(safeValues).some(isComplexValue);\n\n if (!hasComplexValue) {\n // Simple string replacement\n const result = template.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n return (safeValues[trimmedKey] ?? '').toString();\n });\n return { isSimple: true, parts: result };\n }\n\n // Split the template by placeholders while keeping the structure\n const parts: any[] = [];\n let lastIndex = 0;\n const regex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n let match: RegExpExecArray | null = regex.exec(template);\n\n while (match !== null) {\n // Add text before the placeholder\n if (match.index > lastIndex) {\n parts.push(template.substring(lastIndex, match.index));\n }\n\n // Add the replaced value\n const key = match[1].trim();\n const value = safeValues[key];\n if (value !== undefined && value !== null) {\n parts.push(value);\n }\n\n lastIndex = match.index + match[0].length;\n match = regex.exec(template);\n }\n\n // Add remaining text\n if (lastIndex < template.length) {\n parts.push(template.substring(lastIndex));\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":";;;;;;;AAIA,MAAM,kBAAkB,UAAwB;AAC9C,QACE,UAAU,QACV,UAAU,UACV,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;;;;;;;;;;;;;;;;;;;AAqBrB,MAAa,0BACX,UACA,SAA4B,EAAE,KACiB;CAC/C,MAAM,aAAa,UAAU,EAAE;AAK/B,KAAI,CAFoB,OAAO,OAAO,WAAW,CAAC,KAAK,eAAe,CAQpE,QAAO;EAAE,UAAU;EAAM,OAJV,SAAS,QAAQ,yBAAyB,GAAG,QAAQ;AAElE,WAAQ,WADW,IAAI,MAAM,KACK,IAAI,UAAU;IAChD;EACsC;CAI1C,MAAM,QAAe,EAAE;CACvB,IAAI,YAAY;CAChB,MAAM,QAAQ;CACd,IAAI,QAAgC,MAAM,KAAK,SAAS;AAExD,QAAO,UAAU,MAAM;AAErB,MAAI,MAAM,QAAQ,UAChB,OAAM,KAAK,SAAS,UAAU,WAAW,MAAM,MAAM,CAAC;EAKxD,MAAM,QAAQ,WADF,MAAM,GAAG,MAAM;AAE3B,MAAI,UAAU,UAAa,UAAU,KACnC,OAAM,KAAK,MAAM;AAGnB,cAAY,MAAM,QAAQ,MAAM,GAAG;AACnC,UAAQ,MAAM,KAAK,SAAS;;AAI9B,KAAI,YAAY,SAAS,OACvB,OAAM,KAAK,SAAS,UAAU,UAAU,CAAC;AAG3C,QAAO;EAAE,UAAU;EAAO;EAAO"}
1
+ {"version":3,"file":"splitAndJoinInsertion.cjs","names":[],"sources":["../../../src/interpreter/splitAndJoinInsertion.ts"],"sourcesContent":["/**\n * Check if a value is a complex object (not a primitive)\n * Used to determine if values need to be wrapped in fragments\n */\nconst isComplexValue = (value: any): boolean =>\n value != null &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean';\n\n// Hoisted: replace/split do not suffer from the stateful lastIndex mutation of .exec()\nconst insertionRegex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n if (!Object.values(values).some(isComplexValue)) {\n return {\n isSimple: true,\n parts: template.replace(insertionRegex, (_, key) =>\n (values[key.trim()] ?? '').toString()\n ),\n };\n }\n\n const chunks = template.split(insertionRegex);\n const parts: any[] = [];\n\n for (let i = 0; i < chunks.length; i++) {\n if (i % 2 === 0) {\n if (chunks[i]) parts.push(chunks[i]);\n } else {\n const val = values[chunks[i].trim()];\n if (val != null) parts.push(val);\n }\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":";;;;;;;AAIA,MAAM,kBAAkB,UACtB,SAAS,QACT,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAGnB,MAAM,iBAAiB;AAEvB,MAAa,0BACX,UACA,SAA4B,EAAE,KACiB;AAC/C,KAAI,CAAC,OAAO,OAAO,OAAO,CAAC,KAAK,eAAe,CAC7C,QAAO;EACL,UAAU;EACV,OAAO,SAAS,QAAQ,iBAAiB,GAAG,SACzC,OAAO,IAAI,MAAM,KAAK,IAAI,UAAU,CACtC;EACF;CAGH,MAAM,SAAS,SAAS,MAAM,eAAe;CAC7C,MAAM,QAAe,EAAE;AAEvB,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,KAAI,IAAI,MAAM,GACZ;MAAI,OAAO,GAAI,OAAM,KAAK,OAAO,GAAG;QAC/B;EACL,MAAM,MAAM,OAAO,OAAO,GAAG,MAAM;AACnC,MAAI,OAAO,KAAM,OAAM,KAAK,IAAI;;AAIpC,QAAO;EAAE,UAAU;EAAO;EAAO"}
@@ -0,0 +1,111 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_localization_getPrefix = require('./getPrefix.cjs');
3
+ const require_localization_getMultilingualUrls = require('./getMultilingualUrls.cjs');
4
+
5
+ //#region src/localization/generateSitemap.ts
6
+ /**
7
+ * Returns whether xhtml:link alternate tags should be generated for the given routing mode.
8
+ *
9
+ * Alternates are meaningful only when locale URLs are distinct:
10
+ * - 'no-prefix' produces identical URLs for all locales → no alternates
11
+ * - all other modes produce distinct URLs → alternates are generated
12
+ */
13
+ const shouldIncludeAlternates = (mode, xhtmlLinks) => xhtmlLinks && mode !== "no-prefix";
14
+ /**
15
+ * Generates a single `<url>` sitemap entry for the given path.
16
+ *
17
+ * Example:
18
+ *
19
+ * ```ts
20
+ * generateSitemapUrl('/dashboard', {
21
+ * siteUrl: 'https://example.com',
22
+ * changefreq: 'weekly',
23
+ * priority: 0.8,
24
+ * xhtmlLinks: true,
25
+ * locales: ['en', 'fr'],
26
+ * defaultLocale: 'en',
27
+ * mode: 'prefix-no-default',
28
+ * });
29
+ * // Returns:
30
+ * // <url>
31
+ * // <loc>https://example.com/dashboard</loc>
32
+ * // <changefreq>weekly</changefreq>
33
+ * // <priority>0.8</priority>
34
+ * // <xhtml:link rel="alternate" hrefLang="en" href="https://example.com/dashboard"/>
35
+ * // <xhtml:link rel="alternate" hrefLang="fr" href="https://example.com/fr/dashboard"/>
36
+ * // <xhtml:link rel="alternate" hrefLang="x-default" href="https://example.com/dashboard"/>
37
+ * // </url>
38
+ * ```
39
+ *
40
+ * @param path - The canonical path to generate the entry for.
41
+ * @param options - Configuration options.
42
+ * @returns A `<url>` XML string.
43
+ */
44
+ const generateSitemapUrl = (path, options) => {
45
+ const { siteUrl, changefreq, priority, lastmod, xhtmlLinks = true, ...routingOptions } = options;
46
+ const resolved = require_localization_getPrefix.resolveRoutingConfig(routingOptions);
47
+ const fullUrl = `${siteUrl}${path}`;
48
+ const lines = [
49
+ " <url>",
50
+ ` <loc>${fullUrl}</loc>`,
51
+ lastmod ? ` <lastmod>${lastmod}</lastmod>` : null,
52
+ changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,
53
+ priority !== void 0 ? ` <priority>${priority}</priority>` : null
54
+ ];
55
+ if (shouldIncludeAlternates(resolved.mode, xhtmlLinks)) {
56
+ const alternates = require_localization_getMultilingualUrls.getMultilingualUrls(path, routingOptions);
57
+ for (const [lang, localePath] of Object.entries(alternates)) lines.push(` <xhtml:link rel="alternate" hrefLang="${lang}" href="${siteUrl}${localePath}"/>`);
58
+ lines.push(` <xhtml:link rel="alternate" hrefLang="x-default" href="${fullUrl}"/>`);
59
+ }
60
+ lines.push(" </url>");
61
+ return lines.filter(Boolean).join("\n");
62
+ };
63
+ /**
64
+ * Generates a full XML sitemap string from an array of URL entries.
65
+ *
66
+ * Automatically adds `xmlns:xhtml` to the `<urlset>` declaration when
67
+ * xhtml:link alternate tags are included.
68
+ *
69
+ * Example:
70
+ *
71
+ * ```ts
72
+ * generateSitemap(
73
+ * [
74
+ * { path: '/', changefreq: 'daily', priority: 1.0 },
75
+ * { path: '/about', changefreq: 'monthly', priority: 0.5 },
76
+ * ],
77
+ * {
78
+ * siteUrl: 'https://example.com',
79
+ * xhtmlLinks: true,
80
+ * locales: ['en', 'fr'],
81
+ * defaultLocale: 'en',
82
+ * mode: 'prefix-no-default',
83
+ * }
84
+ * );
85
+ * ```
86
+ *
87
+ * @param entries - Array of URL entries to include in the sitemap.
88
+ * @param options - Sitemap generation options.
89
+ * @returns A full XML sitemap string.
90
+ */
91
+ const generateSitemap = (entries, options) => {
92
+ const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;
93
+ const includeAlternates = shouldIncludeAlternates(require_localization_getPrefix.resolveRoutingConfig(routingOptions).mode, xhtmlLinks);
94
+ const xmlEntries = entries.map((entry) => generateSitemapUrl(entry.path, {
95
+ ...entry,
96
+ siteUrl,
97
+ xhtmlLinks,
98
+ ...routingOptions
99
+ }));
100
+ return `<?xml version="1.0" encoding="UTF-8"?>
101
+ <urlset
102
+ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${includeAlternates ? "\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"" : ""}
103
+ >
104
+ ${xmlEntries.join("\n")}
105
+ </urlset>`;
106
+ };
107
+
108
+ //#endregion
109
+ exports.generateSitemap = generateSitemap;
110
+ exports.generateSitemapUrl = generateSitemapUrl;
111
+ //# sourceMappingURL=generateSitemap.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateSitemap.cjs","names":["resolveRoutingConfig","getMultilingualUrls"],"sources":["../../../src/localization/generateSitemap.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getMultilingualUrls } from './getMultilingualUrls';\nimport { type RoutingOptions, resolveRoutingConfig } from './getPrefix';\n\nexport type SitemapUrlEntry = {\n /** The canonical path, e.g. '/dashboard' */\n path: string;\n changefreq?: string;\n priority?: number;\n /** ISO date string, e.g. '2024-01-15' */\n lastmod?: string;\n};\n\nexport type GenerateSitemapOptions = {\n /** Base site URL without trailing slash, e.g. 'https://example.com' */\n siteUrl: string;\n /**\n * Whether to include xhtml:link alternate tags for multilingual support.\n *\n * When enabled, alternate links are only generated for modes where URLs\n * differ per locale:\n * - 'prefix-no-default': included\n * - 'prefix-all': included\n * - 'search-params': included\n * - 'no-prefix': excluded (all locales share the same URL)\n *\n * @default true\n */\n xhtmlLinks?: boolean;\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n};\n\n/**\n * Returns whether xhtml:link alternate tags should be generated for the given routing mode.\n *\n * Alternates are meaningful only when locale URLs are distinct:\n * - 'no-prefix' produces identical URLs for all locales → no alternates\n * - all other modes produce distinct URLs → alternates are generated\n */\nconst shouldIncludeAlternates = (\n mode: RoutingConfig['mode'],\n xhtmlLinks: boolean\n): boolean => xhtmlLinks && mode !== 'no-prefix';\n\n/**\n * Generates a single `<url>` sitemap entry for the given path.\n *\n * Example:\n *\n * ```ts\n * generateSitemapUrl('/dashboard', {\n * siteUrl: 'https://example.com',\n * changefreq: 'weekly',\n * priority: 0.8,\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * });\n * // Returns:\n * // <url>\n * // <loc>https://example.com/dashboard</loc>\n * // <changefreq>weekly</changefreq>\n * // <priority>0.8</priority>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"en\" href=\"https://example.com/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"fr\" href=\"https://example.com/fr/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"x-default\" href=\"https://example.com/dashboard\"/>\n * // </url>\n * ```\n *\n * @param path - The canonical path to generate the entry for.\n * @param options - Configuration options.\n * @returns A `<url>` XML string.\n */\nexport const generateSitemapUrl = (\n path: string,\n options: SitemapUrlEntry & GenerateSitemapOptions\n): string => {\n const {\n siteUrl,\n changefreq,\n priority,\n lastmod,\n xhtmlLinks = true,\n ...routingOptions\n } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const fullUrl = `${siteUrl}${path}`;\n\n const lines: (string | null)[] = [\n ' <url>',\n ` <loc>${fullUrl}</loc>`,\n lastmod ? ` <lastmod>${lastmod}</lastmod>` : null,\n changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,\n priority !== undefined ? ` <priority>${priority}</priority>` : null,\n ];\n\n if (shouldIncludeAlternates(resolved.mode, xhtmlLinks)) {\n const alternates = getMultilingualUrls(\n path,\n routingOptions as RoutingOptions\n );\n\n for (const [lang, localePath] of Object.entries(alternates)) {\n lines.push(\n ` <xhtml:link rel=\"alternate\" hrefLang=\"${lang}\" href=\"${siteUrl}${localePath}\"/>`\n );\n }\n\n lines.push(\n ` <xhtml:link rel=\"alternate\" hrefLang=\"x-default\" href=\"${fullUrl}\"/>`\n );\n }\n\n lines.push(' </url>');\n\n return lines.filter(Boolean).join('\\n');\n};\n\n/**\n * Generates a full XML sitemap string from an array of URL entries.\n *\n * Automatically adds `xmlns:xhtml` to the `<urlset>` declaration when\n * xhtml:link alternate tags are included.\n *\n * Example:\n *\n * ```ts\n * generateSitemap(\n * [\n * { path: '/', changefreq: 'daily', priority: 1.0 },\n * { path: '/about', changefreq: 'monthly', priority: 0.5 },\n * ],\n * {\n * siteUrl: 'https://example.com',\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * }\n * );\n * ```\n *\n * @param entries - Array of URL entries to include in the sitemap.\n * @param options - Sitemap generation options.\n * @returns A full XML sitemap string.\n */\nexport const generateSitemap = (\n entries: SitemapUrlEntry[],\n options: GenerateSitemapOptions\n): string => {\n const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const includeAlternates = shouldIncludeAlternates(resolved.mode, xhtmlLinks);\n\n const xmlEntries = entries.map((entry) =>\n generateSitemapUrl(entry.path, {\n ...entry,\n siteUrl,\n xhtmlLinks,\n ...routingOptions,\n })\n );\n\n const xmlns = includeAlternates\n ? '\\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"'\n : '';\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"${xmlns}\n>\n${xmlEntries.join('\\n')}\n</urlset>`;\n};\n"],"mappings":";;;;;;;;;;;;AA2CA,MAAM,2BACJ,MACA,eACY,cAAc,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCrC,MAAa,sBACX,MACA,YACW;CACX,MAAM,EACJ,SACA,YACA,UACA,SACA,aAAa,MACb,GAAG,mBACD;CAEJ,MAAM,WAAWA,oDAAqB,eAAiC;CACvE,MAAM,UAAU,GAAG,UAAU;CAE7B,MAAM,QAA2B;EAC/B;EACA,YAAY,QAAQ;EACpB,UAAU,gBAAgB,QAAQ,cAAc;EAChD,aAAa,mBAAmB,WAAW,iBAAiB;EAC5D,aAAa,SAAY,iBAAiB,SAAS,eAAe;EACnE;AAED,KAAI,wBAAwB,SAAS,MAAM,WAAW,EAAE;EACtD,MAAM,aAAaC,6DACjB,MACA,eACD;AAED,OAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,WAAW,CACzD,OAAM,KACJ,6CAA6C,KAAK,UAAU,UAAU,WAAW,KAClF;AAGH,QAAM,KACJ,8DAA8D,QAAQ,KACvE;;AAGH,OAAM,KAAK,WAAW;AAEtB,QAAO,MAAM,OAAO,QAAQ,CAAC,KAAK,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BzC,MAAa,mBACX,SACA,YACW;CACX,MAAM,EAAE,SAAS,aAAa,MAAM,GAAG,mBAAmB;CAG1D,MAAM,oBAAoB,wBADTD,oDAAqB,eAAiC,CACZ,MAAM,WAAW;CAE5E,MAAM,aAAa,QAAQ,KAAK,UAC9B,mBAAmB,MAAM,MAAM;EAC7B,GAAG;EACH;EACA;EACA,GAAG;EACJ,CAAC,CACH;AAMD,QAAO;;uDAJO,oBACV,qDACA,GAIuD;;EAE3D,WAAW,KAAK,KAAK,CAAC"}
@@ -55,7 +55,7 @@ const detectLanguage = (order, options) => {
55
55
  };
56
56
  const storageDetector = () => {
57
57
  if (typeof window === "undefined") return;
58
- const locale = require_utils_localeStorage.getLocaleFromStorage({
58
+ const locale = require_utils_localeStorage.getLocaleFromStorageClient({
59
59
  getCookie: (name) => {
60
60
  try {
61
61
  const cookies = document.cookie.split(";");
@@ -1 +1 @@
1
- {"version":3,"file":"getBrowserLocale.cjs","names":["getLocaleFromStorage","configuration","localeDetector","ENGLISH"],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport {\n getLocaleFromStorage,\n type LocaleStorageOptions,\n} from '../utils/localeStorage';\nimport { localeDetector } from './localeDetector';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Storage = 'storage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\nexport const localeStorageOptions: LocaleStorageOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Storage,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n htmlTag: typeof document !== 'undefined' ? document.documentElement : null,\n };\n};\n\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locale | undefined> => {\n const detected: Record<LanguageDetector, Locale | undefined> = {} as Record<\n LanguageDetector,\n Locale | undefined\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locale;\n }\n };\n\n const storageDetector = () => {\n if (typeof window === 'undefined') return;\n\n const locale = getLocaleFromStorage({\n getCookie: (name: string) => {\n try {\n const cookies = document.cookie.split(';');\n const cookieName = `${name}=`;\n\n const cookie = cookies.find((cookie) =>\n cookie.trim().startsWith(cookieName)\n );\n\n if (cookie) {\n return cookie.split('=')[1].trim();\n }\n } catch {}\n return undefined;\n },\n getSessionStorage: (name: string) => {\n try {\n return window.sessionStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n getLocaleStorage: (name: string) => {\n try {\n return window.localStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n });\n\n if (locale) {\n detected[LanguageDetector.Storage] = locale;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n const { internationalization } = configuration;\n const languages = navigator.languages ?? [navigator.language];\n\n // Use localeDetector to find the best matching locale\n const locale = localeDetector(\n { 'accept-language': languages.join(',') },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n if (locale) {\n detected[LanguageDetector.Navigator] = locale;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n const { internationalization } = configuration;\n\n // Validate and resolve the locale\n const locale = localeDetector(\n { 'accept-language': lang },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n detected[LanguageDetector.HtmlTag] = locale;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Storage]: storageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locale | undefined>,\n order: LanguageDetector[]\n): Locale => {\n const { internationalization } = configuration;\n\n for (const detector of order) {\n const locale = locales[detector];\n\n if (locale && internationalization.locales.includes(locale)) {\n return locale;\n }\n }\n\n return internationalization?.defaultLocale ?? ENGLISH;\n};\n\n/**\n * Core language detector function for browser environments.\n *\n * Detects the user's preferred locale by checking multiple sources in order:\n * 1. Query string parameter\n * 2. Storage (cookies, localStorage, sessionStorage) - uses getLocaleFromStorage\n * 3. Navigator languages - uses localeDetector\n * 4. HTML lang attribute - uses localeDetector\n *\n * @param userOptions - Optional configuration for detection order and lookup keys\n * @returns The detected locale or the default locale\n *\n * @example\n * const locale = getBrowserLocale({ order: [LanguageDetector.Storage, LanguageDetector.Navigator] });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locale => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"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"}
1
+ {"version":3,"file":"getBrowserLocale.cjs","names":["getLocaleFromStorageClient","configuration","localeDetector","ENGLISH"],"sources":["../../../src/localization/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport {\n getLocaleFromStorageClient,\n type LocaleStorageClientOptions,\n} from '../utils/localeStorage';\nimport { localeDetector } from './localeDetector';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Storage = 'storage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\nexport const localeStorageOptions: LocaleStorageClientOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Storage,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n htmlTag: typeof document !== 'undefined' ? document.documentElement : null,\n };\n};\n\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locale | undefined> => {\n const detected: Record<LanguageDetector, Locale | undefined> = {} as Record<\n LanguageDetector,\n Locale | undefined\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locale;\n }\n };\n\n const storageDetector = () => {\n if (typeof window === 'undefined') return;\n\n const locale = getLocaleFromStorageClient({\n getCookie: (name: string) => {\n try {\n const cookies = document.cookie.split(';');\n const cookieName = `${name}=`;\n\n const cookie = cookies.find((cookie) =>\n cookie.trim().startsWith(cookieName)\n );\n\n if (cookie) {\n return cookie.split('=')[1].trim();\n }\n } catch {}\n return undefined;\n },\n getSessionStorage: (name: string) => {\n try {\n return window.sessionStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n getLocaleStorage: (name: string) => {\n try {\n return window.localStorage.getItem(name) ?? undefined;\n } catch {}\n return undefined;\n },\n });\n\n if (locale) {\n detected[LanguageDetector.Storage] = locale;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n const { internationalization } = configuration;\n const languages = navigator.languages ?? [navigator.language];\n\n // Use localeDetector to find the best matching locale\n const locale = localeDetector(\n { 'accept-language': languages.join(',') },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n if (locale) {\n detected[LanguageDetector.Navigator] = locale;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n const { internationalization } = configuration;\n\n // Validate and resolve the locale\n const locale = localeDetector(\n { 'accept-language': lang },\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n detected[LanguageDetector.HtmlTag] = locale;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Storage]: storageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locale | undefined>,\n order: LanguageDetector[]\n): Locale => {\n const { internationalization } = configuration;\n\n for (const detector of order) {\n const locale = locales[detector];\n\n if (locale && internationalization.locales.includes(locale)) {\n return locale;\n }\n }\n\n return internationalization?.defaultLocale ?? ENGLISH;\n};\n\n/**\n * Core language detector function for browser environments.\n *\n * Detects the user's preferred locale by checking multiple sources in order:\n * 1. Query string parameter\n * 2. Storage (cookies, localStorage, sessionStorage) - uses getLocaleFromStorage\n * 3. Navigator languages - uses localeDetector\n * 4. HTML lang attribute - uses localeDetector\n *\n * @param userOptions - Optional configuration for detection order and lookup keys\n * @returns The detected locale or the default locale\n *\n * @example\n * const locale = getBrowserLocale({ order: [LanguageDetector.Storage, LanguageDetector.Navigator] });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locale => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"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"}