@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,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced error base with i18n 3.0/3.5 feature support
|
|
3
|
+
* Provides helper methods for ICU MessageFormat, pluralization, gender, and advanced features
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { formatICUMessage } from '../icu/helpers';
|
|
7
|
+
import { PluralCategory } from '../pluralization/plural-categories';
|
|
8
|
+
import { GenderCategory } from '../gender/gender-categories';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Options for enhanced error message formatting
|
|
12
|
+
*/
|
|
13
|
+
export interface EnhancedErrorOptions {
|
|
14
|
+
/** Variables for ICU substitution */
|
|
15
|
+
variables?: Record<string, string | number | boolean>;
|
|
16
|
+
/** Language code for message formatting */
|
|
17
|
+
language?: string;
|
|
18
|
+
/** Count for plural formatting */
|
|
19
|
+
count?: number;
|
|
20
|
+
/** Gender for gender-aware formatting */
|
|
21
|
+
gender?: GenderCategory;
|
|
22
|
+
/** Additional metadata */
|
|
23
|
+
metadata?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper class providing advanced i18n features for error messages
|
|
28
|
+
* This can be used as a mixin or utility class for error classes
|
|
29
|
+
*/
|
|
30
|
+
export class EnhancedErrorHelper {
|
|
31
|
+
/**
|
|
32
|
+
* Format error message with ICU MessageFormat
|
|
33
|
+
* @param pattern - ICU message pattern
|
|
34
|
+
* @param options - Formatting options
|
|
35
|
+
* @returns Formatted message string
|
|
36
|
+
*/
|
|
37
|
+
static formatMessage(
|
|
38
|
+
pattern: string,
|
|
39
|
+
options: EnhancedErrorOptions = {},
|
|
40
|
+
): string {
|
|
41
|
+
const { variables = {}, language = 'en-US', count, gender } = options;
|
|
42
|
+
|
|
43
|
+
// Add count and gender to variables if provided
|
|
44
|
+
const allVars = {
|
|
45
|
+
...variables,
|
|
46
|
+
...(count !== undefined ? { count } : {}),
|
|
47
|
+
...(gender ? { gender } : {}),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return formatICUMessage(pattern, allVars, language);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create a plural-aware error message
|
|
55
|
+
* @param singularPattern - Pattern for singular form
|
|
56
|
+
* @param pluralPattern - Pattern for plural form
|
|
57
|
+
* @param count - Count value
|
|
58
|
+
* @param options - Additional formatting options
|
|
59
|
+
* @returns Formatted message
|
|
60
|
+
*/
|
|
61
|
+
static formatPlural(
|
|
62
|
+
singularPattern: string,
|
|
63
|
+
pluralPattern: string,
|
|
64
|
+
count: number,
|
|
65
|
+
options: Omit<EnhancedErrorOptions, 'count'> = {},
|
|
66
|
+
): string {
|
|
67
|
+
const pattern = `{count, plural, one {${singularPattern}} other {${pluralPattern}}}`;
|
|
68
|
+
return this.formatMessage(pattern, { ...options, count });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create a gender-aware error message
|
|
73
|
+
* @param patterns - Patterns for different genders
|
|
74
|
+
* @param gender - Gender value
|
|
75
|
+
* @param options - Additional formatting options
|
|
76
|
+
* @returns Formatted message
|
|
77
|
+
*/
|
|
78
|
+
static formatGender(
|
|
79
|
+
patterns: Partial<Record<GenderCategory, string>>,
|
|
80
|
+
gender: GenderCategory,
|
|
81
|
+
options: Omit<EnhancedErrorOptions, 'gender'> = {},
|
|
82
|
+
): string {
|
|
83
|
+
const { male, female, neutral, other } = patterns;
|
|
84
|
+
const selectPattern = `{gender, select, ${male ? `male {${male}}` : ''} ${female ? `female {${female}}` : ''} ${neutral ? `neutral {${neutral}}` : ''} other {${other || patterns.male || patterns.female || patterns.neutral || 'Error'}}}`;
|
|
85
|
+
return this.formatMessage(selectPattern, { ...options, gender });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Format ordinal numbers (1st, 2nd, 3rd, etc.)
|
|
90
|
+
* @param number - The number to format
|
|
91
|
+
* @param pattern - Pattern with {number} placeholder
|
|
92
|
+
* @param options - Additional formatting options
|
|
93
|
+
* @returns Formatted message with ordinal
|
|
94
|
+
*/
|
|
95
|
+
static formatOrdinal(
|
|
96
|
+
number: number,
|
|
97
|
+
pattern: string,
|
|
98
|
+
options: EnhancedErrorOptions = {},
|
|
99
|
+
): string {
|
|
100
|
+
const ordinalPattern = pattern.replace(
|
|
101
|
+
'{number}',
|
|
102
|
+
`{number, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}`
|
|
103
|
+
);
|
|
104
|
+
return this.formatMessage(ordinalPattern, {
|
|
105
|
+
...options,
|
|
106
|
+
variables: { ...options.variables, number },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Format numbers with specific formatting (integer, currency, percent)
|
|
112
|
+
* @param value - Number value
|
|
113
|
+
* @param format - Format type
|
|
114
|
+
* @param pattern - Pattern with {value} placeholder
|
|
115
|
+
* @param options - Additional formatting options
|
|
116
|
+
* @returns Formatted message
|
|
117
|
+
*/
|
|
118
|
+
static formatNumber(
|
|
119
|
+
value: number,
|
|
120
|
+
format: 'integer' | 'currency' | 'percent',
|
|
121
|
+
pattern: string,
|
|
122
|
+
options: EnhancedErrorOptions = {},
|
|
123
|
+
): string {
|
|
124
|
+
const numberPattern = pattern.replace(
|
|
125
|
+
'{value}',
|
|
126
|
+
`{value, number, ${format}}`
|
|
127
|
+
);
|
|
128
|
+
return this.formatMessage(numberPattern, {
|
|
129
|
+
...options,
|
|
130
|
+
variables: { ...options.variables, value },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create nested messages with multiple levels of ICU formatting
|
|
136
|
+
* @param pattern - Complex nested ICU pattern
|
|
137
|
+
* @param options - Formatting options
|
|
138
|
+
* @returns Formatted message
|
|
139
|
+
*/
|
|
140
|
+
static formatNested(
|
|
141
|
+
pattern: string,
|
|
142
|
+
options: EnhancedErrorOptions = {},
|
|
143
|
+
): string {
|
|
144
|
+
return this.formatMessage(pattern, options);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Detect if a string key represents a nested path
|
|
149
|
+
* @param key - String key to check
|
|
150
|
+
* @returns Object with nesting information
|
|
151
|
+
*/
|
|
152
|
+
static analyzeKeyPath(key: string): {
|
|
153
|
+
isNested: boolean;
|
|
154
|
+
depth: number;
|
|
155
|
+
parts: string[];
|
|
156
|
+
} {
|
|
157
|
+
const parts = key.split('.');
|
|
158
|
+
return {
|
|
159
|
+
isNested: parts.length > 1,
|
|
160
|
+
depth: parts.length,
|
|
161
|
+
parts,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create metadata object with count information for debugging
|
|
167
|
+
* @param count - Count value
|
|
168
|
+
* @param additionalMetadata - Additional metadata to include
|
|
169
|
+
* @returns Metadata object
|
|
170
|
+
*/
|
|
171
|
+
static createCountMetadata(
|
|
172
|
+
count: number,
|
|
173
|
+
additionalMetadata: Record<string, any> = {},
|
|
174
|
+
): Record<string, any> {
|
|
175
|
+
return {
|
|
176
|
+
count,
|
|
177
|
+
...additionalMetadata,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Validate that all required ICU variables are provided
|
|
183
|
+
* @param pattern - ICU pattern
|
|
184
|
+
* @param variables - Provided variables
|
|
185
|
+
* @returns Object with validation result
|
|
186
|
+
*/
|
|
187
|
+
static validateVariables(
|
|
188
|
+
pattern: string,
|
|
189
|
+
variables: Record<string, any>,
|
|
190
|
+
): { valid: boolean; missing: string[] } {
|
|
191
|
+
// Extract variable names from ICU pattern
|
|
192
|
+
const variableMatches = pattern.match(/\{([a-zA-Z_][a-zA-Z0-9_]*)/g);
|
|
193
|
+
if (!variableMatches) {
|
|
194
|
+
return { valid: true, missing: [] };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const required = variableMatches
|
|
198
|
+
.map(match => match.substring(1))
|
|
199
|
+
.filter((name, index, self) => self.indexOf(name) === index);
|
|
200
|
+
|
|
201
|
+
const missing = required.filter(name => !(name in variables));
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
valid: missing.length === 0,
|
|
205
|
+
missing,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Mixin function to add enhanced i18n features to error classes
|
|
212
|
+
* @param Base - Base error class
|
|
213
|
+
* @returns Enhanced error class
|
|
214
|
+
*/
|
|
215
|
+
export function withEnhancedI18n<T extends new (...args: any[]) => Error>(
|
|
216
|
+
Base: T
|
|
217
|
+
) {
|
|
218
|
+
return class extends Base {
|
|
219
|
+
public formatMessage(
|
|
220
|
+
pattern: string,
|
|
221
|
+
options: EnhancedErrorOptions = {},
|
|
222
|
+
): string {
|
|
223
|
+
return EnhancedErrorHelper.formatMessage(pattern, options);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public formatPlural(
|
|
227
|
+
singularPattern: string,
|
|
228
|
+
pluralPattern: string,
|
|
229
|
+
count: number,
|
|
230
|
+
options: Omit<EnhancedErrorOptions, 'count'> = {},
|
|
231
|
+
): string {
|
|
232
|
+
return EnhancedErrorHelper.formatPlural(singularPattern, pluralPattern, count, options);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public formatGender(
|
|
236
|
+
patterns: Partial<Record<GenderCategory, string>>,
|
|
237
|
+
gender: GenderCategory,
|
|
238
|
+
options: Omit<EnhancedErrorOptions, 'gender'> = {},
|
|
239
|
+
): string {
|
|
240
|
+
return EnhancedErrorHelper.formatGender(patterns, gender, options);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public formatOrdinal(
|
|
244
|
+
number: number,
|
|
245
|
+
pattern: string,
|
|
246
|
+
options: EnhancedErrorOptions = {},
|
|
247
|
+
): string {
|
|
248
|
+
return EnhancedErrorHelper.formatOrdinal(number, pattern, options);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public formatNumber(
|
|
252
|
+
value: number,
|
|
253
|
+
format: 'integer' | 'currency' | 'percent',
|
|
254
|
+
pattern: string,
|
|
255
|
+
options: EnhancedErrorOptions = {},
|
|
256
|
+
): string {
|
|
257
|
+
return EnhancedErrorHelper.formatNumber(value, format, pattern, options);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { IHandleable } from '../interfaces/handleable';
|
|
2
|
+
import { HandleableErrorOptions } from '../interfaces/handleable-error-options';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extended Error constructor type that includes stack trace capture functionality.
|
|
6
|
+
*/
|
|
7
|
+
type ErrorConstructorWithStack = ErrorConstructor & {
|
|
8
|
+
captureStackTrace?: (target: Error, constructorOpt?: Function) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Base error class that implements IHandleable interface with full i18n support.
|
|
13
|
+
*
|
|
14
|
+
* Provides enhanced error handling capabilities including status codes, handled state tracking,
|
|
15
|
+
* and source data preservation. Fully compatible with all i18n features when used with
|
|
16
|
+
* translation strings.
|
|
17
|
+
*
|
|
18
|
+
* **Supported i18n Features** (via translation strings in derived classes):
|
|
19
|
+
* - ICU MessageFormat: plural, select, selectordinal
|
|
20
|
+
* - Pluralization: 37 languages with CLDR rules
|
|
21
|
+
* - Gender support: male, female, neutral, other
|
|
22
|
+
* - Number formatting: integer, currency, percent
|
|
23
|
+
* - Nested messages: complex patterns
|
|
24
|
+
*
|
|
25
|
+
* **Usage Pattern:**
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Extend HandleableError with translated messages
|
|
28
|
+
* class MyHandleableError extends HandleableError {
|
|
29
|
+
* constructor(componentId: string, stringKey: string, variables?: Record<string, any>) {
|
|
30
|
+
* const engine = I18nEngine.getInstance();
|
|
31
|
+
* const message = engine.translate(componentId, stringKey, variables);
|
|
32
|
+
* const error = new Error(message);
|
|
33
|
+
* super(error, { statusCode: 400 });
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // Register translation with ICU features
|
|
38
|
+
* engine.registerComponent({
|
|
39
|
+
* component: { id: 'api', stringKeys: ['validationError'] },
|
|
40
|
+
* strings: {
|
|
41
|
+
* 'en-US': {
|
|
42
|
+
* validationError: \"{count, plural, one {# field is invalid} other {# fields are invalid}}\"
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Use with i18n features
|
|
48
|
+
* throw new MyHandleableError('api', 'validationError', { count: 3 });
|
|
49
|
+
* // Result: \"3 fields are invalid\"
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export class HandleableError extends Error implements IHandleable {
|
|
53
|
+
/** The original error that caused this error */
|
|
54
|
+
public override readonly cause?: Error;
|
|
55
|
+
/** HTTP status code associated with this error */
|
|
56
|
+
public readonly statusCode: number;
|
|
57
|
+
/** Optional source data related to the error */
|
|
58
|
+
public readonly sourceData?: unknown;
|
|
59
|
+
/** Internal tracking of whether this error has been handled */
|
|
60
|
+
private _handled: boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new HandleableError instance.
|
|
64
|
+
* @param source - The original error being wrapped
|
|
65
|
+
* @param options - Optional configuration for the error
|
|
66
|
+
*/
|
|
67
|
+
constructor(source: Error, options?: HandleableErrorOptions) {
|
|
68
|
+
super(source.message);
|
|
69
|
+
this.name = this.constructor.name;
|
|
70
|
+
this.cause = options?.cause ?? source;
|
|
71
|
+
this.statusCode = options?.statusCode ?? 500;
|
|
72
|
+
this._handled = options?.handled ?? false;
|
|
73
|
+
this.sourceData = options?.sourceData;
|
|
74
|
+
this.name = 'HandleableError';
|
|
75
|
+
|
|
76
|
+
// Capture stack trace - prioritize source stack, then capture new one
|
|
77
|
+
if (source.stack) {
|
|
78
|
+
this.stack = source.stack;
|
|
79
|
+
} else if ((Error as ErrorConstructorWithStack).captureStackTrace) {
|
|
80
|
+
(Error as ErrorConstructorWithStack).captureStackTrace?.(
|
|
81
|
+
this,
|
|
82
|
+
this.constructor,
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
this.stack = new Error().stack;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Gets the handled state of this error.
|
|
91
|
+
* @returns True if the error has been handled, false otherwise
|
|
92
|
+
*/
|
|
93
|
+
public get handled(): boolean {
|
|
94
|
+
return this._handled;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sets the handled state of this error.
|
|
99
|
+
* @param value - The new handled state
|
|
100
|
+
*/
|
|
101
|
+
public set handled(value: boolean) {
|
|
102
|
+
this._handled = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Serializes a value to a JSON-compatible format.
|
|
107
|
+
* Handles objects with toJSON methods, Error instances, arrays, and plain objects.
|
|
108
|
+
* @param value - The value to serialize
|
|
109
|
+
* @returns The serialized value
|
|
110
|
+
*/
|
|
111
|
+
private serializeValue(value: unknown): unknown {
|
|
112
|
+
if (
|
|
113
|
+
value &&
|
|
114
|
+
typeof value === 'object' &&
|
|
115
|
+
'toJSON' in value &&
|
|
116
|
+
typeof value.toJSON === 'function'
|
|
117
|
+
) {
|
|
118
|
+
return value.toJSON();
|
|
119
|
+
}
|
|
120
|
+
if (value instanceof Error) {
|
|
121
|
+
return value.message;
|
|
122
|
+
}
|
|
123
|
+
if (Array.isArray(value)) {
|
|
124
|
+
return value.map((item) => this.serializeValue(item));
|
|
125
|
+
}
|
|
126
|
+
if (value && typeof value === 'object') {
|
|
127
|
+
return Object.fromEntries(
|
|
128
|
+
Object.entries(value).map(([k, v]) => [k, this.serializeValue(v)]),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Converts the error to a JSON-serializable object.
|
|
136
|
+
* Includes name, message, status code, handled state, stack trace, and optional source data.
|
|
137
|
+
* @returns A plain object representation of the error
|
|
138
|
+
*/
|
|
139
|
+
public toJSON(): Record<string, unknown> {
|
|
140
|
+
return {
|
|
141
|
+
name: this.name,
|
|
142
|
+
message: this.message,
|
|
143
|
+
statusCode: this.statusCode,
|
|
144
|
+
handled: this.handled,
|
|
145
|
+
stack: this.stack,
|
|
146
|
+
cause: this.serializeValue(this.cause),
|
|
147
|
+
...(this.sourceData
|
|
148
|
+
? { sourceData: this.serializeValue(this.sourceData) }
|
|
149
|
+
: {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|