@digitaldefiance/i18n-lib 3.8.0 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (503) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -0
  3. package/package.json +12 -4
  4. package/src/{active-context.d.ts → active-context.ts} +0 -1
  5. package/src/builders/i18n-builder.ts +82 -0
  6. package/src/builders/{index.d.ts → index.ts} +1 -1
  7. package/src/component-definition.ts +11 -0
  8. package/src/component-registration.ts +29 -0
  9. package/src/component-registry.ts +432 -0
  10. package/src/context-error-type.ts +7 -0
  11. package/src/core/component-store.ts +241 -0
  12. package/src/core/context-manager.ts +113 -0
  13. package/src/core/enum-registry.ts +106 -0
  14. package/src/core/i18n-engine.ts +710 -0
  15. package/src/core/{index.d.ts → index.ts} +4 -1
  16. package/src/core/language-registry.ts +345 -0
  17. package/src/{core-component-id.d.ts → core-component-id.ts} +1 -2
  18. package/src/core-i18n.ts +270 -0
  19. package/src/core-plugin-factory.ts +111 -0
  20. package/src/core-string-key.ts +59 -0
  21. package/src/create-translation-adapter.ts +93 -0
  22. package/src/enum-registry.ts +152 -0
  23. package/src/errors/{base.d.ts → base.ts} +1 -1
  24. package/src/errors/context-error.ts +122 -0
  25. package/src/errors/enhanced-error-base.ts +260 -0
  26. package/src/errors/handleable.ts +152 -0
  27. package/src/errors/i18n-error.ts +494 -0
  28. package/src/errors/{index.d.ts → index.ts} +4 -1
  29. package/src/errors/simple-typed-error.ts +81 -0
  30. package/src/errors/{translatable-exports.d.ts → translatable-exports.ts} +1 -1
  31. package/src/errors/translatable-generic.ts +245 -0
  32. package/src/errors/translatable-handleable-generic.ts +222 -0
  33. package/src/errors/translatable.ts +138 -0
  34. package/src/errors/typed-handleable.ts +138 -0
  35. package/src/errors/typed.ts +617 -0
  36. package/src/gender/{gender-categories.d.ts → gender-categories.ts} +6 -2
  37. package/src/gender/gender-resolver.ts +40 -0
  38. package/src/gender/{index.d.ts → index.ts} +0 -1
  39. package/src/global-active-context.ts +266 -0
  40. package/src/icu/ast.ts +56 -0
  41. package/src/icu/compiler.ts +96 -0
  42. package/src/icu/formatter-registry.ts +36 -0
  43. package/src/icu/formatters/base-formatter.ts +8 -0
  44. package/src/icu/formatters/date-formatter.ts +30 -0
  45. package/src/icu/formatters/number-formatter.ts +32 -0
  46. package/src/icu/formatters/plural-formatter.ts +12 -0
  47. package/src/icu/formatters/select-formatter.ts +7 -0
  48. package/src/icu/formatters/selectordinal-formatter.ts +17 -0
  49. package/src/icu/formatters/time-formatter.ts +30 -0
  50. package/src/icu/helpers.ts +34 -0
  51. package/src/icu/parser.ts +242 -0
  52. package/src/icu/runtime.ts +37 -0
  53. package/src/icu/tokenizer.ts +212 -0
  54. package/src/icu/validator.ts +163 -0
  55. package/src/{index.d.ts → index.ts} +38 -6
  56. package/src/interfaces/active-context.interface.ts +41 -0
  57. package/src/interfaces/component-config.interface.ts +17 -0
  58. package/src/interfaces/engine-config.interface.ts +22 -0
  59. package/src/interfaces/global-active-context.ts +39 -0
  60. package/src/interfaces/handleable-error-options.ts +13 -0
  61. package/src/interfaces/handleable.ts +20 -0
  62. package/src/interfaces/i18n-engine.interface.ts +57 -0
  63. package/src/interfaces/{index.d.ts → index.ts} +1 -1
  64. package/src/interfaces/language-definition.interface.ts +17 -0
  65. package/src/interfaces/translation-options.interface.ts +15 -0
  66. package/src/interfaces/validation-result.interface.ts +24 -0
  67. package/src/language-codes.ts +40 -0
  68. package/src/language-definition.ts +13 -0
  69. package/src/plugin-i18n-engine.ts +707 -0
  70. package/src/pluralization/{index.d.ts → index.ts} +1 -1
  71. package/src/pluralization/language-plural-map.ts +186 -0
  72. package/src/pluralization/{plural-categories.d.ts → plural-categories.ts} +5 -3
  73. package/src/pluralization/plural-rules.ts +228 -0
  74. package/src/registry-config.ts +16 -0
  75. package/src/registry-error-type.ts +19 -0
  76. package/src/registry-error.ts +100 -0
  77. package/src/strict-types.ts +35 -0
  78. package/src/strings/de.ts +75 -0
  79. package/src/strings/en-GB.ts +74 -0
  80. package/src/strings/en-US.ts +74 -0
  81. package/src/strings/es.ts +74 -0
  82. package/src/strings/fr.ts +75 -0
  83. package/src/strings/ja.ts +73 -0
  84. package/src/strings/uk.ts +73 -0
  85. package/src/strings/zh-CN.ts +72 -0
  86. package/src/template.ts +72 -0
  87. package/src/translation-engine.ts +18 -0
  88. package/src/translation-request.ts +12 -0
  89. package/src/translation-response.ts +8 -0
  90. package/src/types/engine.ts +55 -0
  91. package/src/types/{index.d.ts → index.ts} +1 -1
  92. package/src/types/{plural-types.d.ts → plural-types.ts} +29 -3
  93. package/src/{types.d.ts → types.ts} +72 -21
  94. package/src/utils/currency.ts +141 -0
  95. package/src/utils/html-escape.ts +55 -0
  96. package/src/utils/{index.d.ts → index.ts} +0 -1
  97. package/src/utils/lru-cache.ts +76 -0
  98. package/src/utils/{plural-helpers.d.ts → plural-helpers.ts} +14 -4
  99. package/src/utils/{safe-object.js → safe-object.ts} +37 -34
  100. package/src/utils/string-utils.ts +77 -0
  101. package/src/utils/timezone.ts +76 -0
  102. package/src/utils/validation.ts +66 -0
  103. package/src/utils.ts +215 -0
  104. package/src/validation/{index.d.ts → index.ts} +0 -1
  105. package/src/validation/plural-validator.ts +168 -0
  106. package/src/validation-config.ts +11 -0
  107. package/src/validation-result.ts +12 -0
  108. package/src/active-context.d.ts.map +0 -1
  109. package/src/active-context.js +0 -3
  110. package/src/active-context.js.map +0 -1
  111. package/src/builders/i18n-builder.d.ts +0 -26
  112. package/src/builders/i18n-builder.d.ts.map +0 -1
  113. package/src/builders/i18n-builder.js +0 -70
  114. package/src/builders/i18n-builder.js.map +0 -1
  115. package/src/builders/index.d.ts.map +0 -1
  116. package/src/builders/index.js +0 -8
  117. package/src/builders/index.js.map +0 -1
  118. package/src/component-definition.d.ts +0 -12
  119. package/src/component-definition.d.ts.map +0 -1
  120. package/src/component-definition.js +0 -3
  121. package/src/component-definition.js.map +0 -1
  122. package/src/component-registration.d.ts +0 -22
  123. package/src/component-registration.d.ts.map +0 -1
  124. package/src/component-registration.js +0 -3
  125. package/src/component-registration.js.map +0 -1
  126. package/src/component-registry.d.ts +0 -102
  127. package/src/component-registry.d.ts.map +0 -1
  128. package/src/component-registry.js +0 -282
  129. package/src/component-registry.js.map +0 -1
  130. package/src/context-error-type.d.ts +0 -8
  131. package/src/context-error-type.d.ts.map +0 -1
  132. package/src/context-error-type.js +0 -12
  133. package/src/context-error-type.js.map +0 -1
  134. package/src/core/component-store.d.ts +0 -93
  135. package/src/core/component-store.d.ts.map +0 -1
  136. package/src/core/component-store.js +0 -198
  137. package/src/core/component-store.js.map +0 -1
  138. package/src/core/context-manager.d.ts +0 -72
  139. package/src/core/context-manager.d.ts.map +0 -1
  140. package/src/core/context-manager.js +0 -98
  141. package/src/core/context-manager.js.map +0 -1
  142. package/src/core/enum-registry.d.ts +0 -48
  143. package/src/core/enum-registry.d.ts.map +0 -1
  144. package/src/core/enum-registry.js +0 -85
  145. package/src/core/enum-registry.js.map +0 -1
  146. package/src/core/i18n-engine.d.ts +0 -241
  147. package/src/core/i18n-engine.d.ts.map +0 -1
  148. package/src/core/i18n-engine.js +0 -568
  149. package/src/core/i18n-engine.js.map +0 -1
  150. package/src/core/index.d.ts.map +0 -1
  151. package/src/core/index.js +0 -21
  152. package/src/core/index.js.map +0 -1
  153. package/src/core/language-registry.d.ts +0 -180
  154. package/src/core/language-registry.d.ts.map +0 -1
  155. package/src/core/language-registry.js +0 -298
  156. package/src/core/language-registry.js.map +0 -1
  157. package/src/core-component-id.d.ts.map +0 -1
  158. package/src/core-component-id.js +0 -9
  159. package/src/core-component-id.js.map +0 -1
  160. package/src/core-i18n.d.ts +0 -69
  161. package/src/core-i18n.d.ts.map +0 -1
  162. package/src/core-i18n.js +0 -219
  163. package/src/core-i18n.js.map +0 -1
  164. package/src/core-plugin-factory.d.ts +0 -28
  165. package/src/core-plugin-factory.d.ts.map +0 -1
  166. package/src/core-plugin-factory.js +0 -80
  167. package/src/core-plugin-factory.js.map +0 -1
  168. package/src/core-string-key.d.ts +0 -52
  169. package/src/core-string-key.d.ts.map +0 -1
  170. package/src/core-string-key.js +0 -61
  171. package/src/core-string-key.js.map +0 -1
  172. package/src/create-translation-adapter.d.ts +0 -33
  173. package/src/create-translation-adapter.d.ts.map +0 -1
  174. package/src/create-translation-adapter.js +0 -72
  175. package/src/create-translation-adapter.js.map +0 -1
  176. package/src/enum-registry.d.ts +0 -65
  177. package/src/enum-registry.d.ts.map +0 -1
  178. package/src/enum-registry.js +0 -123
  179. package/src/enum-registry.js.map +0 -1
  180. package/src/errors/base.d.ts.map +0 -1
  181. package/src/errors/base.js +0 -11
  182. package/src/errors/base.js.map +0 -1
  183. package/src/errors/context-error.d.ts +0 -50
  184. package/src/errors/context-error.d.ts.map +0 -1
  185. package/src/errors/context-error.js +0 -93
  186. package/src/errors/context-error.js.map +0 -1
  187. package/src/errors/enhanced-error-base.d.ts +0 -125
  188. package/src/errors/enhanced-error-base.d.ts.map +0 -1
  189. package/src/errors/enhanced-error-base.js +0 -165
  190. package/src/errors/enhanced-error-base.js.map +0 -1
  191. package/src/errors/handleable.d.ts +0 -83
  192. package/src/errors/handleable.d.ts.map +0 -1
  193. package/src/errors/handleable.js +0 -136
  194. package/src/errors/handleable.js.map +0 -1
  195. package/src/errors/i18n-error.d.ts +0 -211
  196. package/src/errors/i18n-error.d.ts.map +0 -1
  197. package/src/errors/i18n-error.js +0 -358
  198. package/src/errors/i18n-error.js.map +0 -1
  199. package/src/errors/index.d.ts.map +0 -1
  200. package/src/errors/index.js +0 -17
  201. package/src/errors/index.js.map +0 -1
  202. package/src/errors/simple-typed-error.d.ts +0 -53
  203. package/src/errors/simple-typed-error.d.ts.map +0 -1
  204. package/src/errors/simple-typed-error.js +0 -51
  205. package/src/errors/simple-typed-error.js.map +0 -1
  206. package/src/errors/translatable-exports.d.ts.map +0 -1
  207. package/src/errors/translatable-exports.js +0 -15
  208. package/src/errors/translatable-exports.js.map +0 -1
  209. package/src/errors/translatable-generic.d.ts +0 -87
  210. package/src/errors/translatable-generic.d.ts.map +0 -1
  211. package/src/errors/translatable-generic.js +0 -139
  212. package/src/errors/translatable-generic.js.map +0 -1
  213. package/src/errors/translatable-handleable-generic.d.ts +0 -116
  214. package/src/errors/translatable-handleable-generic.d.ts.map +0 -1
  215. package/src/errors/translatable-handleable-generic.js +0 -121
  216. package/src/errors/translatable-handleable-generic.js.map +0 -1
  217. package/src/errors/translatable.d.ts +0 -63
  218. package/src/errors/translatable.d.ts.map +0 -1
  219. package/src/errors/translatable.js +0 -85
  220. package/src/errors/translatable.js.map +0 -1
  221. package/src/errors/typed-handleable.d.ts +0 -62
  222. package/src/errors/typed-handleable.d.ts.map +0 -1
  223. package/src/errors/typed-handleable.js +0 -108
  224. package/src/errors/typed-handleable.js.map +0 -1
  225. package/src/errors/typed.d.ts +0 -206
  226. package/src/errors/typed.d.ts.map +0 -1
  227. package/src/errors/typed.js +0 -458
  228. package/src/errors/typed.js.map +0 -1
  229. package/src/gender/gender-categories.d.ts.map +0 -1
  230. package/src/gender/gender-categories.js +0 -15
  231. package/src/gender/gender-categories.js.map +0 -1
  232. package/src/gender/gender-resolver.d.ts +0 -14
  233. package/src/gender/gender-resolver.d.ts.map +0 -1
  234. package/src/gender/gender-resolver.js +0 -35
  235. package/src/gender/gender-resolver.js.map +0 -1
  236. package/src/gender/index.d.ts.map +0 -1
  237. package/src/gender/index.js +0 -6
  238. package/src/gender/index.js.map +0 -1
  239. package/src/global-active-context.d.ts +0 -50
  240. package/src/global-active-context.d.ts.map +0 -1
  241. package/src/global-active-context.js +0 -185
  242. package/src/global-active-context.js.map +0 -1
  243. package/src/icu/ast.d.ts +0 -48
  244. package/src/icu/ast.d.ts.map +0 -1
  245. package/src/icu/ast.js +0 -16
  246. package/src/icu/ast.js.map +0 -1
  247. package/src/icu/compiler.d.ts +0 -16
  248. package/src/icu/compiler.d.ts.map +0 -1
  249. package/src/icu/compiler.js +0 -87
  250. package/src/icu/compiler.js.map +0 -1
  251. package/src/icu/formatter-registry.d.ts +0 -10
  252. package/src/icu/formatter-registry.d.ts.map +0 -1
  253. package/src/icu/formatter-registry.js +0 -34
  254. package/src/icu/formatter-registry.js.map +0 -1
  255. package/src/icu/formatters/base-formatter.d.ts +0 -8
  256. package/src/icu/formatters/base-formatter.d.ts.map +0 -1
  257. package/src/icu/formatters/base-formatter.js +0 -3
  258. package/src/icu/formatters/base-formatter.js.map +0 -1
  259. package/src/icu/formatters/date-formatter.d.ts +0 -5
  260. package/src/icu/formatters/date-formatter.d.ts.map +0 -1
  261. package/src/icu/formatters/date-formatter.js +0 -31
  262. package/src/icu/formatters/date-formatter.js.map +0 -1
  263. package/src/icu/formatters/number-formatter.d.ts +0 -5
  264. package/src/icu/formatters/number-formatter.d.ts.map +0 -1
  265. package/src/icu/formatters/number-formatter.js +0 -33
  266. package/src/icu/formatters/number-formatter.js.map +0 -1
  267. package/src/icu/formatters/plural-formatter.d.ts +0 -5
  268. package/src/icu/formatters/plural-formatter.d.ts.map +0 -1
  269. package/src/icu/formatters/plural-formatter.js +0 -15
  270. package/src/icu/formatters/plural-formatter.js.map +0 -1
  271. package/src/icu/formatters/select-formatter.d.ts +0 -5
  272. package/src/icu/formatters/select-formatter.d.ts.map +0 -1
  273. package/src/icu/formatters/select-formatter.js +0 -10
  274. package/src/icu/formatters/select-formatter.js.map +0 -1
  275. package/src/icu/formatters/selectordinal-formatter.d.ts +0 -5
  276. package/src/icu/formatters/selectordinal-formatter.d.ts.map +0 -1
  277. package/src/icu/formatters/selectordinal-formatter.js +0 -22
  278. package/src/icu/formatters/selectordinal-formatter.js.map +0 -1
  279. package/src/icu/formatters/time-formatter.d.ts +0 -5
  280. package/src/icu/formatters/time-formatter.d.ts.map +0 -1
  281. package/src/icu/formatters/time-formatter.js +0 -31
  282. package/src/icu/formatters/time-formatter.js.map +0 -1
  283. package/src/icu/helpers.d.ts +0 -9
  284. package/src/icu/helpers.d.ts.map +0 -1
  285. package/src/icu/helpers.js +0 -31
  286. package/src/icu/helpers.js.map +0 -1
  287. package/src/icu/parser.d.ts +0 -31
  288. package/src/icu/parser.d.ts.map +0 -1
  289. package/src/icu/parser.js +0 -203
  290. package/src/icu/parser.js.map +0 -1
  291. package/src/icu/runtime.d.ts +0 -10
  292. package/src/icu/runtime.d.ts.map +0 -1
  293. package/src/icu/runtime.js +0 -33
  294. package/src/icu/runtime.js.map +0 -1
  295. package/src/icu/tokenizer.d.ts +0 -37
  296. package/src/icu/tokenizer.d.ts.map +0 -1
  297. package/src/icu/tokenizer.js +0 -187
  298. package/src/icu/tokenizer.js.map +0 -1
  299. package/src/icu/validator.d.ts +0 -11
  300. package/src/icu/validator.d.ts.map +0 -1
  301. package/src/icu/validator.js +0 -140
  302. package/src/icu/validator.js.map +0 -1
  303. package/src/index.d.ts.map +0 -1
  304. package/src/index.js +0 -76
  305. package/src/index.js.map +0 -1
  306. package/src/interfaces/active-context.interface.d.ts +0 -36
  307. package/src/interfaces/active-context.interface.d.ts.map +0 -1
  308. package/src/interfaces/active-context.interface.js +0 -3
  309. package/src/interfaces/active-context.interface.js.map +0 -1
  310. package/src/interfaces/component-config.interface.d.ts +0 -16
  311. package/src/interfaces/component-config.interface.d.ts.map +0 -1
  312. package/src/interfaces/component-config.interface.js +0 -6
  313. package/src/interfaces/component-config.interface.js.map +0 -1
  314. package/src/interfaces/engine-config.interface.d.ts +0 -22
  315. package/src/interfaces/engine-config.interface.d.ts.map +0 -1
  316. package/src/interfaces/engine-config.interface.js +0 -6
  317. package/src/interfaces/engine-config.interface.js.map +0 -1
  318. package/src/interfaces/global-active-context.d.ts +0 -23
  319. package/src/interfaces/global-active-context.d.ts.map +0 -1
  320. package/src/interfaces/global-active-context.js +0 -3
  321. package/src/interfaces/global-active-context.js.map +0 -1
  322. package/src/interfaces/handleable-error-options.d.ts +0 -14
  323. package/src/interfaces/handleable-error-options.d.ts.map +0 -1
  324. package/src/interfaces/handleable-error-options.js +0 -3
  325. package/src/interfaces/handleable-error-options.js.map +0 -1
  326. package/src/interfaces/handleable.d.ts +0 -21
  327. package/src/interfaces/handleable.d.ts.map +0 -1
  328. package/src/interfaces/handleable.js +0 -3
  329. package/src/interfaces/handleable.js.map +0 -1
  330. package/src/interfaces/i18n-engine.interface.d.ts +0 -46
  331. package/src/interfaces/i18n-engine.interface.d.ts.map +0 -1
  332. package/src/interfaces/i18n-engine.interface.js +0 -6
  333. package/src/interfaces/i18n-engine.interface.js.map +0 -1
  334. package/src/interfaces/index.d.ts.map +0 -1
  335. package/src/interfaces/index.js +0 -7
  336. package/src/interfaces/index.js.map +0 -1
  337. package/src/interfaces/language-definition.interface.d.ts +0 -17
  338. package/src/interfaces/language-definition.interface.d.ts.map +0 -1
  339. package/src/interfaces/language-definition.interface.js +0 -6
  340. package/src/interfaces/language-definition.interface.js.map +0 -1
  341. package/src/interfaces/translation-options.interface.d.ts +0 -15
  342. package/src/interfaces/translation-options.interface.d.ts.map +0 -1
  343. package/src/interfaces/translation-options.interface.js +0 -6
  344. package/src/interfaces/translation-options.interface.js.map +0 -1
  345. package/src/interfaces/validation-result.interface.d.ts +0 -24
  346. package/src/interfaces/validation-result.interface.d.ts.map +0 -1
  347. package/src/interfaces/validation-result.interface.js +0 -6
  348. package/src/interfaces/validation-result.interface.js.map +0 -1
  349. package/src/language-codes.d.ts +0 -28
  350. package/src/language-codes.d.ts.map +0 -1
  351. package/src/language-codes.js +0 -32
  352. package/src/language-codes.js.map +0 -1
  353. package/src/language-definition.d.ts +0 -14
  354. package/src/language-definition.d.ts.map +0 -1
  355. package/src/language-definition.js +0 -3
  356. package/src/language-definition.js.map +0 -1
  357. package/src/plugin-i18n-engine.d.ts +0 -164
  358. package/src/plugin-i18n-engine.d.ts.map +0 -1
  359. package/src/plugin-i18n-engine.js +0 -493
  360. package/src/plugin-i18n-engine.js.map +0 -1
  361. package/src/pluralization/index.d.ts.map +0 -1
  362. package/src/pluralization/index.js +0 -10
  363. package/src/pluralization/index.js.map +0 -1
  364. package/src/pluralization/language-plural-map.d.ts +0 -29
  365. package/src/pluralization/language-plural-map.d.ts.map +0 -1
  366. package/src/pluralization/language-plural-map.js +0 -155
  367. package/src/pluralization/language-plural-map.js.map +0 -1
  368. package/src/pluralization/plural-categories.d.ts.map +0 -1
  369. package/src/pluralization/plural-categories.js +0 -8
  370. package/src/pluralization/plural-categories.js.map +0 -1
  371. package/src/pluralization/plural-rules.d.ts +0 -102
  372. package/src/pluralization/plural-rules.d.ts.map +0 -1
  373. package/src/pluralization/plural-rules.js +0 -263
  374. package/src/pluralization/plural-rules.js.map +0 -1
  375. package/src/registry-config.d.ts +0 -16
  376. package/src/registry-config.d.ts.map +0 -1
  377. package/src/registry-config.js +0 -3
  378. package/src/registry-config.js.map +0 -1
  379. package/src/registry-error-type.d.ts +0 -20
  380. package/src/registry-error-type.d.ts.map +0 -1
  381. package/src/registry-error-type.js +0 -24
  382. package/src/registry-error-type.js.map +0 -1
  383. package/src/registry-error.d.ts +0 -25
  384. package/src/registry-error.d.ts.map +0 -1
  385. package/src/registry-error.js +0 -63
  386. package/src/registry-error.js.map +0 -1
  387. package/src/strict-types.d.ts +0 -19
  388. package/src/strict-types.d.ts.map +0 -1
  389. package/src/strict-types.js +0 -18
  390. package/src/strict-types.js.map +0 -1
  391. package/src/strings/de.d.ts +0 -3
  392. package/src/strings/de.d.ts.map +0 -1
  393. package/src/strings/de.js +0 -57
  394. package/src/strings/de.js.map +0 -1
  395. package/src/strings/en-GB.d.ts +0 -3
  396. package/src/strings/en-GB.d.ts.map +0 -1
  397. package/src/strings/en-GB.js +0 -57
  398. package/src/strings/en-GB.js.map +0 -1
  399. package/src/strings/en-US.d.ts +0 -3
  400. package/src/strings/en-US.d.ts.map +0 -1
  401. package/src/strings/en-US.js +0 -57
  402. package/src/strings/en-US.js.map +0 -1
  403. package/src/strings/es.d.ts +0 -3
  404. package/src/strings/es.d.ts.map +0 -1
  405. package/src/strings/es.js +0 -57
  406. package/src/strings/es.js.map +0 -1
  407. package/src/strings/fr.d.ts +0 -3
  408. package/src/strings/fr.d.ts.map +0 -1
  409. package/src/strings/fr.js +0 -57
  410. package/src/strings/fr.js.map +0 -1
  411. package/src/strings/ja.d.ts +0 -3
  412. package/src/strings/ja.d.ts.map +0 -1
  413. package/src/strings/ja.js +0 -57
  414. package/src/strings/ja.js.map +0 -1
  415. package/src/strings/uk.d.ts +0 -3
  416. package/src/strings/uk.d.ts.map +0 -1
  417. package/src/strings/uk.js +0 -57
  418. package/src/strings/uk.js.map +0 -1
  419. package/src/strings/zh-CN.d.ts +0 -3
  420. package/src/strings/zh-CN.d.ts.map +0 -1
  421. package/src/strings/zh-CN.js +0 -57
  422. package/src/strings/zh-CN.js.map +0 -1
  423. package/src/template.d.ts +0 -13
  424. package/src/template.d.ts.map +0 -1
  425. package/src/template.js +0 -40
  426. package/src/template.js.map +0 -1
  427. package/src/translation-engine.d.ts +0 -9
  428. package/src/translation-engine.d.ts.map +0 -1
  429. package/src/translation-engine.js +0 -3
  430. package/src/translation-engine.js.map +0 -1
  431. package/src/translation-request.d.ts +0 -10
  432. package/src/translation-request.d.ts.map +0 -1
  433. package/src/translation-request.js +0 -3
  434. package/src/translation-request.js.map +0 -1
  435. package/src/translation-response.d.ts +0 -9
  436. package/src/translation-response.d.ts.map +0 -1
  437. package/src/translation-response.js +0 -3
  438. package/src/translation-response.js.map +0 -1
  439. package/src/types/engine.d.ts +0 -47
  440. package/src/types/engine.d.ts.map +0 -1
  441. package/src/types/engine.js +0 -8
  442. package/src/types/engine.js.map +0 -1
  443. package/src/types/index.d.ts.map +0 -1
  444. package/src/types/index.js +0 -9
  445. package/src/types/index.js.map +0 -1
  446. package/src/types/plural-types.d.ts.map +0 -1
  447. package/src/types/plural-types.js +0 -39
  448. package/src/types/plural-types.js.map +0 -1
  449. package/src/types.d.ts.map +0 -1
  450. package/src/types.js +0 -23
  451. package/src/types.js.map +0 -1
  452. package/src/utils/currency.d.ts +0 -81
  453. package/src/utils/currency.d.ts.map +0 -1
  454. package/src/utils/currency.js +0 -99
  455. package/src/utils/currency.js.map +0 -1
  456. package/src/utils/html-escape.d.ts +0 -22
  457. package/src/utils/html-escape.d.ts.map +0 -1
  458. package/src/utils/html-escape.js +0 -53
  459. package/src/utils/html-escape.js.map +0 -1
  460. package/src/utils/index.d.ts.map +0 -1
  461. package/src/utils/index.js +0 -12
  462. package/src/utils/index.js.map +0 -1
  463. package/src/utils/lru-cache.d.ts +0 -42
  464. package/src/utils/lru-cache.d.ts.map +0 -1
  465. package/src/utils/lru-cache.js +0 -73
  466. package/src/utils/lru-cache.js.map +0 -1
  467. package/src/utils/plural-helpers.d.ts.map +0 -1
  468. package/src/utils/plural-helpers.js +0 -35
  469. package/src/utils/plural-helpers.js.map +0 -1
  470. package/src/utils/safe-object.d.ts +0 -39
  471. package/src/utils/safe-object.d.ts.map +0 -1
  472. package/src/utils/safe-object.js.map +0 -1
  473. package/src/utils/string-utils.d.ts +0 -28
  474. package/src/utils/string-utils.d.ts.map +0 -1
  475. package/src/utils/string-utils.js +0 -63
  476. package/src/utils/string-utils.js.map +0 -1
  477. package/src/utils/timezone.d.ts +0 -50
  478. package/src/utils/timezone.d.ts.map +0 -1
  479. package/src/utils/timezone.js +0 -74
  480. package/src/utils/timezone.js.map +0 -1
  481. package/src/utils/validation.d.ts +0 -40
  482. package/src/utils/validation.d.ts.map +0 -1
  483. package/src/utils/validation.js +0 -69
  484. package/src/utils/validation.js.map +0 -1
  485. package/src/utils.d.ts +0 -65
  486. package/src/utils.d.ts.map +0 -1
  487. package/src/utils.js +0 -129
  488. package/src/utils.js.map +0 -1
  489. package/src/validation/index.d.ts.map +0 -1
  490. package/src/validation/index.js +0 -5
  491. package/src/validation/index.js.map +0 -1
  492. package/src/validation/plural-validator.d.ts +0 -46
  493. package/src/validation/plural-validator.d.ts.map +0 -1
  494. package/src/validation/plural-validator.js +0 -123
  495. package/src/validation/plural-validator.js.map +0 -1
  496. package/src/validation-config.d.ts +0 -12
  497. package/src/validation-config.d.ts.map +0 -1
  498. package/src/validation-config.js +0 -3
  499. package/src/validation-config.js.map +0 -1
  500. package/src/validation-result.d.ts +0 -13
  501. package/src/validation-result.d.ts.map +0 -1
  502. package/src/validation-result.js +0 -3
  503. package/src/validation-result.js.map +0 -1
@@ -0,0 +1,494 @@
1
+ /**
2
+ * Unified error class for i18n library with ICU MessageFormat support
3
+ */
4
+
5
+ import { formatICUMessage } from '../icu/helpers';
6
+
7
+ /**
8
+ * Error codes used throughout the i18n library.
9
+ */
10
+ export const I18nErrorCode = {
11
+ /** Component not found in registry */
12
+ COMPONENT_NOT_FOUND: 'COMPONENT_NOT_FOUND',
13
+ /** String key not found in component */
14
+ STRING_KEY_NOT_FOUND: 'STRING_KEY_NOT_FOUND',
15
+ /** Language not found in registry */
16
+ LANGUAGE_NOT_FOUND: 'LANGUAGE_NOT_FOUND',
17
+ /** Translation missing for specified key and language */
18
+ TRANSLATION_MISSING: 'TRANSLATION_MISSING',
19
+ /** Invalid configuration provided */
20
+ INVALID_CONFIG: 'INVALID_CONFIG',
21
+ /** Attempt to register duplicate component */
22
+ DUPLICATE_COMPONENT: 'DUPLICATE_COMPONENT',
23
+ /** Attempt to register duplicate language */
24
+ DUPLICATE_LANGUAGE: 'DUPLICATE_LANGUAGE',
25
+ /** Validation failed during registration */
26
+ VALIDATION_FAILED: 'VALIDATION_FAILED',
27
+ /** I18n instance not found */
28
+ INSTANCE_NOT_FOUND: 'INSTANCE_NOT_FOUND',
29
+ /** I18n instance already exists */
30
+ INSTANCE_EXISTS: 'INSTANCE_EXISTS',
31
+ /** Invalid context key provided */
32
+ INVALID_CONTEXT: 'INVALID_CONTEXT',
33
+ /** Plural form not found for language and category */
34
+ PLURAL_FORM_NOT_FOUND: 'PLURAL_FORM_NOT_FOUND',
35
+ /** Invalid plural category provided */
36
+ INVALID_PLURAL_CATEGORY: 'INVALID_PLURAL_CATEGORY',
37
+ /** Count variable missing for plural translation */
38
+ MISSING_COUNT_VARIABLE: 'MISSING_COUNT_VARIABLE',
39
+ /** Validation threshold exceeded */
40
+ VALIDATION_THRESHOLD_EXCEEDED: 'VALIDATION_THRESHOLD_EXCEEDED',
41
+ /** Operation failed at specific step */
42
+ OPERATION_STEP_FAILED: 'OPERATION_STEP_FAILED',
43
+ /** Rate limit exceeded */
44
+ RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
45
+ /** Nested validation error with context */
46
+ NESTED_VALIDATION_ERROR: 'NESTED_VALIDATION_ERROR',
47
+ } as const;
48
+
49
+ /**
50
+ * Type representing all possible i18n error codes.
51
+ */
52
+ export type I18nErrorCode = (typeof I18nErrorCode)[keyof typeof I18nErrorCode];
53
+
54
+ /**
55
+ * Main error class for i18n-related errors.
56
+ * Includes error code and optional metadata for debugging.
57
+ */
58
+ export class I18nError extends Error {
59
+ /**
60
+ * Creates a new I18nError instance.
61
+ * @param code - The specific error code
62
+ * @param message - Human-readable error message
63
+ * @param metadata - Optional metadata providing context about the error
64
+ */
65
+ constructor(
66
+ public readonly code: I18nErrorCode,
67
+ message: string,
68
+ public override readonly metadata?: Record<string, any>,
69
+ ) {
70
+ super(message);
71
+ this.name = 'I18nError';
72
+ Object.setPrototypeOf(this, I18nError.prototype);
73
+ }
74
+
75
+ /**
76
+ * Creates an error for when a component is not found with nested ICU select formatting.
77
+ * @param componentId - The ID of the component that was not found
78
+ * @param language - Optional language code for message formatting
79
+ * @returns An I18nError instance
80
+ */
81
+ static componentNotFound(componentId: string, language = 'en-US'): I18nError {
82
+ const hasNamespace = componentId.includes('.');
83
+ const message = formatICUMessage(
84
+ '{hasNamespace, select, true {Namespaced component {componentId}} other {Component {componentId}}} not found in registry',
85
+ { componentId, hasNamespace: hasNamespace ? 'true' : 'false' },
86
+ language,
87
+ );
88
+ return new I18nError(I18nErrorCode.COMPONENT_NOT_FOUND, message, {
89
+ componentId,
90
+ });
91
+ }
92
+
93
+ /**
94
+ * Creates an error for when a string key is not found in a component with nested ICU formatting.
95
+ * @param componentId - The ID of the component
96
+ * @param stringKey - The string key that was not found
97
+ * @param language - Optional language code for message formatting
98
+ * @returns An I18nError instance
99
+ */
100
+ static stringKeyNotFound(
101
+ componentId: string,
102
+ stringKey: string,
103
+ language = 'en-US',
104
+ ): I18nError {
105
+ const depth = stringKey.split('.').length;
106
+ const isNested = depth > 1;
107
+ const message = formatICUMessage(
108
+ '{isNested, select, true {Nested string key at {depth, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} level {stringKey}} other {String key {stringKey}}} not found in component {componentId}',
109
+ { componentId, stringKey, depth, isNested: isNested ? 'true' : 'false' },
110
+ language,
111
+ );
112
+ return new I18nError(I18nErrorCode.STRING_KEY_NOT_FOUND, message, {
113
+ componentId,
114
+ stringKey,
115
+ });
116
+ }
117
+
118
+ /**
119
+ * Creates an error for when a language is not found with ICU formatting.
120
+ * @param language - The language code that was not found
121
+ * @param messageLanguage - Optional language code for error message formatting
122
+ * @returns An I18nError instance
123
+ */
124
+ static languageNotFound(
125
+ language: string,
126
+ messageLanguage = 'en-US',
127
+ ): I18nError {
128
+ const message = formatICUMessage(
129
+ 'Language {language} not found',
130
+ { language },
131
+ messageLanguage,
132
+ );
133
+ return new I18nError(I18nErrorCode.LANGUAGE_NOT_FOUND, message, {
134
+ language,
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Creates an error for when a translation is missing with nested ICU formatting.
140
+ * @param componentId - The ID of the component
141
+ * @param stringKey - The string key
142
+ * @param language - The language code where translation is missing
143
+ * @param messageLanguage - Optional language code for error message formatting
144
+ * @returns An I18nError instance
145
+ */
146
+ static translationMissing(
147
+ componentId: string,
148
+ stringKey: string,
149
+ language: string,
150
+ messageLanguage = 'en-US',
151
+ ): I18nError {
152
+ const hasNestedKey = stringKey.includes('.');
153
+ const message = formatICUMessage(
154
+ 'Translation missing: {hasNested, select, true {nested path} other {key}} {componentId}.{stringKey} not found in language {language}',
155
+ {
156
+ componentId,
157
+ stringKey,
158
+ language,
159
+ hasNested: hasNestedKey ? 'true' : 'false',
160
+ },
161
+ messageLanguage,
162
+ );
163
+ return new I18nError(I18nErrorCode.TRANSLATION_MISSING, message, {
164
+ componentId,
165
+ stringKey,
166
+ language,
167
+ });
168
+ }
169
+
170
+ /**
171
+ * Creates an error for invalid configuration.
172
+ * @param reason - The reason why the configuration is invalid
173
+ * @returns An I18nError instance
174
+ */
175
+ static invalidConfig(reason: string): I18nError {
176
+ return new I18nError(I18nErrorCode.INVALID_CONFIG, reason);
177
+ }
178
+
179
+ /**
180
+ * Creates an error for duplicate component registration with nested ICU select formatting.
181
+ * @param componentId - The ID of the duplicate component
182
+ * @param language - Optional language code for message formatting
183
+ * @returns An I18nError instance
184
+ */
185
+ static duplicateComponent(
186
+ componentId: string,
187
+ language = 'en-US',
188
+ ): I18nError {
189
+ const hasNamespace = componentId.includes('.');
190
+ const message = formatICUMessage(
191
+ '{hasNamespace, select, true {Namespaced component {componentId}} other {Component {componentId}}} is already registered {hasNamespace, select, true {in this namespace} other {in the registry}}',
192
+ { componentId, hasNamespace: hasNamespace ? 'true' : 'false' },
193
+ language,
194
+ );
195
+ return new I18nError(I18nErrorCode.DUPLICATE_COMPONENT, message, {
196
+ componentId,
197
+ });
198
+ }
199
+
200
+ /**
201
+ * Creates an error for duplicate language registration with ICU formatting.
202
+ * @param language - The language code that is duplicate
203
+ * @param messageLanguage - Optional language code for error message formatting
204
+ * @returns An I18nError instance
205
+ */
206
+ static duplicateLanguage(
207
+ language: string,
208
+ messageLanguage = 'en-US',
209
+ ): I18nError {
210
+ const message = `Language '${language}' already registered`;
211
+ return new I18nError(I18nErrorCode.DUPLICATE_LANGUAGE, message, {
212
+ language,
213
+ });
214
+ }
215
+
216
+ /**
217
+ * Creates an error for validation failure with ICU plural formatting and number formatting.
218
+ * @param errors - Array of validation error messages
219
+ * @param language - Optional language code for message formatting
220
+ * @returns An I18nError instance
221
+ */
222
+ static validationFailed(errors: string[], language = 'en-US'): I18nError {
223
+ const message = formatICUMessage(
224
+ 'Validation failed with {count, plural, one {{count, number, integer} error} other {{count, number, integer} errors}}: {details}',
225
+ { count: errors.length, details: errors.join(', ') },
226
+ language,
227
+ );
228
+ return new I18nError(I18nErrorCode.VALIDATION_FAILED, message, {
229
+ errors,
230
+ count: errors.length,
231
+ });
232
+ }
233
+
234
+ /**
235
+ * Creates an error for when an i18n instance is not found with nested ICU select formatting.
236
+ * @param key - The instance key that was not found
237
+ * @param language - Optional language code for message formatting
238
+ * @returns An I18nError instance
239
+ */
240
+ static instanceNotFound(key: string, language = 'en-US'): I18nError {
241
+ const isDefault = key === 'default' || key === '';
242
+ const message = formatICUMessage(
243
+ '{isDefault, select, true {Default i18n instance not found} other {I18n instance {key} not found}} in registry',
244
+ { key, isDefault: isDefault ? 'true' : 'false' },
245
+ language,
246
+ );
247
+ return new I18nError(I18nErrorCode.INSTANCE_NOT_FOUND, message, { key });
248
+ }
249
+
250
+ /**
251
+ * Creates an error for when an i18n instance already exists with nested ICU select formatting.
252
+ * @param key - The instance key that already exists
253
+ * @param language - Optional language code for message formatting
254
+ * @returns An I18nError instance
255
+ */
256
+ static instanceExists(key: string, language = 'en-US'): I18nError {
257
+ const isDefault = key === 'default' || key === '';
258
+ const message = formatICUMessage(
259
+ "{isDefault, select, true {Default i18n instance 'default' already exists. Use a different key or remove the existing instance first.} other {I18n instance {key} already exists in registry}}",
260
+ { key, isDefault: isDefault ? 'true' : 'false' },
261
+ language,
262
+ );
263
+ return new I18nError(I18nErrorCode.INSTANCE_EXISTS, message, { key });
264
+ }
265
+
266
+ /**
267
+ * Creates an error for an invalid context key with ICU formatting.
268
+ * @param contextKey - The invalid context key
269
+ * @param language - Optional language code for message formatting
270
+ * @returns An I18nError instance
271
+ */
272
+ static invalidContext(contextKey: string, language = 'en-US'): I18nError {
273
+ const message = formatICUMessage(
274
+ 'Invalid context key {contextKey}',
275
+ { contextKey },
276
+ language,
277
+ );
278
+ return new I18nError(I18nErrorCode.INVALID_CONTEXT, message, {
279
+ contextKey,
280
+ });
281
+ }
282
+
283
+ /**
284
+ * Creates an error for when a plural form is not found with nested ICU select and plural formatting.
285
+ * @param category - The plural category that was not found
286
+ * @param language - The language code
287
+ * @param key - The translation key
288
+ * @param availableForms - Array of available plural forms
289
+ * @returns An I18nError instance
290
+ */
291
+ static pluralFormNotFound(
292
+ category: string,
293
+ language: string,
294
+ key: string,
295
+ availableForms: string[],
296
+ ): I18nError {
297
+ const formCount = availableForms.length;
298
+ const message = formatICUMessage(
299
+ 'Plural form {category} not found for language {language}{hasKey, select, true { in key {keyName}} other {}}. {formCount, plural, one {Available form} other {Available forms}} ({formCount, number, integer}): {forms}',
300
+ {
301
+ category,
302
+ language,
303
+ keyName: key,
304
+ hasKey: key ? 'true' : 'false',
305
+ forms: availableForms.join(', '),
306
+ formCount,
307
+ },
308
+ language,
309
+ );
310
+ return new I18nError(I18nErrorCode.PLURAL_FORM_NOT_FOUND, message, {
311
+ category,
312
+ language,
313
+ key,
314
+ availableForms,
315
+ formCount,
316
+ });
317
+ }
318
+
319
+ /**
320
+ * Creates an error for an invalid plural category with nested ICU plural and number formatting.
321
+ * @param category - The invalid category
322
+ * @param validCategories - Array of valid categories
323
+ * @param language - Optional language code for message formatting
324
+ * @returns An I18nError instance
325
+ */
326
+ static invalidPluralCategory(
327
+ category: string,
328
+ validCategories: string[],
329
+ language = 'en-US',
330
+ ): I18nError {
331
+ const count = validCategories.length;
332
+ const message = formatICUMessage(
333
+ 'Invalid plural category {category}. {count, plural, one {Valid category ({count, number, integer})} other {Valid categories ({count, number, integer})}}: {categories}',
334
+ {
335
+ category,
336
+ categories: validCategories.join(', '),
337
+ count,
338
+ },
339
+ language,
340
+ );
341
+ return new I18nError(I18nErrorCode.INVALID_PLURAL_CATEGORY, message, {
342
+ category,
343
+ validCategories,
344
+ count,
345
+ });
346
+ }
347
+
348
+ /**
349
+ * Creates an error for when the count variable is missing for plural forms with ICU formatting.
350
+ * @param key - The translation key that requires a count variable
351
+ * @param language - Optional language code for message formatting
352
+ * @returns An I18nError instance
353
+ */
354
+ static missingCountVariable(key: string, language = 'en-US'): I18nError {
355
+ const message = formatICUMessage(
356
+ "Plural forms used in key {key} but no 'count' variable provided",
357
+ { key },
358
+ language,
359
+ );
360
+ return new I18nError(I18nErrorCode.MISSING_COUNT_VARIABLE, message, {
361
+ key,
362
+ });
363
+ }
364
+
365
+ /**
366
+ * Creates an error for validation threshold violations with ICU number formatting.
367
+ * Demonstrates currency, percent, and integer formatting based on threshold type.
368
+ * @param fieldName - The field that exceeded the threshold
369
+ * @param value - The actual value
370
+ * @param threshold - The maximum allowed value
371
+ * @param thresholdType - Type of threshold: 'currency', 'percent', or 'integer'
372
+ * @param language - Optional language code for message formatting
373
+ * @returns An I18nError instance
374
+ */
375
+ static validationThresholdExceeded(
376
+ fieldName: string,
377
+ value: number,
378
+ threshold: number,
379
+ thresholdType: 'currency' | 'percent' | 'integer' = 'integer',
380
+ language = 'en-US',
381
+ ): I18nError {
382
+ const message = formatICUMessage(
383
+ 'Validation failed for {fieldName}: value {value, number, ' +
384
+ thresholdType +
385
+ '} exceeds maximum threshold of {threshold, number, ' +
386
+ thresholdType +
387
+ '}',
388
+ { fieldName, value, threshold },
389
+ language,
390
+ );
391
+ return new I18nError(I18nErrorCode.VALIDATION_THRESHOLD_EXCEEDED, message, {
392
+ fieldName,
393
+ value,
394
+ threshold,
395
+ thresholdType,
396
+ });
397
+ }
398
+
399
+ /**
400
+ * Creates an error for operation failures at specific steps with ICU selectordinal formatting.
401
+ * Demonstrates 1st, 2nd, 3rd, etc. formatting for step numbers.
402
+ * @param stepNumber - The step number where the operation failed (1-based)
403
+ * @param operationName - The name of the operation
404
+ * @param reason - The reason for failure
405
+ * @param language - Optional language code for message formatting
406
+ * @returns An I18nError instance
407
+ */
408
+ static operationStepFailed(
409
+ stepNumber: number,
410
+ operationName: string,
411
+ reason: string,
412
+ language = 'en-US',
413
+ ): I18nError {
414
+ const message = formatICUMessage(
415
+ 'Operation {operationName} failed at {stepNumber, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} step: {reason}',
416
+ { stepNumber, operationName, reason },
417
+ language,
418
+ );
419
+ return new I18nError(I18nErrorCode.OPERATION_STEP_FAILED, message, {
420
+ stepNumber,
421
+ operationName,
422
+ reason,
423
+ });
424
+ }
425
+
426
+ /**
427
+ * Creates an error for rate limit violations with nested ICU messages.
428
+ * Demonstrates nested plural, number formatting, and conditional messages.
429
+ * @param requestCount - Number of requests made
430
+ * @param limit - Maximum allowed requests
431
+ * @param windowSeconds - Time window in seconds
432
+ * @param retryAfterSeconds - Seconds until retry is allowed
433
+ * @param language - Optional language code for message formatting
434
+ * @returns An I18nError instance
435
+ */
436
+ static rateLimitExceeded(
437
+ requestCount: number,
438
+ limit: number,
439
+ windowSeconds: number,
440
+ retryAfterSeconds: number,
441
+ language = 'en-US',
442
+ ): I18nError {
443
+ const message = formatICUMessage(
444
+ 'Rate limit exceeded: {requestCount, plural, one {# request} other {# requests}} made, exceeding limit of {limit, number, integer} {limit, plural, one {request} other {requests}} per {windowSeconds, number, integer} {windowSeconds, plural, one {second} other {seconds}}. {hasRetry, select, true {Retry after {retryAfterSeconds, number, integer} {retryAfterSeconds, plural, one {second} other {seconds}}.} other {Retry immediately.}}',
445
+ {
446
+ requestCount,
447
+ limit,
448
+ windowSeconds,
449
+ retryAfterSeconds,
450
+ hasRetry: retryAfterSeconds > 0 ? 'true' : 'false',
451
+ },
452
+ language,
453
+ );
454
+ return new I18nError(I18nErrorCode.RATE_LIMIT_EXCEEDED, message, {
455
+ requestCount,
456
+ limit,
457
+ windowSeconds,
458
+ retryAfterSeconds,
459
+ });
460
+ }
461
+
462
+ /**
463
+ * Creates a nested validation error with multiple layers of context.
464
+ * Demonstrates 4-level deep nested ICU messages with plural, select, and number formatting.
465
+ * @param componentId - The component being validated
466
+ * @param fieldPath - Nested field path (e.g., 'user.profile.settings.theme')
467
+ * @param errorCount - Number of errors found
468
+ * @param errorType - Type of validation error
469
+ * @param severity - Error severity level
470
+ * @param language - Optional language code for message formatting
471
+ * @returns An I18nError instance
472
+ */
473
+ static nestedValidationError(
474
+ componentId: string,
475
+ fieldPath: string,
476
+ errorCount: number,
477
+ errorType: 'type' | 'range' | 'format' | 'required',
478
+ severity: 'low' | 'medium' | 'high' | 'critical',
479
+ language = 'en-US',
480
+ ): I18nError {
481
+ const message = formatICUMessage(
482
+ 'Validation error in component {componentId}: {severity, select, low {Minor issue} medium {Moderate issue} high {Serious issue} critical {Critical issue} other {Issue}} detected in nested field {fieldPath} - {errorType, select, type {Type mismatch} range {Value out of range} format {Invalid format} required {Required field missing} other {Validation error}} with {errorCount, plural, one {# occurrence} other {# occurrences}}',
483
+ { componentId, fieldPath, errorCount, errorType, severity },
484
+ language,
485
+ );
486
+ return new I18nError(I18nErrorCode.NESTED_VALIDATION_ERROR, message, {
487
+ componentId,
488
+ fieldPath,
489
+ errorCount,
490
+ errorType,
491
+ severity,
492
+ });
493
+ }
494
+ }
@@ -7,6 +7,9 @@
7
7
  *
8
8
  * Import from specific files when possible to minimize module loading.
9
9
  */
10
+
11
+ // Re-export from base (no core dependencies)
10
12
  export * from './base';
13
+
14
+ // Re-export from translatable (uses lazy initialization)
11
15
  export * from './translatable-exports';
12
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * TypedError class with proper type safety
3
+ *
4
+ * This class provides a type-safe way to create errors with additional
5
+ * properties without using type casts. It extends the standard Error class
6
+ * and adds support for:
7
+ * - type: Error type classification
8
+ * - componentId: Component identifier where error originated
9
+ * - reasonMap: Map of reasons or context for the error
10
+ * - metadata: Additional metadata associated with the error
11
+ * - cause: Error cause chaining (ES2022 standard)
12
+ */
13
+
14
+ export interface TypedErrorOptions {
15
+ /**
16
+ * Error type classification (e.g., 'validation', 'network', 'auth')
17
+ */
18
+ type: string;
19
+
20
+ /**
21
+ * Component identifier where the error originated
22
+ */
23
+ componentId?: string;
24
+
25
+ /**
26
+ * Map of reasons or context for the error
27
+ */
28
+ reasonMap?: Record<string, unknown>;
29
+
30
+ /**
31
+ * Additional metadata associated with the error
32
+ */
33
+ metadata?: Record<string, unknown>;
34
+
35
+ /**
36
+ * The cause of this error (for error chaining)
37
+ */
38
+ cause?: Error;
39
+ }
40
+
41
+ /**
42
+ * TypedError class that extends Error with additional type-safe properties
43
+ */
44
+ export class TypedError extends Error {
45
+ public override readonly type: string;
46
+ public override readonly componentId?: string;
47
+ public override readonly reasonMap?: Record<string, unknown>;
48
+ public override readonly metadata?: Record<string, unknown>;
49
+
50
+ constructor(message: string, options: TypedErrorOptions) {
51
+ super(message, { cause: options.cause });
52
+ this.type = options.type;
53
+ this.componentId = options.componentId;
54
+ this.reasonMap = options.reasonMap;
55
+ this.metadata = options.metadata;
56
+ this.name = 'TypedError';
57
+
58
+ // Maintain proper prototype chain
59
+ Object.setPrototypeOf(this, TypedError.prototype);
60
+ }
61
+
62
+ /**
63
+ * Check if an error is a TypedError
64
+ */
65
+ static isTypedError(error: unknown): error is TypedError {
66
+ return error instanceof TypedError;
67
+ }
68
+
69
+ /**
70
+ * Convert a standard Error to a TypedError
71
+ */
72
+ static fromError(
73
+ error: Error,
74
+ options: Omit<TypedErrorOptions, 'cause'>,
75
+ ): TypedError {
76
+ return new TypedError(error.message, {
77
+ ...options,
78
+ cause: error,
79
+ });
80
+ }
81
+ }
@@ -2,6 +2,7 @@
2
2
  * Translatable error exports that use lazy initialization
3
3
  * These errors depend on core modules but use lazy loading patterns
4
4
  */
5
+
5
6
  export * from './context-error';
6
7
  export * from './i18n-error';
7
8
  export * from './translatable';
@@ -9,4 +10,3 @@ export * from './translatable-generic';
9
10
  export * from './translatable-handleable-generic';
10
11
  export * from './typed';
11
12
  export * from './typed-handleable';
12
- //# sourceMappingURL=translatable-exports.d.ts.map