@intlayer/core 8.5.2 → 8.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) 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 +17 -9
  19. package/dist/cjs/interpreter/getContent/getContent.cjs +1 -1
  20. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  21. package/dist/cjs/interpreter/getContent/index.cjs +1 -0
  22. package/dist/cjs/interpreter/getContent/plugins.cjs +20 -9
  23. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  24. package/dist/cjs/interpreter/index.cjs +1 -0
  25. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +10 -35
  26. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
  27. package/dist/cjs/localization/generateSitemap.cjs +111 -0
  28. package/dist/cjs/localization/generateSitemap.cjs.map +1 -0
  29. package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
  30. package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
  31. package/dist/cjs/localization/getLocale.cjs +2 -2
  32. package/dist/cjs/localization/getLocale.cjs.map +1 -1
  33. package/dist/cjs/localization/getLocalizedUrl.cjs +1 -1
  34. package/dist/cjs/localization/getPrefix.cjs +1 -1
  35. package/dist/cjs/localization/index.cjs +8 -7
  36. package/dist/cjs/localization/localeMapper.cjs +1 -1
  37. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +2 -3
  38. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
  39. package/dist/cjs/utils/index.cjs +9 -3
  40. package/dist/cjs/utils/intl.cjs +88 -72
  41. package/dist/cjs/utils/intl.cjs.map +1 -1
  42. package/dist/cjs/utils/localeStorage.cjs +191 -64
  43. package/dist/cjs/utils/localeStorage.cjs.map +1 -1
  44. package/dist/esm/formatters/compact.mjs +2 -2
  45. package/dist/esm/formatters/compact.mjs.map +1 -1
  46. package/dist/esm/formatters/currency.mjs +2 -2
  47. package/dist/esm/formatters/currency.mjs.map +1 -1
  48. package/dist/esm/formatters/date.mjs +2 -2
  49. package/dist/esm/formatters/date.mjs.map +1 -1
  50. package/dist/esm/formatters/index.mjs +2 -2
  51. package/dist/esm/formatters/list.mjs +2 -2
  52. package/dist/esm/formatters/list.mjs.map +1 -1
  53. package/dist/esm/formatters/number.mjs +2 -2
  54. package/dist/esm/formatters/number.mjs.map +1 -1
  55. package/dist/esm/formatters/percentage.mjs +3 -3
  56. package/dist/esm/formatters/percentage.mjs.map +1 -1
  57. package/dist/esm/formatters/relativeTime.mjs +2 -2
  58. package/dist/esm/formatters/relativeTime.mjs.map +1 -1
  59. package/dist/esm/formatters/units.mjs +2 -2
  60. package/dist/esm/formatters/units.mjs.map +1 -1
  61. package/dist/esm/index.mjs +11 -11
  62. package/dist/esm/interpreter/getContent/getContent.mjs +1 -1
  63. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  64. package/dist/esm/interpreter/getContent/index.mjs +2 -2
  65. package/dist/esm/interpreter/getContent/plugins.mjs +20 -10
  66. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  67. package/dist/esm/interpreter/index.mjs +2 -2
  68. package/dist/esm/interpreter/splitAndJoinInsertion.mjs +10 -35
  69. package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
  70. package/dist/esm/localization/generateSitemap.mjs +109 -0
  71. package/dist/esm/localization/generateSitemap.mjs.map +1 -0
  72. package/dist/esm/localization/getBrowserLocale.mjs +2 -2
  73. package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
  74. package/dist/esm/localization/getLocale.mjs +3 -3
  75. package/dist/esm/localization/getLocale.mjs.map +1 -1
  76. package/dist/esm/localization/getLocalizedUrl.mjs +1 -1
  77. package/dist/esm/localization/getPrefix.mjs +1 -1
  78. package/dist/esm/localization/index.mjs +7 -7
  79. package/dist/esm/localization/localeMapper.mjs +1 -1
  80. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +2 -4
  81. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
  82. package/dist/esm/utils/index.mjs +4 -4
  83. package/dist/esm/utils/intl.mjs +87 -72
  84. package/dist/esm/utils/intl.mjs.map +1 -1
  85. package/dist/esm/utils/localeStorage.mjs +186 -65
  86. package/dist/esm/utils/localeStorage.mjs.map +1 -1
  87. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +10 -10
  88. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
  89. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +10 -10
  90. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
  91. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +10 -10
  92. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
  93. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
  94. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
  95. package/dist/types/formatters/index.d.ts +2 -2
  96. package/dist/types/formatters/number.d.ts +4 -1
  97. package/dist/types/formatters/number.d.ts.map +1 -1
  98. package/dist/types/formatters/percentage.d.ts +4 -1
  99. package/dist/types/formatters/percentage.d.ts.map +1 -1
  100. package/dist/types/index.d.ts +5 -5
  101. package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
  102. package/dist/types/interpreter/getContent/index.d.ts +2 -2
  103. package/dist/types/interpreter/getContent/plugins.d.ts +7 -1
  104. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  105. package/dist/types/interpreter/index.d.ts +2 -2
  106. package/dist/types/interpreter/splitAndJoinInsertion.d.ts +0 -17
  107. package/dist/types/interpreter/splitAndJoinInsertion.d.ts.map +1 -1
  108. package/dist/types/localization/generateSitemap.d.ts +93 -0
  109. package/dist/types/localization/generateSitemap.d.ts.map +1 -0
  110. package/dist/types/localization/getBrowserLocale.d.ts +2 -2
  111. package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
  112. package/dist/types/localization/index.d.ts +2 -2
  113. package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -1
  114. package/dist/types/utils/index.d.ts +3 -3
  115. package/dist/types/utils/intl.d.ts +15 -11
  116. package/dist/types/utils/intl.d.ts.map +1 -1
  117. package/dist/types/utils/localeStorage.d.ts +85 -68
  118. package/dist/types/utils/localeStorage.d.ts.map +1 -1
  119. package/package.json +8 -8
  120. package/dist/cjs/getStorageAttributes.cjs +0 -135
  121. package/dist/cjs/getStorageAttributes.cjs.map +0 -1
  122. package/dist/esm/getStorageAttributes.mjs +0 -133
  123. package/dist/esm/getStorageAttributes.mjs.map +0 -1
  124. package/dist/types/getStorageAttributes.d.ts +0 -29
  125. 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;
@@ -187,6 +188,7 @@ exports.deepTransformNode = require_interpreter_getContent_deepTransform.deepTra
187
188
  exports.editDictionaryByKeyPath = require_dictionaryManipulator_editDictionaryByKeyPath.editDictionaryByKeyPath;
188
189
  exports.enu = require_transpiler_enumeration_enumeration.enu;
189
190
  exports.enumerationPlugin = require_interpreter_getContent_plugins.enumerationPlugin;
191
+ exports.fallbackPlugin = require_interpreter_getContent_plugins.fallbackPlugin;
190
192
  exports.filePlugin = require_interpreter_getContent_plugins.filePlugin;
191
193
  exports.filterMissingTranslationsOnlyPlugin = require_deepTransformPlugins_getFilterMissingTranslationsContent.filterMissingTranslationsOnlyPlugin;
192
194
  exports.filterTranslationsOnlyPlugin = require_deepTransformPlugins_getFilterTranslationsOnlyContent.filterTranslationsOnlyPlugin;
@@ -197,9 +199,12 @@ exports.generateListItemPrefix = require_markdown_constants.generateListItemPref
197
199
  exports.generateListItemPrefixRegex = require_markdown_constants.generateListItemPrefixRegex;
198
200
  exports.generateListItemRegex = require_markdown_constants.generateListItemRegex;
199
201
  exports.generateListRegex = require_markdown_constants.generateListRegex;
202
+ exports.generateSitemap = require_localization_generateSitemap.generateSitemap;
203
+ exports.generateSitemapUrl = require_localization_generateSitemap.generateSitemapUrl;
200
204
  exports.get = require_markdown_utils.get;
201
205
  exports.getBasePlugins = require_interpreter_getContent_getContent.getBasePlugins;
202
206
  exports.getBrowserLocale = require_localization_getBrowserLocale.getBrowserLocale;
207
+ exports.getCachedIntl = require_utils_intl.getCachedIntl;
203
208
  exports.getCanonicalPath = require_localization_rewriteUtils.getCanonicalPath;
204
209
  exports.getCondition = require_interpreter_getCondition.getCondition;
205
210
  exports.getContent = require_interpreter_getContent_getContent.getContent;
@@ -223,6 +228,8 @@ exports.getIntlayer = require_interpreter_getIntlayer.getIntlayer;
223
228
  exports.getLocale = require_localization_getLocale.getLocale;
224
229
  exports.getLocaleFromPath = require_localization_getLocaleFromPath.getLocaleFromPath;
225
230
  exports.getLocaleFromStorage = require_utils_localeStorage.getLocaleFromStorage;
231
+ exports.getLocaleFromStorageClient = require_utils_localeStorage.getLocaleFromStorageClient;
232
+ exports.getLocaleFromStorageServer = require_utils_localeStorage.getLocaleFromStorageServer;
226
233
  exports.getLocaleLang = require_localization_getLocaleLang.getLocaleLang;
227
234
  exports.getLocaleName = require_localization_getLocaleName.getLocaleName;
228
235
  exports.getLocalizedContent = require_deepTransformPlugins_getLocalizedContent.getLocalizedContent;
@@ -245,7 +252,6 @@ exports.getRewritePath = require_localization_rewriteUtils.getRewritePath;
245
252
  exports.getRewriteRules = require_localization_rewriteUtils.getRewriteRules;
246
253
  exports.getSplittedContent = require_deepTransformPlugins_getSplittedContent.getSplittedContent;
247
254
  exports.getSplittedDictionaryContent = require_deepTransformPlugins_getSplittedContent.getSplittedDictionaryContent;
248
- exports.getStorageAttributes = require_getStorageAttributes.getStorageAttributes;
249
255
  exports.getTranslation = require_interpreter_getTranslation.getTranslation;
250
256
  exports.html = require_transpiler_html_html.html;
251
257
  exports.i18nextToIntlayerFormatter = require_messageFormat_i18next.i18nextToIntlayerFormatter;
@@ -297,6 +303,8 @@ exports.renderFor = require_markdown_renderer.renderFor;
297
303
  exports.renderNothing = require_markdown_utils.renderNothing;
298
304
  exports.sanitizer = require_markdown_utils.sanitizer;
299
305
  exports.setLocaleInStorage = require_utils_localeStorage.setLocaleInStorage;
306
+ exports.setLocaleInStorageClient = require_utils_localeStorage.setLocaleInStorageClient;
307
+ exports.setLocaleInStorageServer = require_utils_localeStorage.setLocaleInStorageServer;
300
308
  exports.simpleInlineRegex = require_markdown_utils.simpleInlineRegex;
301
309
  exports.slugify = require_markdown_utils.slugify;
302
310
  exports.some = require_markdown_utils.some;
@@ -14,7 +14,7 @@ const getBasePlugins = (locale, fallback = true) => [
14
14
  require_interpreter_getContent_plugins.nestedPlugin(locale ?? _intlayer_config_built.default.internationalization.defaultLocale),
15
15
  require_interpreter_getContent_plugins.filePlugin,
16
16
  require_interpreter_getContent_plugins.genderPlugin
17
- ];
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 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 ].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;CACEA,yDACE,UAAUC,+BAAc,qBAAqB,eAC7C,WAAWA,+BAAc,qBAAqB,gBAAgB,OAC/D;CACDC;CACAC;CACAC;CACAC,oDAAa,UAAUJ,+BAAc,qBAAqB,cAAc;CACxEK;CACAC;CACD,CAAC,OAAO,QAAQ;;;;;;;AAQnB,MAAa,cAIX,MACA,WACA,UAAqB,EAAE,KAEvBC,+DAAkB,MAAM;CACtB,GAAG;CACH;CACD,CAAC"}
@@ -6,6 +6,7 @@ const require_interpreter_getContent_getContent = require('./getContent.cjs');
6
6
  exports.conditionPlugin = require_interpreter_getContent_plugins.conditionPlugin;
7
7
  exports.deepTransformNode = require_interpreter_getContent_deepTransform.deepTransformNode;
8
8
  exports.enumerationPlugin = require_interpreter_getContent_plugins.enumerationPlugin;
9
+ exports.fallbackPlugin = require_interpreter_getContent_plugins.fallbackPlugin;
9
10
  exports.filePlugin = require_interpreter_getContent_plugins.filePlugin;
10
11
  exports.genderPlugin = require_interpreter_getContent_plugins.genderPlugin;
11
12
  exports.getBasePlugins = require_interpreter_getContent_getContent.getBasePlugins;
@@ -10,8 +10,18 @@ let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
10
10
  _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
11
11
 
12
12
  //#region src/interpreter/getContent/plugins.ts
13
+ /** ---------------------------------------------
14
+ * FALLBACK PLUGIN
15
+ *
16
+ * Used to fallback a tree-shaken plugin
17
+ * --------------------------------------------- */
18
+ const fallbackPlugin = {
19
+ id: "fallback-plugin",
20
+ canHandle: () => false,
21
+ transform: (node) => node
22
+ };
13
23
  /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
14
- const translationPlugin = (locale, fallback) => ({
24
+ const translationPlugin = (locale, fallback) => process.env.INTLAYER_NODE_TYPE_TRANSLATION === "false" ? fallbackPlugin : {
15
25
  id: "translation-plugin",
16
26
  canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.TRANSLATION,
17
27
  transform: (node, props, deepTransformNode) => {
@@ -29,9 +39,9 @@ const translationPlugin = (locale, fallback) => ({
29
39
  }
30
40
  return require_interpreter_getTranslation.getTranslation(result, locale, fallback);
31
41
  }
32
- });
42
+ };
33
43
  /** Enumeration plugin. Replaces node with a function that takes quantity => string. */
34
- const enumerationPlugin = {
44
+ const enumerationPlugin = process.env.INTLAYER_NODE_TYPE_ENUMERATION === "false" ? fallbackPlugin : {
35
45
  id: "enumeration-plugin",
36
46
  canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.ENUMERATION,
37
47
  transform: (node, props, deepTransformNode) => {
@@ -55,7 +65,7 @@ const enumerationPlugin = {
55
65
  }
56
66
  };
57
67
  /** Condition plugin. Replaces node with a function that takes boolean => string. */
58
- const conditionPlugin = {
68
+ const conditionPlugin = process.env.INTLAYER_NODE_TYPE_CONDITION === "false" ? fallbackPlugin : {
59
69
  id: "condition-plugin",
60
70
  canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.CONDITION,
61
71
  transform: (node, props, deepTransformNode) => {
@@ -79,7 +89,7 @@ const conditionPlugin = {
79
89
  }
80
90
  };
81
91
  /** Insertion plugin. Replaces node with a function that takes quantity => string. */
82
- const insertionPlugin = {
92
+ const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? fallbackPlugin : {
83
93
  id: "insertion-plugin",
84
94
  canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.INSERTION,
85
95
  transform: (node, props, deepTransformNode) => {
@@ -114,7 +124,7 @@ const insertionPlugin = {
114
124
  }
115
125
  };
116
126
  /** Gender plugin. Replaces node with a function that takes gender => string. */
117
- const genderPlugin = {
127
+ const genderPlugin = process.env.INTLAYER_NODE_TYPE_GENDER === "false" ? fallbackPlugin : {
118
128
  id: "gender-plugin",
119
129
  canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.GENDER,
120
130
  transform: (node, props, deepTransformNode) => {
@@ -134,16 +144,16 @@ const genderPlugin = {
134
144
  }
135
145
  };
136
146
  /** Nested plugin. Replaces node with the result of `getNesting`. */
137
- const nestedPlugin = (locale) => ({
147
+ const nestedPlugin = (locale) => process.env.INTLAYER_NODE_TYPE_NESTED === "false" ? fallbackPlugin : {
138
148
  id: "nested-plugin",
139
149
  canHandle: (node) => typeof node === "object" && (node?.nodeType === _intlayer_types_nodeType.NESTED || node?.nodeType === "n"),
140
150
  transform: (node, props) => require_interpreter_getNesting.getNesting(node[_intlayer_types_nodeType.NESTED].dictionaryKey, node[_intlayer_types_nodeType.NESTED].path, {
141
151
  ...props,
142
152
  locale: locale ?? props.locale
143
153
  })
144
- });
154
+ };
145
155
  /** File plugin. Replaces node with the result of `getNesting`. */
146
- const filePlugin = {
156
+ const filePlugin = process.env.INTLAYER_NODE_TYPE_FILE === "false" ? fallbackPlugin : {
147
157
  id: "file-plugin",
148
158
  canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.FILE,
149
159
  transform: (node, props, deepTransform) => deepTransform(node.content, {
@@ -155,6 +165,7 @@ const filePlugin = {
155
165
  //#endregion
156
166
  exports.conditionPlugin = conditionPlugin;
157
167
  exports.enumerationPlugin = enumerationPlugin;
168
+ exports.fallbackPlugin = fallbackPlugin;
158
169
  exports.filePlugin = filePlugin;
159
170
  exports.genderPlugin = genderPlugin;
160
171
  exports.insertionPlugin = insertionPlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.cjs","names":["NodeTypes","getTranslation","getEnumeration","getCondition","getInsertion","getGender","getNesting"],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = {\n ...(node[NodeTypes.TRANSLATION] ?? {}),\n };\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key as keyof typeof result] = deepTransformNode(\n result[key as keyof typeof result],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = { ...node[NodeTypes.ENUMERATION] };\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = { ...node[NodeTypes.CONDITION] };\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: string;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => DeepTransformContent<string, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = { ...node[NodeTypes.GENDER] };\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeTypes.GENDER, key } as KeyPath],\n };\n result[key as keyof typeof result] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins => ({\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n getNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n});\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":"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"}
1
+ {"version":3,"file":"plugins.cjs","names":["NodeTypes","getTranslation","getEnumeration","getCondition","getInsertion","getGender","getNesting"],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = {\n ...(node[NodeTypes.TRANSLATION] ?? {}),\n };\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key as keyof typeof result] = deepTransformNode(\n result[key as keyof typeof result],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = { ...node[NodeTypes.ENUMERATION] };\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = { ...node[NodeTypes.CONDITION] };\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: string;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => DeepTransformContent<string, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = { ...node[NodeTypes.GENDER] };\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: Gender) => getGender(result, value);\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n getNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":"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"}
@@ -14,6 +14,7 @@ const require_interpreter_splitAndJoinInsertion = require('./splitAndJoinInserti
14
14
  exports.conditionPlugin = require_interpreter_getContent_plugins.conditionPlugin;
15
15
  exports.deepTransformNode = require_interpreter_getContent_deepTransform.deepTransformNode;
16
16
  exports.enumerationPlugin = require_interpreter_getContent_plugins.enumerationPlugin;
17
+ exports.fallbackPlugin = require_interpreter_getContent_plugins.fallbackPlugin;
17
18
  exports.filePlugin = require_interpreter_getContent_plugins.filePlugin;
18
19
  exports.findMatchingCondition = require_interpreter_getEnumeration.findMatchingCondition;
19
20
  exports.genderPlugin = require_interpreter_getContent_plugins.genderPlugin;
@@ -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