@vielzeug/i18nit 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/i18n.cjs +1 -1
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.d.ts +2 -76
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +142 -179
- package/dist/i18n.js.map +1 -1
- package/dist/i18nit.cjs +1 -1
- package/dist/i18nit.cjs.map +1 -1
- package/dist/i18nit.js +1 -1
- package/dist/i18nit.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/core.cjs +0 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -35
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js +0 -53
- package/dist/core.js.map +0 -1
- package/dist/i18nit.d.ts +0 -3
- package/dist/i18nit.d.ts.map +0 -1
package/dist/core.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","names":["#core","#fixedLocale","#prefix","#key"],"sources":["../src/core.ts"],"sourcesContent":["import type { BoundI18n, Locale, MessageValue, Messages, NamespaceKeys, TranslationKeyParam, Vars } from './types';\n\n/* -------------------- I18nCore -------------------- */\n\n/**\n * Module-private interface given to every `BoundView` — exposes only the operations views need.\n * Created once per `I18n` instance so `scope()` / `withLocale()` allocate no closures per call.\n */\nexport type I18nCore = {\n checkOwn(key: string, locale: Locale): boolean;\n findMessage(key: string, locale: Locale): MessageValue | undefined;\n formatDate(value: Date | number, options: Intl.DateTimeFormatOptions | undefined, locale: Locale): string;\n formatList(items: unknown[], locale: string, type: 'and' | 'or'): string;\n formatNumber(value: number, options: Intl.NumberFormatOptions | undefined, locale: Locale): string;\n formatRelative(\n value: number,\n unit: Intl.RelativeTimeFormatUnit,\n options: Intl.RelativeTimeFormatOptions | undefined,\n locale: Locale,\n ): string;\n getLocale(): Locale;\n translate(key: string, vars: Vars | undefined, locale: Locale): string;\n};\n\n/* -------------------- BoundView -------------------- */\n\n/**\n * Lightweight view over an `I18n` instance, fixed to a locale and/or key namespace prefix.\n * All methods live on the prototype — no closures are allocated per `scope()` / `withLocale()` call.\n */\nexport class BoundView<T extends Messages = Messages> implements BoundI18n<T> {\n readonly #core: I18nCore;\n readonly #fixedLocale: Locale | null;\n readonly #prefix: string | undefined;\n\n constructor(core: I18nCore, fixedLocale: Locale | null, prefix?: string) {\n this.#core = core;\n this.#fixedLocale = fixedLocale;\n this.#prefix = prefix;\n }\n\n get locale(): Locale {\n return this.#fixedLocale ?? this.#core.getLocale();\n }\n\n #key(key: string): string {\n return this.#prefix ? `${this.#prefix}.${key}` : key;\n }\n\n t(key: TranslationKeyParam<T>, vars?: Vars): string {\n return this.#core.translate(this.#key(key as string), vars, this.locale);\n }\n\n has(key: string): boolean {\n return this.#core.findMessage(this.#key(key), this.locale) !== undefined;\n }\n\n hasOwn(key: string): boolean {\n return this.#core.checkOwn(this.#key(key), this.locale);\n }\n\n number(value: number, options?: Intl.NumberFormatOptions): string {\n return this.#core.formatNumber(value, options, this.locale);\n }\n\n date(value: Date | number, options?: Intl.DateTimeFormatOptions): string {\n return this.#core.formatDate(value, options, this.locale);\n }\n\n list(items: unknown[], type: 'and' | 'or' = 'and'): string {\n return this.#core.formatList(items, this.locale, type);\n }\n\n relative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string {\n return this.#core.formatRelative(value, unit, options, this.locale);\n }\n\n currency(value: number, currency: string, options?: Omit<Intl.NumberFormatOptions, 'style' | 'currency'>): string {\n return this.#core.formatNumber(value, { ...options, currency, style: 'currency' }, this.locale);\n }\n\n scope<K extends NamespaceKeys<T>>(ns: K): BoundI18n<T[K] & Messages> {\n return new BoundView(\n this.#core,\n this.#fixedLocale,\n this.#prefix ? `${this.#prefix}.${String(ns)}` : String(ns),\n ) as BoundI18n<T[K] & Messages>;\n }\n\n withLocale(locale: Locale): BoundI18n<T> {\n return new BoundView<T>(this.#core, locale, this.#prefix);\n }\n}\n"],"mappings":";AA8BA,IAAa,IAAb,MAAa,EAAiE;CAC5E;CACA;CACA;CAEA,YAAY,GAAgB,GAA4B,GAAiB;AAGvE,EAFA,MAAA,IAAa,GACb,MAAA,IAAoB,GACpB,MAAA,IAAe;;CAGjB,IAAI,SAAiB;AACnB,SAAO,MAAA,KAAqB,MAAA,EAAW,WAAW;;CAGpD,GAAK,GAAqB;AACxB,SAAO,MAAA,IAAe,GAAG,MAAA,EAAa,GAAG,MAAQ;;CAGnD,EAAE,GAA6B,GAAqB;AAClD,SAAO,MAAA,EAAW,UAAU,MAAA,EAAU,EAAc,EAAE,GAAM,KAAK,OAAO;;CAG1E,IAAI,GAAsB;AACxB,SAAO,MAAA,EAAW,YAAY,MAAA,EAAU,EAAI,EAAE,KAAK,OAAO,KAAK,KAAA;;CAGjE,OAAO,GAAsB;AAC3B,SAAO,MAAA,EAAW,SAAS,MAAA,EAAU,EAAI,EAAE,KAAK,OAAO;;CAGzD,OAAO,GAAe,GAA4C;AAChE,SAAO,MAAA,EAAW,aAAa,GAAO,GAAS,KAAK,OAAO;;CAG7D,KAAK,GAAsB,GAA8C;AACvE,SAAO,MAAA,EAAW,WAAW,GAAO,GAAS,KAAK,OAAO;;CAG3D,KAAK,GAAkB,IAAqB,OAAe;AACzD,SAAO,MAAA,EAAW,WAAW,GAAO,KAAK,QAAQ,EAAK;;CAGxD,SAAS,GAAe,GAAmC,GAAkD;AAC3G,SAAO,MAAA,EAAW,eAAe,GAAO,GAAM,GAAS,KAAK,OAAO;;CAGrE,SAAS,GAAe,G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