@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.
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/package.json +12 -4
- package/src/{active-context.d.ts → active-context.ts} +0 -1
- package/src/builders/i18n-builder.ts +82 -0
- package/src/builders/{index.d.ts → index.ts} +1 -1
- package/src/component-definition.ts +11 -0
- package/src/component-registration.ts +29 -0
- package/src/component-registry.ts +432 -0
- package/src/context-error-type.ts +7 -0
- package/src/core/component-store.ts +241 -0
- package/src/core/context-manager.ts +113 -0
- package/src/core/enum-registry.ts +106 -0
- package/src/core/i18n-engine.ts +710 -0
- package/src/core/{index.d.ts → index.ts} +4 -1
- package/src/core/language-registry.ts +345 -0
- package/src/{core-component-id.d.ts → core-component-id.ts} +1 -2
- package/src/core-i18n.ts +270 -0
- package/src/core-plugin-factory.ts +111 -0
- package/src/core-string-key.ts +59 -0
- package/src/create-translation-adapter.ts +93 -0
- package/src/enum-registry.ts +152 -0
- package/src/errors/{base.d.ts → base.ts} +1 -1
- package/src/errors/context-error.ts +122 -0
- package/src/errors/enhanced-error-base.ts +260 -0
- package/src/errors/handleable.ts +152 -0
- package/src/errors/i18n-error.ts +494 -0
- package/src/errors/{index.d.ts → index.ts} +4 -1
- package/src/errors/simple-typed-error.ts +81 -0
- package/src/errors/{translatable-exports.d.ts → translatable-exports.ts} +1 -1
- package/src/errors/translatable-generic.ts +245 -0
- package/src/errors/translatable-handleable-generic.ts +222 -0
- package/src/errors/translatable.ts +138 -0
- package/src/errors/typed-handleable.ts +138 -0
- package/src/errors/typed.ts +617 -0
- package/src/gender/{gender-categories.d.ts → gender-categories.ts} +6 -2
- package/src/gender/gender-resolver.ts +40 -0
- package/src/gender/{index.d.ts → index.ts} +0 -1
- package/src/global-active-context.ts +266 -0
- package/src/icu/ast.ts +56 -0
- package/src/icu/compiler.ts +96 -0
- package/src/icu/formatter-registry.ts +36 -0
- package/src/icu/formatters/base-formatter.ts +8 -0
- package/src/icu/formatters/date-formatter.ts +30 -0
- package/src/icu/formatters/number-formatter.ts +32 -0
- package/src/icu/formatters/plural-formatter.ts +12 -0
- package/src/icu/formatters/select-formatter.ts +7 -0
- package/src/icu/formatters/selectordinal-formatter.ts +17 -0
- package/src/icu/formatters/time-formatter.ts +30 -0
- package/src/icu/helpers.ts +34 -0
- package/src/icu/parser.ts +242 -0
- package/src/icu/runtime.ts +37 -0
- package/src/icu/tokenizer.ts +212 -0
- package/src/icu/validator.ts +163 -0
- package/src/{index.d.ts → index.ts} +38 -6
- package/src/interfaces/active-context.interface.ts +41 -0
- package/src/interfaces/component-config.interface.ts +17 -0
- package/src/interfaces/engine-config.interface.ts +22 -0
- package/src/interfaces/global-active-context.ts +39 -0
- package/src/interfaces/handleable-error-options.ts +13 -0
- package/src/interfaces/handleable.ts +20 -0
- package/src/interfaces/i18n-engine.interface.ts +57 -0
- package/src/interfaces/{index.d.ts → index.ts} +1 -1
- package/src/interfaces/language-definition.interface.ts +17 -0
- package/src/interfaces/translation-options.interface.ts +15 -0
- package/src/interfaces/validation-result.interface.ts +24 -0
- package/src/language-codes.ts +40 -0
- package/src/language-definition.ts +13 -0
- package/src/plugin-i18n-engine.ts +707 -0
- package/src/pluralization/{index.d.ts → index.ts} +1 -1
- package/src/pluralization/language-plural-map.ts +186 -0
- package/src/pluralization/{plural-categories.d.ts → plural-categories.ts} +5 -3
- package/src/pluralization/plural-rules.ts +228 -0
- package/src/registry-config.ts +16 -0
- package/src/registry-error-type.ts +19 -0
- package/src/registry-error.ts +100 -0
- package/src/strict-types.ts +35 -0
- package/src/strings/de.ts +75 -0
- package/src/strings/en-GB.ts +74 -0
- package/src/strings/en-US.ts +74 -0
- package/src/strings/es.ts +74 -0
- package/src/strings/fr.ts +75 -0
- package/src/strings/ja.ts +73 -0
- package/src/strings/uk.ts +73 -0
- package/src/strings/zh-CN.ts +72 -0
- package/src/template.ts +72 -0
- package/src/translation-engine.ts +18 -0
- package/src/translation-request.ts +12 -0
- package/src/translation-response.ts +8 -0
- package/src/types/engine.ts +55 -0
- package/src/types/{index.d.ts → index.ts} +1 -1
- package/src/types/{plural-types.d.ts → plural-types.ts} +29 -3
- package/src/{types.d.ts → types.ts} +72 -21
- package/src/utils/currency.ts +141 -0
- package/src/utils/html-escape.ts +55 -0
- package/src/utils/{index.d.ts → index.ts} +0 -1
- package/src/utils/lru-cache.ts +76 -0
- package/src/utils/{plural-helpers.d.ts → plural-helpers.ts} +14 -4
- package/src/utils/{safe-object.js → safe-object.ts} +37 -34
- package/src/utils/string-utils.ts +77 -0
- package/src/utils/timezone.ts +76 -0
- package/src/utils/validation.ts +66 -0
- package/src/utils.ts +215 -0
- package/src/validation/{index.d.ts → index.ts} +0 -1
- package/src/validation/plural-validator.ts +168 -0
- package/src/validation-config.ts +11 -0
- package/src/validation-result.ts +12 -0
- package/src/active-context.d.ts.map +0 -1
- package/src/active-context.js +0 -3
- package/src/active-context.js.map +0 -1
- package/src/builders/i18n-builder.d.ts +0 -26
- package/src/builders/i18n-builder.d.ts.map +0 -1
- package/src/builders/i18n-builder.js +0 -70
- package/src/builders/i18n-builder.js.map +0 -1
- package/src/builders/index.d.ts.map +0 -1
- package/src/builders/index.js +0 -8
- package/src/builders/index.js.map +0 -1
- package/src/component-definition.d.ts +0 -12
- package/src/component-definition.d.ts.map +0 -1
- package/src/component-definition.js +0 -3
- package/src/component-definition.js.map +0 -1
- package/src/component-registration.d.ts +0 -22
- package/src/component-registration.d.ts.map +0 -1
- package/src/component-registration.js +0 -3
- package/src/component-registration.js.map +0 -1
- package/src/component-registry.d.ts +0 -102
- package/src/component-registry.d.ts.map +0 -1
- package/src/component-registry.js +0 -282
- package/src/component-registry.js.map +0 -1
- package/src/context-error-type.d.ts +0 -8
- package/src/context-error-type.d.ts.map +0 -1
- package/src/context-error-type.js +0 -12
- package/src/context-error-type.js.map +0 -1
- package/src/core/component-store.d.ts +0 -93
- package/src/core/component-store.d.ts.map +0 -1
- package/src/core/component-store.js +0 -198
- package/src/core/component-store.js.map +0 -1
- package/src/core/context-manager.d.ts +0 -72
- package/src/core/context-manager.d.ts.map +0 -1
- package/src/core/context-manager.js +0 -98
- package/src/core/context-manager.js.map +0 -1
- package/src/core/enum-registry.d.ts +0 -48
- package/src/core/enum-registry.d.ts.map +0 -1
- package/src/core/enum-registry.js +0 -85
- package/src/core/enum-registry.js.map +0 -1
- package/src/core/i18n-engine.d.ts +0 -241
- package/src/core/i18n-engine.d.ts.map +0 -1
- package/src/core/i18n-engine.js +0 -568
- package/src/core/i18n-engine.js.map +0 -1
- package/src/core/index.d.ts.map +0 -1
- package/src/core/index.js +0 -21
- package/src/core/index.js.map +0 -1
- package/src/core/language-registry.d.ts +0 -180
- package/src/core/language-registry.d.ts.map +0 -1
- package/src/core/language-registry.js +0 -298
- package/src/core/language-registry.js.map +0 -1
- package/src/core-component-id.d.ts.map +0 -1
- package/src/core-component-id.js +0 -9
- package/src/core-component-id.js.map +0 -1
- package/src/core-i18n.d.ts +0 -69
- package/src/core-i18n.d.ts.map +0 -1
- package/src/core-i18n.js +0 -219
- package/src/core-i18n.js.map +0 -1
- package/src/core-plugin-factory.d.ts +0 -28
- package/src/core-plugin-factory.d.ts.map +0 -1
- package/src/core-plugin-factory.js +0 -80
- package/src/core-plugin-factory.js.map +0 -1
- package/src/core-string-key.d.ts +0 -52
- package/src/core-string-key.d.ts.map +0 -1
- package/src/core-string-key.js +0 -61
- package/src/core-string-key.js.map +0 -1
- package/src/create-translation-adapter.d.ts +0 -33
- package/src/create-translation-adapter.d.ts.map +0 -1
- package/src/create-translation-adapter.js +0 -72
- package/src/create-translation-adapter.js.map +0 -1
- package/src/enum-registry.d.ts +0 -65
- package/src/enum-registry.d.ts.map +0 -1
- package/src/enum-registry.js +0 -123
- package/src/enum-registry.js.map +0 -1
- package/src/errors/base.d.ts.map +0 -1
- package/src/errors/base.js +0 -11
- package/src/errors/base.js.map +0 -1
- package/src/errors/context-error.d.ts +0 -50
- package/src/errors/context-error.d.ts.map +0 -1
- package/src/errors/context-error.js +0 -93
- package/src/errors/context-error.js.map +0 -1
- package/src/errors/enhanced-error-base.d.ts +0 -125
- package/src/errors/enhanced-error-base.d.ts.map +0 -1
- package/src/errors/enhanced-error-base.js +0 -165
- package/src/errors/enhanced-error-base.js.map +0 -1
- package/src/errors/handleable.d.ts +0 -83
- package/src/errors/handleable.d.ts.map +0 -1
- package/src/errors/handleable.js +0 -136
- package/src/errors/handleable.js.map +0 -1
- package/src/errors/i18n-error.d.ts +0 -211
- package/src/errors/i18n-error.d.ts.map +0 -1
- package/src/errors/i18n-error.js +0 -358
- package/src/errors/i18n-error.js.map +0 -1
- package/src/errors/index.d.ts.map +0 -1
- package/src/errors/index.js +0 -17
- package/src/errors/index.js.map +0 -1
- package/src/errors/simple-typed-error.d.ts +0 -53
- package/src/errors/simple-typed-error.d.ts.map +0 -1
- package/src/errors/simple-typed-error.js +0 -51
- package/src/errors/simple-typed-error.js.map +0 -1
- package/src/errors/translatable-exports.d.ts.map +0 -1
- package/src/errors/translatable-exports.js +0 -15
- package/src/errors/translatable-exports.js.map +0 -1
- package/src/errors/translatable-generic.d.ts +0 -87
- package/src/errors/translatable-generic.d.ts.map +0 -1
- package/src/errors/translatable-generic.js +0 -139
- package/src/errors/translatable-generic.js.map +0 -1
- package/src/errors/translatable-handleable-generic.d.ts +0 -116
- package/src/errors/translatable-handleable-generic.d.ts.map +0 -1
- package/src/errors/translatable-handleable-generic.js +0 -121
- package/src/errors/translatable-handleable-generic.js.map +0 -1
- package/src/errors/translatable.d.ts +0 -63
- package/src/errors/translatable.d.ts.map +0 -1
- package/src/errors/translatable.js +0 -85
- package/src/errors/translatable.js.map +0 -1
- package/src/errors/typed-handleable.d.ts +0 -62
- package/src/errors/typed-handleable.d.ts.map +0 -1
- package/src/errors/typed-handleable.js +0 -108
- package/src/errors/typed-handleable.js.map +0 -1
- package/src/errors/typed.d.ts +0 -206
- package/src/errors/typed.d.ts.map +0 -1
- package/src/errors/typed.js +0 -458
- package/src/errors/typed.js.map +0 -1
- package/src/gender/gender-categories.d.ts.map +0 -1
- package/src/gender/gender-categories.js +0 -15
- package/src/gender/gender-categories.js.map +0 -1
- package/src/gender/gender-resolver.d.ts +0 -14
- package/src/gender/gender-resolver.d.ts.map +0 -1
- package/src/gender/gender-resolver.js +0 -35
- package/src/gender/gender-resolver.js.map +0 -1
- package/src/gender/index.d.ts.map +0 -1
- package/src/gender/index.js +0 -6
- package/src/gender/index.js.map +0 -1
- package/src/global-active-context.d.ts +0 -50
- package/src/global-active-context.d.ts.map +0 -1
- package/src/global-active-context.js +0 -185
- package/src/global-active-context.js.map +0 -1
- package/src/icu/ast.d.ts +0 -48
- package/src/icu/ast.d.ts.map +0 -1
- package/src/icu/ast.js +0 -16
- package/src/icu/ast.js.map +0 -1
- package/src/icu/compiler.d.ts +0 -16
- package/src/icu/compiler.d.ts.map +0 -1
- package/src/icu/compiler.js +0 -87
- package/src/icu/compiler.js.map +0 -1
- package/src/icu/formatter-registry.d.ts +0 -10
- package/src/icu/formatter-registry.d.ts.map +0 -1
- package/src/icu/formatter-registry.js +0 -34
- package/src/icu/formatter-registry.js.map +0 -1
- package/src/icu/formatters/base-formatter.d.ts +0 -8
- package/src/icu/formatters/base-formatter.d.ts.map +0 -1
- package/src/icu/formatters/base-formatter.js +0 -3
- package/src/icu/formatters/base-formatter.js.map +0 -1
- package/src/icu/formatters/date-formatter.d.ts +0 -5
- package/src/icu/formatters/date-formatter.d.ts.map +0 -1
- package/src/icu/formatters/date-formatter.js +0 -31
- package/src/icu/formatters/date-formatter.js.map +0 -1
- package/src/icu/formatters/number-formatter.d.ts +0 -5
- package/src/icu/formatters/number-formatter.d.ts.map +0 -1
- package/src/icu/formatters/number-formatter.js +0 -33
- package/src/icu/formatters/number-formatter.js.map +0 -1
- package/src/icu/formatters/plural-formatter.d.ts +0 -5
- package/src/icu/formatters/plural-formatter.d.ts.map +0 -1
- package/src/icu/formatters/plural-formatter.js +0 -15
- package/src/icu/formatters/plural-formatter.js.map +0 -1
- package/src/icu/formatters/select-formatter.d.ts +0 -5
- package/src/icu/formatters/select-formatter.d.ts.map +0 -1
- package/src/icu/formatters/select-formatter.js +0 -10
- package/src/icu/formatters/select-formatter.js.map +0 -1
- package/src/icu/formatters/selectordinal-formatter.d.ts +0 -5
- package/src/icu/formatters/selectordinal-formatter.d.ts.map +0 -1
- package/src/icu/formatters/selectordinal-formatter.js +0 -22
- package/src/icu/formatters/selectordinal-formatter.js.map +0 -1
- package/src/icu/formatters/time-formatter.d.ts +0 -5
- package/src/icu/formatters/time-formatter.d.ts.map +0 -1
- package/src/icu/formatters/time-formatter.js +0 -31
- package/src/icu/formatters/time-formatter.js.map +0 -1
- package/src/icu/helpers.d.ts +0 -9
- package/src/icu/helpers.d.ts.map +0 -1
- package/src/icu/helpers.js +0 -31
- package/src/icu/helpers.js.map +0 -1
- package/src/icu/parser.d.ts +0 -31
- package/src/icu/parser.d.ts.map +0 -1
- package/src/icu/parser.js +0 -203
- package/src/icu/parser.js.map +0 -1
- package/src/icu/runtime.d.ts +0 -10
- package/src/icu/runtime.d.ts.map +0 -1
- package/src/icu/runtime.js +0 -33
- package/src/icu/runtime.js.map +0 -1
- package/src/icu/tokenizer.d.ts +0 -37
- package/src/icu/tokenizer.d.ts.map +0 -1
- package/src/icu/tokenizer.js +0 -187
- package/src/icu/tokenizer.js.map +0 -1
- package/src/icu/validator.d.ts +0 -11
- package/src/icu/validator.d.ts.map +0 -1
- package/src/icu/validator.js +0 -140
- package/src/icu/validator.js.map +0 -1
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -76
- package/src/index.js.map +0 -1
- package/src/interfaces/active-context.interface.d.ts +0 -36
- package/src/interfaces/active-context.interface.d.ts.map +0 -1
- package/src/interfaces/active-context.interface.js +0 -3
- package/src/interfaces/active-context.interface.js.map +0 -1
- package/src/interfaces/component-config.interface.d.ts +0 -16
- package/src/interfaces/component-config.interface.d.ts.map +0 -1
- package/src/interfaces/component-config.interface.js +0 -6
- package/src/interfaces/component-config.interface.js.map +0 -1
- package/src/interfaces/engine-config.interface.d.ts +0 -22
- package/src/interfaces/engine-config.interface.d.ts.map +0 -1
- package/src/interfaces/engine-config.interface.js +0 -6
- package/src/interfaces/engine-config.interface.js.map +0 -1
- package/src/interfaces/global-active-context.d.ts +0 -23
- package/src/interfaces/global-active-context.d.ts.map +0 -1
- package/src/interfaces/global-active-context.js +0 -3
- package/src/interfaces/global-active-context.js.map +0 -1
- package/src/interfaces/handleable-error-options.d.ts +0 -14
- package/src/interfaces/handleable-error-options.d.ts.map +0 -1
- package/src/interfaces/handleable-error-options.js +0 -3
- package/src/interfaces/handleable-error-options.js.map +0 -1
- package/src/interfaces/handleable.d.ts +0 -21
- package/src/interfaces/handleable.d.ts.map +0 -1
- package/src/interfaces/handleable.js +0 -3
- package/src/interfaces/handleable.js.map +0 -1
- package/src/interfaces/i18n-engine.interface.d.ts +0 -46
- package/src/interfaces/i18n-engine.interface.d.ts.map +0 -1
- package/src/interfaces/i18n-engine.interface.js +0 -6
- package/src/interfaces/i18n-engine.interface.js.map +0 -1
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js +0 -7
- package/src/interfaces/index.js.map +0 -1
- package/src/interfaces/language-definition.interface.d.ts +0 -17
- package/src/interfaces/language-definition.interface.d.ts.map +0 -1
- package/src/interfaces/language-definition.interface.js +0 -6
- package/src/interfaces/language-definition.interface.js.map +0 -1
- package/src/interfaces/translation-options.interface.d.ts +0 -15
- package/src/interfaces/translation-options.interface.d.ts.map +0 -1
- package/src/interfaces/translation-options.interface.js +0 -6
- package/src/interfaces/translation-options.interface.js.map +0 -1
- package/src/interfaces/validation-result.interface.d.ts +0 -24
- package/src/interfaces/validation-result.interface.d.ts.map +0 -1
- package/src/interfaces/validation-result.interface.js +0 -6
- package/src/interfaces/validation-result.interface.js.map +0 -1
- package/src/language-codes.d.ts +0 -28
- package/src/language-codes.d.ts.map +0 -1
- package/src/language-codes.js +0 -32
- package/src/language-codes.js.map +0 -1
- package/src/language-definition.d.ts +0 -14
- package/src/language-definition.d.ts.map +0 -1
- package/src/language-definition.js +0 -3
- package/src/language-definition.js.map +0 -1
- package/src/plugin-i18n-engine.d.ts +0 -164
- package/src/plugin-i18n-engine.d.ts.map +0 -1
- package/src/plugin-i18n-engine.js +0 -493
- package/src/plugin-i18n-engine.js.map +0 -1
- package/src/pluralization/index.d.ts.map +0 -1
- package/src/pluralization/index.js +0 -10
- package/src/pluralization/index.js.map +0 -1
- package/src/pluralization/language-plural-map.d.ts +0 -29
- package/src/pluralization/language-plural-map.d.ts.map +0 -1
- package/src/pluralization/language-plural-map.js +0 -155
- package/src/pluralization/language-plural-map.js.map +0 -1
- package/src/pluralization/plural-categories.d.ts.map +0 -1
- package/src/pluralization/plural-categories.js +0 -8
- package/src/pluralization/plural-categories.js.map +0 -1
- package/src/pluralization/plural-rules.d.ts +0 -102
- package/src/pluralization/plural-rules.d.ts.map +0 -1
- package/src/pluralization/plural-rules.js +0 -263
- package/src/pluralization/plural-rules.js.map +0 -1
- package/src/registry-config.d.ts +0 -16
- package/src/registry-config.d.ts.map +0 -1
- package/src/registry-config.js +0 -3
- package/src/registry-config.js.map +0 -1
- package/src/registry-error-type.d.ts +0 -20
- package/src/registry-error-type.d.ts.map +0 -1
- package/src/registry-error-type.js +0 -24
- package/src/registry-error-type.js.map +0 -1
- package/src/registry-error.d.ts +0 -25
- package/src/registry-error.d.ts.map +0 -1
- package/src/registry-error.js +0 -63
- package/src/registry-error.js.map +0 -1
- package/src/strict-types.d.ts +0 -19
- package/src/strict-types.d.ts.map +0 -1
- package/src/strict-types.js +0 -18
- package/src/strict-types.js.map +0 -1
- package/src/strings/de.d.ts +0 -3
- package/src/strings/de.d.ts.map +0 -1
- package/src/strings/de.js +0 -57
- package/src/strings/de.js.map +0 -1
- package/src/strings/en-GB.d.ts +0 -3
- package/src/strings/en-GB.d.ts.map +0 -1
- package/src/strings/en-GB.js +0 -57
- package/src/strings/en-GB.js.map +0 -1
- package/src/strings/en-US.d.ts +0 -3
- package/src/strings/en-US.d.ts.map +0 -1
- package/src/strings/en-US.js +0 -57
- package/src/strings/en-US.js.map +0 -1
- package/src/strings/es.d.ts +0 -3
- package/src/strings/es.d.ts.map +0 -1
- package/src/strings/es.js +0 -57
- package/src/strings/es.js.map +0 -1
- package/src/strings/fr.d.ts +0 -3
- package/src/strings/fr.d.ts.map +0 -1
- package/src/strings/fr.js +0 -57
- package/src/strings/fr.js.map +0 -1
- package/src/strings/ja.d.ts +0 -3
- package/src/strings/ja.d.ts.map +0 -1
- package/src/strings/ja.js +0 -57
- package/src/strings/ja.js.map +0 -1
- package/src/strings/uk.d.ts +0 -3
- package/src/strings/uk.d.ts.map +0 -1
- package/src/strings/uk.js +0 -57
- package/src/strings/uk.js.map +0 -1
- package/src/strings/zh-CN.d.ts +0 -3
- package/src/strings/zh-CN.d.ts.map +0 -1
- package/src/strings/zh-CN.js +0 -57
- package/src/strings/zh-CN.js.map +0 -1
- package/src/template.d.ts +0 -13
- package/src/template.d.ts.map +0 -1
- package/src/template.js +0 -40
- package/src/template.js.map +0 -1
- package/src/translation-engine.d.ts +0 -9
- package/src/translation-engine.d.ts.map +0 -1
- package/src/translation-engine.js +0 -3
- package/src/translation-engine.js.map +0 -1
- package/src/translation-request.d.ts +0 -10
- package/src/translation-request.d.ts.map +0 -1
- package/src/translation-request.js +0 -3
- package/src/translation-request.js.map +0 -1
- package/src/translation-response.d.ts +0 -9
- package/src/translation-response.d.ts.map +0 -1
- package/src/translation-response.js +0 -3
- package/src/translation-response.js.map +0 -1
- package/src/types/engine.d.ts +0 -47
- package/src/types/engine.d.ts.map +0 -1
- package/src/types/engine.js +0 -8
- package/src/types/engine.js.map +0 -1
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -9
- package/src/types/index.js.map +0 -1
- package/src/types/plural-types.d.ts.map +0 -1
- package/src/types/plural-types.js +0 -39
- package/src/types/plural-types.js.map +0 -1
- package/src/types.d.ts.map +0 -1
- package/src/types.js +0 -23
- package/src/types.js.map +0 -1
- package/src/utils/currency.d.ts +0 -81
- package/src/utils/currency.d.ts.map +0 -1
- package/src/utils/currency.js +0 -99
- package/src/utils/currency.js.map +0 -1
- package/src/utils/html-escape.d.ts +0 -22
- package/src/utils/html-escape.d.ts.map +0 -1
- package/src/utils/html-escape.js +0 -53
- package/src/utils/html-escape.js.map +0 -1
- package/src/utils/index.d.ts.map +0 -1
- package/src/utils/index.js +0 -12
- package/src/utils/index.js.map +0 -1
- package/src/utils/lru-cache.d.ts +0 -42
- package/src/utils/lru-cache.d.ts.map +0 -1
- package/src/utils/lru-cache.js +0 -73
- package/src/utils/lru-cache.js.map +0 -1
- package/src/utils/plural-helpers.d.ts.map +0 -1
- package/src/utils/plural-helpers.js +0 -35
- package/src/utils/plural-helpers.js.map +0 -1
- package/src/utils/safe-object.d.ts +0 -39
- package/src/utils/safe-object.d.ts.map +0 -1
- package/src/utils/safe-object.js.map +0 -1
- package/src/utils/string-utils.d.ts +0 -28
- package/src/utils/string-utils.d.ts.map +0 -1
- package/src/utils/string-utils.js +0 -63
- package/src/utils/string-utils.js.map +0 -1
- package/src/utils/timezone.d.ts +0 -50
- package/src/utils/timezone.d.ts.map +0 -1
- package/src/utils/timezone.js +0 -74
- package/src/utils/timezone.js.map +0 -1
- package/src/utils/validation.d.ts +0 -40
- package/src/utils/validation.d.ts.map +0 -1
- package/src/utils/validation.js +0 -69
- package/src/utils/validation.js.map +0 -1
- package/src/utils.d.ts +0 -65
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -129
- package/src/utils.js.map +0 -1
- package/src/validation/index.d.ts.map +0 -1
- package/src/validation/index.js +0 -5
- package/src/validation/index.js.map +0 -1
- package/src/validation/plural-validator.d.ts +0 -46
- package/src/validation/plural-validator.d.ts.map +0 -1
- package/src/validation/plural-validator.js +0 -123
- package/src/validation/plural-validator.js.map +0 -1
- package/src/validation-config.d.ts +0 -12
- package/src/validation-config.d.ts.map +0 -1
- package/src/validation-config.js +0 -3
- package/src/validation-config.js.map +0 -1
- package/src/validation-result.d.ts +0 -13
- package/src/validation-result.d.ts.map +0 -1
- package/src/validation-result.js +0 -3
- 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
|