@vielzeug/lingua 3.0.0 → 26.10.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.
Files changed (71) hide show
  1. package/dist/_bounded-cache.cjs +1 -1
  2. package/dist/_bounded-cache.cjs.map +1 -1
  3. package/dist/_bounded-cache.js +1 -9
  4. package/dist/_bounded-cache.js.map +1 -1
  5. package/dist/_catalog.cjs +1 -1
  6. package/dist/_catalog.cjs.map +1 -1
  7. package/dist/_catalog.js +1 -49
  8. package/dist/_catalog.js.map +1 -1
  9. package/dist/_dev.cjs +1 -1
  10. package/dist/_dev.cjs.map +1 -1
  11. package/dist/_dev.d.ts +1 -1
  12. package/dist/_dev.d.ts.map +1 -1
  13. package/dist/_dev.js +1 -6
  14. package/dist/_dev.js.map +1 -1
  15. package/dist/_locale.cjs +1 -1
  16. package/dist/_locale.cjs.map +1 -1
  17. package/dist/_locale.js +1 -25
  18. package/dist/_locale.js.map +1 -1
  19. package/dist/_resources.cjs +1 -1
  20. package/dist/_resources.cjs.map +1 -1
  21. package/dist/_resources.js +1 -47
  22. package/dist/_resources.js.map +1 -1
  23. package/dist/_template.cjs +1 -1
  24. package/dist/_template.cjs.map +1 -1
  25. package/dist/_template.js +1 -40
  26. package/dist/_template.js.map +1 -1
  27. package/dist/catalog.cjs +1 -1
  28. package/dist/catalog.cjs.map +1 -1
  29. package/dist/catalog.d.ts +6 -6
  30. package/dist/catalog.d.ts.map +1 -1
  31. package/dist/catalog.js +1 -14
  32. package/dist/catalog.js.map +1 -1
  33. package/dist/errors.cjs +1 -1
  34. package/dist/errors.cjs.map +1 -1
  35. package/dist/errors.js +1 -13
  36. package/dist/errors.js.map +1 -1
  37. package/dist/format.cjs +1 -1
  38. package/dist/format.cjs.map +1 -1
  39. package/dist/format.d.ts.map +1 -1
  40. package/dist/format.js +1 -84
  41. package/dist/format.js.map +1 -1
  42. package/dist/i18n.cjs +1 -1
  43. package/dist/i18n.cjs.map +1 -1
  44. package/dist/i18n.d.ts +5 -0
  45. package/dist/i18n.d.ts.map +1 -1
  46. package/dist/i18n.js +1 -103
  47. package/dist/i18n.js.map +1 -1
  48. package/dist/index.js +1 -5
  49. package/dist/lingua.cjs +1 -1
  50. package/dist/lingua.cjs.map +1 -1
  51. package/dist/lingua.iife.js +1 -1
  52. package/dist/lingua.iife.js.map +1 -1
  53. package/dist/lingua.js +1 -1
  54. package/dist/lingua.js.map +1 -1
  55. package/dist/ripple.cjs +2 -0
  56. package/dist/ripple.cjs.map +1 -0
  57. package/dist/ripple.d.ts +24 -0
  58. package/dist/ripple.d.ts.map +1 -0
  59. package/dist/ripple.js +2 -0
  60. package/dist/ripple.js.map +1 -0
  61. package/dist/translator.cjs +1 -1
  62. package/dist/translator.cjs.map +1 -1
  63. package/dist/translator.d.ts.map +1 -1
  64. package/dist/translator.js +1 -76
  65. package/dist/translator.js.map +1 -1
  66. package/dist/types.d.ts +1 -1
  67. package/dist/validate.cjs +1 -1
  68. package/dist/validate.cjs.map +1 -1
  69. package/dist/validate.js +1 -45
  70. package/dist/validate.js.map +1 -1
  71. package/package.json +22 -5
@@ -1,2 +1,2 @@
1
- function e(e,t,n,r){if(e.has(t))return e.get(t);let i=r();return e.size>=n&&e.delete(e.keys().next().value),e.set(t,i),i}exports.getOrCreate=e;
1
+ function getOrCreate(e,t,n,r){if(e.has(t))return e.get(t);let i=r();return e.size>=n&&e.delete(e.keys().next().value),e.set(t,i),i}exports.getOrCreate=getOrCreate;
2
2
  //# sourceMappingURL=_bounded-cache.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_bounded-cache.cjs","names":[],"sources":["../src/_bounded-cache.ts"],"sourcesContent":["// Internal — not part of the public API.\n// Minimal bounded cache: evicts the oldest entry (insertion order) once `maxSize` is exceeded.\n// Not LRU — no access-time reordering, only insertion order matters. These caches exist purely\n// to avoid rebuilding cheap-but-not-free values (compiled `Intl` formatters, scoped translator\n// objects) for a bounded number of frequently-reused keys, not to model real recency.\n\nexport function getOrCreate<K, V>(cache: Map<K, V>, key: K, maxSize: number, build: () => V): V {\n if (cache.has(key)) return cache.get(key)!;\n\n const value = build();\n\n if (cache.size >= maxSize) cache.delete(cache.keys().next().value as K);\n\n cache.set(key, value);\n\n return value;\n}\n"],"mappings":"AAMA,SAAgB,EAAkB,EAAkB,EAAQ,EAAiB,EAAmB,CAC9F,GAAI,EAAM,IAAI,CAAG,EAAG,OAAO,EAAM,IAAI,CAAG,EAExC,IAAM,EAAQ,EAAM,EAMpB,OAJI,EAAM,MAAQ,GAAS,EAAM,OAAO,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAEtE,EAAM,IAAI,EAAK,CAAK,EAEb,CACT"}
1
+ {"version":3,"file":"_bounded-cache.cjs","names":[],"sources":["../src/_bounded-cache.ts"],"sourcesContent":["// Internal — not part of the public API.\n// Minimal bounded cache: evicts the oldest entry (insertion order) once `maxSize` is exceeded.\n// Not LRU — no access-time reordering, only insertion order matters. These caches exist purely\n// to avoid rebuilding cheap-but-not-free values (compiled `Intl` formatters, scoped translator\n// objects) for a bounded number of frequently-reused keys, not to model real recency.\n\nexport function getOrCreate<K, V>(cache: Map<K, V>, key: K, maxSize: number, build: () => V): V {\n if (cache.has(key)) return cache.get(key)!;\n\n const value = build();\n\n if (cache.size >= maxSize) cache.delete(cache.keys().next().value as K);\n\n cache.set(key, value);\n\n return value;\n}\n"],"mappings":"AAMA,SAAgB,YAAkB,EAAkB,EAAQ,EAAiB,EAAmB,CAC9F,GAAI,EAAM,IAAI,CAAG,EAAG,OAAO,EAAM,IAAI,CAAG,EAExC,IAAM,EAAQ,EAAM,EAMpB,OAJI,EAAM,MAAQ,GAAS,EAAM,OAAO,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAEtE,EAAM,IAAI,EAAK,CAAK,EAEb,CACT"}
@@ -1,10 +1,2 @@
1
- //#region src/_bounded-cache.ts
2
- function e(e, t, n, r) {
3
- if (e.has(t)) return e.get(t);
4
- let i = r();
5
- return e.size >= n && e.delete(e.keys().next().value), e.set(t, i), i;
6
- }
7
- //#endregion
8
- export { e as getOrCreate };
9
-
1
+ function getOrCreate(e,t,n,r){if(e.has(t))return e.get(t);let i=r();return e.size>=n&&e.delete(e.keys().next().value),e.set(t,i),i}export{getOrCreate};
10
2
  //# sourceMappingURL=_bounded-cache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_bounded-cache.js","names":[],"sources":["../src/_bounded-cache.ts"],"sourcesContent":["// Internal — not part of the public API.\n// Minimal bounded cache: evicts the oldest entry (insertion order) once `maxSize` is exceeded.\n// Not LRU — no access-time reordering, only insertion order matters. These caches exist purely\n// to avoid rebuilding cheap-but-not-free values (compiled `Intl` formatters, scoped translator\n// objects) for a bounded number of frequently-reused keys, not to model real recency.\n\nexport function getOrCreate<K, V>(cache: Map<K, V>, key: K, maxSize: number, build: () => V): V {\n if (cache.has(key)) return cache.get(key)!;\n\n const value = build();\n\n if (cache.size >= maxSize) cache.delete(cache.keys().next().value as K);\n\n cache.set(key, value);\n\n return value;\n}\n"],"mappings":";AAMA,SAAgB,EAAkB,GAAkB,GAAQ,GAAiB,GAAmB;CAC9F,IAAI,EAAM,IAAI,CAAG,GAAG,OAAO,EAAM,IAAI,CAAG;CAExC,IAAM,IAAQ,EAAM;CAMpB,OAJI,EAAM,QAAQ,KAAS,EAAM,OAAO,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,GAEtE,EAAM,IAAI,GAAK,CAAK,GAEb;AACT"}
1
+ {"version":3,"file":"_bounded-cache.js","names":[],"sources":["../src/_bounded-cache.ts"],"sourcesContent":["// Internal — not part of the public API.\n// Minimal bounded cache: evicts the oldest entry (insertion order) once `maxSize` is exceeded.\n// Not LRU — no access-time reordering, only insertion order matters. These caches exist purely\n// to avoid rebuilding cheap-but-not-free values (compiled `Intl` formatters, scoped translator\n// objects) for a bounded number of frequently-reused keys, not to model real recency.\n\nexport function getOrCreate<K, V>(cache: Map<K, V>, key: K, maxSize: number, build: () => V): V {\n if (cache.has(key)) return cache.get(key)!;\n\n const value = build();\n\n if (cache.size >= maxSize) cache.delete(cache.keys().next().value as K);\n\n cache.set(key, value);\n\n return value;\n}\n"],"mappings":"AAMA,SAAgB,YAAkB,EAAkB,EAAQ,EAAiB,EAAmB,CAC9F,GAAI,EAAM,IAAI,CAAG,EAAG,OAAO,EAAM,IAAI,CAAG,EAExC,IAAM,EAAQ,EAAM,EAMpB,OAJI,EAAM,MAAQ,GAAS,EAAM,OAAO,EAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAEtE,EAAM,IAAI,EAAK,CAAK,EAEb,CACT"}
package/dist/_catalog.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_template.cjs"),t=require("./errors.cjs");var n=new Set([`__proto__`,`constructor`,`prototype`]);function r(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function i(i){let a=new Map,o=(i,s)=>{if(typeof i==`string`){a.set(s,{kind:`text`,template:e.compileTemplate(i)});return}if(typeof i!=`object`||!i||Array.isArray(i))throw new t.LinguaInvalidCatalogError(`Catalog node "${s}" must be a string, plural message, or object.`);if(r(i)){if(Reflect.ownKeys(i).some(e=>e!==`plural`))throw new t.LinguaInvalidCatalogError(`Plural message "${s}" must contain only a "plural" property.`);if(typeof i.plural!=`object`||i.plural===null||Array.isArray(i.plural))throw new t.LinguaInvalidCatalogError(`Plural message "${s}" must provide an object of string forms.`);let n=new Map;for(let[r,a]of Object.entries(i.plural)){if(typeof a!=`string`)throw new t.LinguaInvalidCatalogError(`Plural form "${s}.${r}" must be a string.`);n.set(r,e.compileTemplate(a))}a.set(s,{forms:n,kind:`plural`});return}for(let[e,r]of Object.entries(i)){if(n.has(e))throw new t.LinguaInvalidCatalogError(`Catalog key "${e}" is reserved.`);o(r,s?`${s}.${e}`:e)}};for(let[e,r]of Object.entries(i)){if(n.has(e))throw new t.LinguaInvalidCatalogError(`Catalog key "${e}" is reserved.`);o(r,e)}return a}exports.compileCatalog=i,exports.isPluralMessage=r;
1
+ const e=require("./_template.cjs"),t=require("./errors.cjs");var n=new Set([`__proto__`,`constructor`,`prototype`]);function isPluralMessage(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function compileCatalog(r){let i=new Map,visit=(r,a)=>{if(typeof r==`string`){i.set(a,{kind:`text`,template:e.compileTemplate(r)});return}if(typeof r!=`object`||!r||Array.isArray(r))throw new t.LinguaInvalidCatalogError(`Catalog node "${a}" must be a string, plural message, or object.`);if(isPluralMessage(r)){if(Reflect.ownKeys(r).some(e=>e!==`plural`))throw new t.LinguaInvalidCatalogError(`Plural message "${a}" must contain only a "plural" property.`);if(typeof r.plural!=`object`||r.plural===null||Array.isArray(r.plural))throw new t.LinguaInvalidCatalogError(`Plural message "${a}" must provide an object of string forms.`);let n=new Map;for(let[i,o]of Object.entries(r.plural)){if(typeof o!=`string`)throw new t.LinguaInvalidCatalogError(`Plural form "${a}.${i}" must be a string.`);n.set(i,e.compileTemplate(o))}i.set(a,{forms:n,kind:`plural`});return}for(let[e,i]of Object.entries(r)){if(n.has(e))throw new t.LinguaInvalidCatalogError(`Catalog key "${e}" is reserved.`);visit(i,a?`${a}.${e}`:e)}};for(let[e,i]of Object.entries(r)){if(n.has(e))throw new t.LinguaInvalidCatalogError(`Catalog key "${e}" is reserved.`);visit(i,e)}return i}exports.compileCatalog=compileCatalog,exports.isPluralMessage=isPluralMessage;
2
2
  //# sourceMappingURL=_catalog.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_catalog.cjs","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":"6DAIA,IAAM,EAAa,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAOpE,SAAgB,EAAgB,EAA0C,CACxE,OAAO,OAAO,GAAS,YAAY,GAAiB,OAAO,OAAO,EAAM,QAAQ,CAClF,CAGA,SAAgB,EAAe,EAAmC,CAChE,IAAM,EAAW,IAAI,IAEf,GAAS,EAAmB,IAAyB,CACzD,GAAI,OAAO,GAAS,SAAU,CAC5B,EAAS,IAAI,EAAQ,CAAE,KAAM,OAAQ,SAAU,EAAA,gBAAgB,CAAI,CAAE,CAAC,EAEtE,MACF,CAEA,GAAI,OAAO,GAAS,WAAY,GAAiB,MAAM,QAAQ,CAAI,EACjE,MAAM,IAAI,EAAA,0BAA0B,iBAAiB,EAAO,+CAA+C,EAG7G,GAAI,EAAgB,CAAI,EAAG,CACzB,GAAI,QAAQ,QAAQ,CAAI,CAAC,CAAC,KAAM,GAAQ,IAAQ,QAAQ,EACtD,MAAM,IAAI,EAAA,0BAA0B,mBAAmB,EAAO,yCAAyC,EAGzG,GAAI,OAAO,EAAK,QAAW,UAAY,EAAK,SAAW,MAAQ,MAAM,QAAQ,EAAK,MAAM,EACtF,MAAM,IAAI,EAAA,0BAA0B,mBAAmB,EAAO,0CAA0C,EAG1G,IAAM,EAAQ,IAAI,IAElB,IAAK,GAAM,CAAC,EAAM,KAAa,OAAO,QAAQ,EAAK,MAAM,EAAG,CAC1D,GAAI,OAAO,GAAa,SACtB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAO,GAAG,EAAK,oBAAoB,EAGzF,EAAM,IAAI,EAAM,EAAA,gBAAgB,CAAQ,CAAC,CAC3C,CAEA,EAAS,IAAI,EAAQ,CAAE,QAAO,KAAM,QAAS,CAAC,EAE9C,MACF,CAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAI,EAAG,CAC/C,GAAI,EAAW,IAAI,CAAG,EACpB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAGzE,EAAM,EAAO,EAAS,GAAG,EAAO,GAAG,IAAQ,CAAG,CAChD,CACF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAO,EAAG,CAClD,GAAI,EAAW,IAAI,CAAG,EAAG,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAEhG,EAAM,EAAO,CAAG,CAClB,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"_catalog.cjs","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":"6DAIA,IAAM,EAAa,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAOpE,SAAgB,gBAAgB,EAA0C,CACxE,OAAO,OAAO,GAAS,YAAY,GAAiB,OAAO,OAAO,EAAM,QAAQ,CAClF,CAGA,SAAgB,eAAe,EAAmC,CAChE,IAAM,EAAW,IAAI,IAEf,OAAS,EAAmB,IAAyB,CACzD,GAAI,OAAO,GAAS,SAAU,CAC5B,EAAS,IAAI,EAAQ,CAAE,KAAM,OAAQ,SAAU,EAAA,gBAAgB,CAAI,CAAE,CAAC,EAEtE,MACF,CAEA,GAAI,OAAO,GAAS,WAAY,GAAiB,MAAM,QAAQ,CAAI,EACjE,MAAM,IAAI,EAAA,0BAA0B,iBAAiB,EAAO,+CAA+C,EAG7G,GAAI,gBAAgB,CAAI,EAAG,CACzB,GAAI,QAAQ,QAAQ,CAAI,CAAC,CAAC,KAAM,GAAQ,IAAQ,QAAQ,EACtD,MAAM,IAAI,EAAA,0BAA0B,mBAAmB,EAAO,yCAAyC,EAGzG,GAAI,OAAO,EAAK,QAAW,UAAY,EAAK,SAAW,MAAQ,MAAM,QAAQ,EAAK,MAAM,EACtF,MAAM,IAAI,EAAA,0BAA0B,mBAAmB,EAAO,0CAA0C,EAG1G,IAAM,EAAQ,IAAI,IAElB,IAAK,GAAM,CAAC,EAAM,KAAa,OAAO,QAAQ,EAAK,MAAM,EAAG,CAC1D,GAAI,OAAO,GAAa,SACtB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAO,GAAG,EAAK,oBAAoB,EAGzF,EAAM,IAAI,EAAM,EAAA,gBAAgB,CAAQ,CAAC,CAC3C,CAEA,EAAS,IAAI,EAAQ,CAAE,QAAO,KAAM,QAAS,CAAC,EAE9C,MACF,CAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAI,EAAG,CAC/C,GAAI,EAAW,IAAI,CAAG,EACpB,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAGzE,MAAM,EAAO,EAAS,GAAG,EAAO,GAAG,IAAQ,CAAG,CAChD,CACF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAO,EAAG,CAClD,GAAI,EAAW,IAAI,CAAG,EAAG,MAAM,IAAI,EAAA,0BAA0B,gBAAgB,EAAI,eAAe,EAEhG,MAAM,EAAO,CAAG,CAClB,CAEA,OAAO,CACT"}
package/dist/_catalog.js CHANGED
@@ -1,50 +1,2 @@
1
- import { compileTemplate as e } from "./_template.js";
2
- import { LinguaInvalidCatalogError as t } from "./errors.js";
3
- //#region src/_catalog.ts
4
- var n = /* @__PURE__ */ new Set([
5
- "__proto__",
6
- "constructor",
7
- "prototype"
8
- ]);
9
- function r(e) {
10
- return typeof e == "object" && !!e && Object.hasOwn(e, "plural");
11
- }
12
- function i(i) {
13
- let a = /* @__PURE__ */ new Map(), o = (i, s) => {
14
- if (typeof i == "string") {
15
- a.set(s, {
16
- kind: "text",
17
- template: e(i)
18
- });
19
- return;
20
- }
21
- if (typeof i != "object" || !i || Array.isArray(i)) throw new t(`Catalog node "${s}" must be a string, plural message, or object.`);
22
- if (r(i)) {
23
- if (Reflect.ownKeys(i).some((e) => e !== "plural")) throw new t(`Plural message "${s}" must contain only a "plural" property.`);
24
- if (typeof i.plural != "object" || i.plural === null || Array.isArray(i.plural)) throw new t(`Plural message "${s}" must provide an object of string forms.`);
25
- let n = /* @__PURE__ */ new Map();
26
- for (let [r, a] of Object.entries(i.plural)) {
27
- if (typeof a != "string") throw new t(`Plural form "${s}.${r}" must be a string.`);
28
- n.set(r, e(a));
29
- }
30
- a.set(s, {
31
- forms: n,
32
- kind: "plural"
33
- });
34
- return;
35
- }
36
- for (let [e, r] of Object.entries(i)) {
37
- if (n.has(e)) throw new t(`Catalog key "${e}" is reserved.`);
38
- o(r, s ? `${s}.${e}` : e);
39
- }
40
- };
41
- for (let [e, r] of Object.entries(i)) {
42
- if (n.has(e)) throw new t(`Catalog key "${e}" is reserved.`);
43
- o(r, e);
44
- }
45
- return a;
46
- }
47
- //#endregion
48
- export { i as compileCatalog, r as isPluralMessage };
49
-
1
+ import{compileTemplate as e}from"./_template.js";import{LinguaInvalidCatalogError as t}from"./errors.js";var n=new Set([`__proto__`,`constructor`,`prototype`]);function isPluralMessage(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`plural`)}function compileCatalog(r){let i=new Map,visit=(r,a)=>{if(typeof r==`string`){i.set(a,{kind:`text`,template:e(r)});return}if(typeof r!=`object`||!r||Array.isArray(r))throw new t(`Catalog node "${a}" must be a string, plural message, or object.`);if(isPluralMessage(r)){if(Reflect.ownKeys(r).some(e=>e!==`plural`))throw new t(`Plural message "${a}" must contain only a "plural" property.`);if(typeof r.plural!=`object`||r.plural===null||Array.isArray(r.plural))throw new t(`Plural message "${a}" must provide an object of string forms.`);let n=new Map;for(let[i,o]of Object.entries(r.plural)){if(typeof o!=`string`)throw new t(`Plural form "${a}.${i}" must be a string.`);n.set(i,e(o))}i.set(a,{forms:n,kind:`plural`});return}for(let[e,i]of Object.entries(r)){if(n.has(e))throw new t(`Catalog key "${e}" is reserved.`);visit(i,a?`${a}.${e}`:e)}};for(let[e,i]of Object.entries(r)){if(n.has(e))throw new t(`Catalog key "${e}" is reserved.`);visit(i,e)}return i}export{compileCatalog,isPluralMessage};
50
2
  //# sourceMappingURL=_catalog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_catalog.js","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":";;;AAIA,IAAM,oBAAa,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAOpE,SAAgB,EAAgB,GAA0C;CACxE,OAAO,OAAO,KAAS,cAAY,KAAiB,OAAO,OAAO,GAAM,QAAQ;AAClF;AAGA,SAAgB,EAAe,GAAmC;CAChE,IAAM,oBAAW,IAAI,IAA6B,GAE5C,KAAS,GAAmB,MAAyB;EACzD,IAAI,OAAO,KAAS,UAAU;GAC5B,EAAS,IAAI,GAAQ;IAAE,MAAM;IAAQ,UAAU,EAAgB,CAAI;GAAE,CAAC;GAEtE;EACF;EAEA,IAAI,OAAO,KAAS,aAAY,KAAiB,MAAM,QAAQ,CAAI,GACjE,MAAM,IAAI,EAA0B,iBAAiB,EAAO,+CAA+C;EAG7G,IAAI,EAAgB,CAAI,GAAG;GACzB,IAAI,QAAQ,QAAQ,CAAI,CAAC,CAAC,MAAM,MAAQ,MAAQ,QAAQ,GACtD,MAAM,IAAI,EAA0B,mBAAmB,EAAO,yCAAyC;GAGzG,IAAI,OAAO,EAAK,UAAW,YAAY,EAAK,WAAW,QAAQ,MAAM,QAAQ,EAAK,MAAM,GACtF,MAAM,IAAI,EAA0B,mBAAmB,EAAO,0CAA0C;GAG1G,IAAM,oBAAQ,IAAI,IAAsB;GAExC,KAAK,IAAM,CAAC,GAAM,MAAa,OAAO,QAAQ,EAAK,MAAM,GAAG;IAC1D,IAAI,OAAO,KAAa,UACtB,MAAM,IAAI,EAA0B,gBAAgB,EAAO,GAAG,EAAK,oBAAoB;IAGzF,EAAM,IAAI,GAAM,EAAgB,CAAQ,CAAC;GAC3C;GAEA,EAAS,IAAI,GAAQ;IAAE;IAAO,MAAM;GAAS,CAAC;GAE9C;EACF;EAEA,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAI,GAAG;GAC/C,IAAI,EAAW,IAAI,CAAG,GACpB,MAAM,IAAI,EAA0B,gBAAgB,EAAI,eAAe;GAGzE,EAAM,GAAO,IAAS,GAAG,EAAO,GAAG,MAAQ,CAAG;EAChD;CACF;CAEA,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAO,GAAG;EAClD,IAAI,EAAW,IAAI,CAAG,GAAG,MAAM,IAAI,EAA0B,gBAAgB,EAAI,eAAe;EAEhG,EAAM,GAAO,CAAG;CAClB;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"_catalog.js","names":[],"sources":["../src/_catalog.ts"],"sourcesContent":["import { compileTemplate, type Template } from './_template';\nimport { LinguaInvalidCatalogError } from './errors';\nimport type { Catalog, CatalogNode, PluralMessage } from './types';\n\nconst unsafeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\nexport type CompiledText = { readonly kind: 'text'; readonly template: Template };\nexport type CompiledPlural = { readonly forms: ReadonlyMap<string, Template>; readonly kind: 'plural' };\nexport type CompiledMessage = CompiledPlural | CompiledText;\nexport type CompiledCatalog = ReadonlyMap<string, CompiledMessage>;\n\nexport function isPluralMessage(node: CatalogNode): node is PluralMessage {\n return typeof node === 'object' && node !== null && Object.hasOwn(node, 'plural');\n}\n\n/** Compile explicit catalog nodes once. Nested objects only group keys; plural intent is never inferred. */\nexport function compileCatalog(catalog: Catalog): CompiledCatalog {\n const messages = new Map<string, CompiledMessage>();\n\n const visit = (node: CatalogNode, prefix: string): void => {\n if (typeof node === 'string') {\n messages.set(prefix, { kind: 'text', template: compileTemplate(node) });\n\n return;\n }\n\n if (typeof node !== 'object' || node === null || Array.isArray(node)) {\n throw new LinguaInvalidCatalogError(`Catalog node \"${prefix}\" must be a string, plural message, or object.`);\n }\n\n if (isPluralMessage(node)) {\n if (Reflect.ownKeys(node).some((key) => key !== 'plural')) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must contain only a \"plural\" property.`);\n }\n\n if (typeof node.plural !== 'object' || node.plural === null || Array.isArray(node.plural)) {\n throw new LinguaInvalidCatalogError(`Plural message \"${prefix}\" must provide an object of string forms.`);\n }\n\n const forms = new Map<string, Template>();\n\n for (const [form, template] of Object.entries(node.plural)) {\n if (typeof template !== 'string') {\n throw new LinguaInvalidCatalogError(`Plural form \"${prefix}.${form}\" must be a string.`);\n }\n\n forms.set(form, compileTemplate(template));\n }\n\n messages.set(prefix, { forms, kind: 'plural' });\n\n return;\n }\n\n for (const [key, value] of Object.entries(node)) {\n if (unsafeKeys.has(key)) {\n throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n }\n\n visit(value, prefix ? `${prefix}.${key}` : key);\n }\n };\n\n for (const [key, value] of Object.entries(catalog)) {\n if (unsafeKeys.has(key)) throw new LinguaInvalidCatalogError(`Catalog key \"${key}\" is reserved.`);\n\n visit(value, key);\n }\n\n return messages;\n}\n"],"mappings":"yGAIA,IAAM,EAAa,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EAOpE,SAAgB,gBAAgB,EAA0C,CACxE,OAAO,OAAO,GAAS,YAAY,GAAiB,OAAO,OAAO,EAAM,QAAQ,CAClF,CAGA,SAAgB,eAAe,EAAmC,CAChE,IAAM,EAAW,IAAI,IAEf,OAAS,EAAmB,IAAyB,CACzD,GAAI,OAAO,GAAS,SAAU,CAC5B,EAAS,IAAI,EAAQ,CAAE,KAAM,OAAQ,SAAU,EAAgB,CAAI,CAAE,CAAC,EAEtE,MACF,CAEA,GAAI,OAAO,GAAS,WAAY,GAAiB,MAAM,QAAQ,CAAI,EACjE,MAAM,IAAI,EAA0B,iBAAiB,EAAO,+CAA+C,EAG7G,GAAI,gBAAgB,CAAI,EAAG,CACzB,GAAI,QAAQ,QAAQ,CAAI,CAAC,CAAC,KAAM,GAAQ,IAAQ,QAAQ,EACtD,MAAM,IAAI,EAA0B,mBAAmB,EAAO,yCAAyC,EAGzG,GAAI,OAAO,EAAK,QAAW,UAAY,EAAK,SAAW,MAAQ,MAAM,QAAQ,EAAK,MAAM,EACtF,MAAM,IAAI,EAA0B,mBAAmB,EAAO,0CAA0C,EAG1G,IAAM,EAAQ,IAAI,IAElB,IAAK,GAAM,CAAC,EAAM,KAAa,OAAO,QAAQ,EAAK,MAAM,EAAG,CAC1D,GAAI,OAAO,GAAa,SACtB,MAAM,IAAI,EAA0B,gBAAgB,EAAO,GAAG,EAAK,oBAAoB,EAGzF,EAAM,IAAI,EAAM,EAAgB,CAAQ,CAAC,CAC3C,CAEA,EAAS,IAAI,EAAQ,CAAE,QAAO,KAAM,QAAS,CAAC,EAE9C,MACF,CAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAI,EAAG,CAC/C,GAAI,EAAW,IAAI,CAAG,EACpB,MAAM,IAAI,EAA0B,gBAAgB,EAAI,eAAe,EAGzE,MAAM,EAAO,EAAS,GAAG,EAAO,GAAG,IAAQ,CAAG,CAChD,CACF,EAEA,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAO,EAAG,CAClD,GAAI,EAAW,IAAI,CAAG,EAAG,MAAM,IAAI,EAA0B,gBAAgB,EAAI,eAAe,EAEhG,MAAM,EAAO,CAAG,CAClB,CAEA,OAAO,CACT"}
package/dist/_dev.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function e(e){}function t(e,...t){}exports.error=t,exports.warn=e;
1
+ function warn(e){}function error(e,...t){}exports.error=error,exports.warn=warn;
2
2
  //# sourceMappingURL=_dev.cjs.map
package/dist/_dev.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/lingua] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/lingua] ${msg}`, ...args);\n}\n"],"mappings":"AAGA,SAAgB,EAAK,EAAmB,CAExC,CAGA,SAAgB,EAAM,EAAa,GAAG,EAAuB,CAE7D"}
1
+ {"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["export const isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/lingua] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/lingua] ${msg}`, ...args);\n}\n"],"mappings":"AAGA,SAAgB,KAAK,EAAmB,CAExC,CAGA,SAAgB,MAAM,EAAa,GAAG,EAAuB,CAE7D"}
package/dist/_dev.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export {};
1
+ export declare const isDev: boolean;
2
2
  //# sourceMappingURL=_dev.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.d.ts","sourceRoot":"","sources":["../src/_dev.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"_dev.d.ts","sourceRoot":"","sources":["../src/_dev.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,SAAiE,CAAC"}
package/dist/_dev.js CHANGED
@@ -1,7 +1,2 @@
1
- //#region src/_dev.ts
2
- function e(e) {}
3
- function t(e, ...t) {}
4
- //#endregion
5
- export { t as error, e as warn };
6
-
1
+ function warn(e){}function error(e,...t){}export{error,warn};
7
2
  //# sourceMappingURL=_dev.js.map
package/dist/_dev.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/lingua] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/lingua] ${msg}`, ...args);\n}\n"],"mappings":";AAGA,SAAgB,EAAK,GAAmB,CAExC;AAGA,SAAgB,EAAM,GAAa,GAAG,GAAuB,CAE7D"}
1
+ {"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["export const isDev = !(globalThis as { __LINGUA_PROD__?: boolean }).__LINGUA_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/lingua] ${msg}`);\n}\n\n/** @internal */\nexport function error(msg: string, ...args: unknown[]): void {\n if (isDev) console.error(`[@vielzeug/lingua] ${msg}`, ...args);\n}\n"],"mappings":"AAGA,SAAgB,KAAK,EAAmB,CAExC,CAGA,SAAgB,MAAM,EAAa,GAAG,EAAuB,CAE7D"}
package/dist/_locale.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs");var t=new Map;function n(t){try{let[e]=Intl.getCanonicalLocales(t);if(e)return e}catch{}throw new e.LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: "${t}".`)}function r(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function i(e,n,r){let i=`${e}:${r?`ordinal`:`cardinal`}`,a=t.get(i);return a||(a=new Intl.PluralRules(e,{type:r?`ordinal`:`cardinal`}),t.set(i,a)),a.select(n)}exports.canonicalLocale=n,exports.localeChain=r,exports.pluralCategory=i;
1
+ const e=require("./errors.cjs");var t=new Map;function canonicalLocale(t){try{let[e]=Intl.getCanonicalLocales(t);if(e)return e}catch{}throw new e.LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: "${t}".`)}function localeChain(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function pluralCategory(e,n,r){let i=`${e}:${r?`ordinal`:`cardinal`}`,a=t.get(i);return a||(a=new Intl.PluralRules(e,{type:r?`ordinal`:`cardinal`}),t.set(i,a)),a.select(n)}exports.canonicalLocale=canonicalLocale,exports.localeChain=localeChain,exports.pluralCategory=pluralCategory;
2
2
  //# sourceMappingURL=_locale.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_locale.cjs","names":[],"sources":["../src/_locale.ts"],"sourcesContent":["import { LinguaInvalidLocaleError } from './errors';\nimport type { Locale } from './types';\n\nconst pluralRules = new Map<string, Intl.PluralRules>();\n\nexport function canonicalLocale(locale: string): Locale {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) return canonical;\n } catch {\n // Error below names the failed public input.\n }\n\n throw new LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: \"${locale}\".`);\n}\n\nexport function localeChain(locale: Locale, fallback: readonly Locale[]): readonly Locale[] {\n const chain = new Set<Locale>();\n\n for (const candidate of [locale, ...fallback]) {\n const parts = candidate.split('-');\n\n for (let length = parts.length; length > 0; length--) {\n chain.add(parts.slice(0, length).join('-'));\n }\n }\n\n return [...chain];\n}\n\nexport function pluralCategory(locale: Locale, count: number, ordinal: boolean): Intl.LDMLPluralRule {\n const key = `${locale}:${ordinal ? 'ordinal' : 'cardinal'}`;\n let rules = pluralRules.get(key);\n\n if (!rules) {\n rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });\n pluralRules.set(key, rules);\n }\n\n return rules.select(count);\n}\n"],"mappings":"gCAGA,IAAM,EAAc,IAAI,IAExB,SAAgB,EAAgB,EAAwB,CACtD,GAAI,CACF,GAAM,CAAC,GAAa,KAAK,oBAAoB,CAAM,EAEnD,GAAI,EAAW,OAAO,CACxB,MAAQ,CAER,CAEA,MAAM,IAAI,EAAA,yBAAyB,+BAA+B,EAAO,GAAG,CAC9E,CAEA,SAAgB,EAAY,EAAgB,EAAgD,CAC1F,IAAM,EAAQ,IAAI,IAElB,IAAK,IAAM,IAAa,CAAC,EAAQ,GAAG,CAAQ,EAAG,CAC7C,IAAM,EAAQ,EAAU,MAAM,GAAG,EAEjC,IAAK,IAAI,EAAS,EAAM,OAAQ,EAAS,EAAG,IAC1C,EAAM,IAAI,EAAM,MAAM,EAAG,CAAM,CAAC,CAAC,KAAK,GAAG,CAAC,CAE9C,CAEA,MAAO,CAAC,GAAG,CAAK,CAClB,CAEA,SAAgB,EAAe,EAAgB,EAAe,EAAuC,CACnG,IAAM,EAAM,GAAG,EAAO,GAAG,EAAU,UAAY,aAC3C,EAAQ,EAAY,IAAI,CAAG,EAO/B,OALK,IACH,EAAQ,IAAI,KAAK,YAAY,EAAQ,CAAE,KAAM,EAAU,UAAY,UAAW,CAAC,EAC/E,EAAY,IAAI,EAAK,CAAK,GAGrB,EAAM,OAAO,CAAK,CAC3B"}
1
+ {"version":3,"file":"_locale.cjs","names":[],"sources":["../src/_locale.ts"],"sourcesContent":["import { LinguaInvalidLocaleError } from './errors';\nimport type { Locale } from './types';\n\nconst pluralRules = new Map<string, Intl.PluralRules>();\n\nexport function canonicalLocale(locale: string): Locale {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) return canonical;\n } catch {\n // Error below names the failed public input.\n }\n\n throw new LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: \"${locale}\".`);\n}\n\nexport function localeChain(locale: Locale, fallback: readonly Locale[]): readonly Locale[] {\n const chain = new Set<Locale>();\n\n for (const candidate of [locale, ...fallback]) {\n const parts = candidate.split('-');\n\n for (let length = parts.length; length > 0; length--) {\n chain.add(parts.slice(0, length).join('-'));\n }\n }\n\n return [...chain];\n}\n\nexport function pluralCategory(locale: Locale, count: number, ordinal: boolean): Intl.LDMLPluralRule {\n const key = `${locale}:${ordinal ? 'ordinal' : 'cardinal'}`;\n let rules = pluralRules.get(key);\n\n if (!rules) {\n rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });\n pluralRules.set(key, rules);\n }\n\n return rules.select(count);\n}\n"],"mappings":"gCAGA,IAAM,EAAc,IAAI,IAExB,SAAgB,gBAAgB,EAAwB,CACtD,GAAI,CACF,GAAM,CAAC,GAAa,KAAK,oBAAoB,CAAM,EAEnD,GAAI,EAAW,OAAO,CACxB,MAAQ,CAER,CAEA,MAAM,IAAI,EAAA,yBAAyB,+BAA+B,EAAO,GAAG,CAC9E,CAEA,SAAgB,YAAY,EAAgB,EAAgD,CAC1F,IAAM,EAAQ,IAAI,IAElB,IAAK,IAAM,IAAa,CAAC,EAAQ,GAAG,CAAQ,EAAG,CAC7C,IAAM,EAAQ,EAAU,MAAM,GAAG,EAEjC,IAAK,IAAI,EAAS,EAAM,OAAQ,EAAS,EAAG,IAC1C,EAAM,IAAI,EAAM,MAAM,EAAG,CAAM,CAAC,CAAC,KAAK,GAAG,CAAC,CAE9C,CAEA,MAAO,CAAC,GAAG,CAAK,CAClB,CAEA,SAAgB,eAAe,EAAgB,EAAe,EAAuC,CACnG,IAAM,EAAM,GAAG,EAAO,GAAG,EAAU,UAAY,aAC3C,EAAQ,EAAY,IAAI,CAAG,EAO/B,OALK,IACH,EAAQ,IAAI,KAAK,YAAY,EAAQ,CAAE,KAAM,EAAU,UAAY,UAAW,CAAC,EAC/E,EAAY,IAAI,EAAK,CAAK,GAGrB,EAAM,OAAO,CAAK,CAC3B"}
package/dist/_locale.js CHANGED
@@ -1,26 +1,2 @@
1
- import { LinguaInvalidLocaleError as e } from "./errors.js";
2
- //#region src/_locale.ts
3
- var t = /* @__PURE__ */ new Map();
4
- function n(t) {
5
- try {
6
- let [e] = Intl.getCanonicalLocales(t);
7
- if (e) return e;
8
- } catch {}
9
- throw new e(`Invalid BCP 47 locale tag: "${t}".`);
10
- }
11
- function r(e, t) {
12
- let n = /* @__PURE__ */ new Set();
13
- for (let r of [e, ...t]) {
14
- let e = r.split("-");
15
- for (let t = e.length; t > 0; t--) n.add(e.slice(0, t).join("-"));
16
- }
17
- return [...n];
18
- }
19
- function i(e, n, r) {
20
- let i = `${e}:${r ? "ordinal" : "cardinal"}`, a = t.get(i);
21
- return a || (a = new Intl.PluralRules(e, { type: r ? "ordinal" : "cardinal" }), t.set(i, a)), a.select(n);
22
- }
23
- //#endregion
24
- export { n as canonicalLocale, r as localeChain, i as pluralCategory };
25
-
1
+ import{LinguaInvalidLocaleError as e}from"./errors.js";var t=new Map;function canonicalLocale(t){try{let[e]=Intl.getCanonicalLocales(t);if(e)return e}catch{}throw new e(`Invalid BCP 47 locale tag: "${t}".`)}function localeChain(e,t){let n=new Set;for(let r of[e,...t]){let e=r.split(`-`);for(let t=e.length;t>0;t--)n.add(e.slice(0,t).join(`-`))}return[...n]}function pluralCategory(e,n,r){let i=`${e}:${r?`ordinal`:`cardinal`}`,a=t.get(i);return a||(a=new Intl.PluralRules(e,{type:r?`ordinal`:`cardinal`}),t.set(i,a)),a.select(n)}export{canonicalLocale,localeChain,pluralCategory};
26
2
  //# sourceMappingURL=_locale.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_locale.js","names":[],"sources":["../src/_locale.ts"],"sourcesContent":["import { LinguaInvalidLocaleError } from './errors';\nimport type { Locale } from './types';\n\nconst pluralRules = new Map<string, Intl.PluralRules>();\n\nexport function canonicalLocale(locale: string): Locale {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) return canonical;\n } catch {\n // Error below names the failed public input.\n }\n\n throw new LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: \"${locale}\".`);\n}\n\nexport function localeChain(locale: Locale, fallback: readonly Locale[]): readonly Locale[] {\n const chain = new Set<Locale>();\n\n for (const candidate of [locale, ...fallback]) {\n const parts = candidate.split('-');\n\n for (let length = parts.length; length > 0; length--) {\n chain.add(parts.slice(0, length).join('-'));\n }\n }\n\n return [...chain];\n}\n\nexport function pluralCategory(locale: Locale, count: number, ordinal: boolean): Intl.LDMLPluralRule {\n const key = `${locale}:${ordinal ? 'ordinal' : 'cardinal'}`;\n let rules = pluralRules.get(key);\n\n if (!rules) {\n rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });\n pluralRules.set(key, rules);\n }\n\n return rules.select(count);\n}\n"],"mappings":";;AAGA,IAAM,oBAAc,IAAI,IAA8B;AAEtD,SAAgB,EAAgB,GAAwB;CACtD,IAAI;EACF,IAAM,CAAC,KAAa,KAAK,oBAAoB,CAAM;EAEnD,IAAI,GAAW,OAAO;CACxB,QAAQ,CAER;CAEA,MAAM,IAAI,EAAyB,+BAA+B,EAAO,GAAG;AAC9E;AAEA,SAAgB,EAAY,GAAgB,GAAgD;CAC1F,IAAM,oBAAQ,IAAI,IAAY;CAE9B,KAAK,IAAM,KAAa,CAAC,GAAQ,GAAG,CAAQ,GAAG;EAC7C,IAAM,IAAQ,EAAU,MAAM,GAAG;EAEjC,KAAK,IAAI,IAAS,EAAM,QAAQ,IAAS,GAAG,KAC1C,EAAM,IAAI,EAAM,MAAM,GAAG,CAAM,CAAC,CAAC,KAAK,GAAG,CAAC;CAE9C;CAEA,OAAO,CAAC,GAAG,CAAK;AAClB;AAEA,SAAgB,EAAe,GAAgB,GAAe,GAAuC;CACnG,IAAM,IAAM,GAAG,EAAO,GAAG,IAAU,YAAY,cAC3C,IAAQ,EAAY,IAAI,CAAG;CAO/B,OALK,MACH,IAAQ,IAAI,KAAK,YAAY,GAAQ,EAAE,MAAM,IAAU,YAAY,WAAW,CAAC,GAC/E,EAAY,IAAI,GAAK,CAAK,IAGrB,EAAM,OAAO,CAAK;AAC3B"}
1
+ {"version":3,"file":"_locale.js","names":[],"sources":["../src/_locale.ts"],"sourcesContent":["import { LinguaInvalidLocaleError } from './errors';\nimport type { Locale } from './types';\n\nconst pluralRules = new Map<string, Intl.PluralRules>();\n\nexport function canonicalLocale(locale: string): Locale {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) return canonical;\n } catch {\n // Error below names the failed public input.\n }\n\n throw new LinguaInvalidLocaleError(`Invalid BCP 47 locale tag: \"${locale}\".`);\n}\n\nexport function localeChain(locale: Locale, fallback: readonly Locale[]): readonly Locale[] {\n const chain = new Set<Locale>();\n\n for (const candidate of [locale, ...fallback]) {\n const parts = candidate.split('-');\n\n for (let length = parts.length; length > 0; length--) {\n chain.add(parts.slice(0, length).join('-'));\n }\n }\n\n return [...chain];\n}\n\nexport function pluralCategory(locale: Locale, count: number, ordinal: boolean): Intl.LDMLPluralRule {\n const key = `${locale}:${ordinal ? 'ordinal' : 'cardinal'}`;\n let rules = pluralRules.get(key);\n\n if (!rules) {\n rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });\n pluralRules.set(key, rules);\n }\n\n return rules.select(count);\n}\n"],"mappings":"uDAGA,IAAM,EAAc,IAAI,IAExB,SAAgB,gBAAgB,EAAwB,CACtD,GAAI,CACF,GAAM,CAAC,GAAa,KAAK,oBAAoB,CAAM,EAEnD,GAAI,EAAW,OAAO,CACxB,MAAQ,CAER,CAEA,MAAM,IAAI,EAAyB,+BAA+B,EAAO,GAAG,CAC9E,CAEA,SAAgB,YAAY,EAAgB,EAAgD,CAC1F,IAAM,EAAQ,IAAI,IAElB,IAAK,IAAM,IAAa,CAAC,EAAQ,GAAG,CAAQ,EAAG,CAC7C,IAAM,EAAQ,EAAU,MAAM,GAAG,EAEjC,IAAK,IAAI,EAAS,EAAM,OAAQ,EAAS,EAAG,IAC1C,EAAM,IAAI,EAAM,MAAM,EAAG,CAAM,CAAC,CAAC,KAAK,GAAG,CAAC,CAE9C,CAEA,MAAO,CAAC,GAAG,CAAK,CAClB,CAEA,SAAgB,eAAe,EAAgB,EAAe,EAAuC,CACnG,IAAM,EAAM,GAAG,EAAO,GAAG,EAAU,UAAY,aAC3C,EAAQ,EAAY,IAAI,CAAG,EAO/B,OALK,IACH,EAAQ,IAAI,KAAK,YAAY,EAAQ,CAAE,KAAM,EAAU,UAAY,UAAW,CAAC,EAC/E,EAAY,IAAI,EAAK,CAAK,GAGrB,EAAM,OAAO,CAAK,CAC3B"}
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs"),t=require("./_catalog.cjs"),n=require("./_locale.cjs");function r(r){let i=new Map,a=new Map,o=(e,r)=>{i.set(n.canonicalLocale(e),{catalog:r,compiled:t.compileCatalog(r)})};for(let[e,t]of Object.entries(r.catalogs??{}))o(e,t);return{catalogMap(){return new Map([...i].map(([e,{compiled:t}])=>[e,t]))},hydrate:o,isLoaded(e){return i.has(n.canonicalLocale(e))},load:async t=>{let s=n.canonicalLocale(t);if(i.has(s))return!1;let c=a.get(s);if(c)return await c,!1;if(!r.loadCatalog)throw new e.LinguaMissingCatalogError(`No catalog source provided for locale "${s}".`);let l=Promise.resolve(r.loadCatalog(s)).then(e=>{o(s,e),a.delete(s)},e=>{throw a.delete(s),e});return a.set(s,l),await l,!0},state(e){let t={};for(let[e,{catalog:n}]of i)t[e]=n;return{catalogs:t,locale:e,version:4}}}}exports.createCatalogStore=r;
1
+ const e=require("./errors.cjs"),t=require("./_catalog.cjs"),n=require("./_locale.cjs");function createCatalogStore(r){let i=new Map,a=new Map,hydrate=(e,r)=>{i.set(n.canonicalLocale(e),{catalog:r,compiled:t.compileCatalog(r)})};for(let[e,t]of Object.entries(r.catalogs??{}))hydrate(e,t);let load=async t=>{let o=n.canonicalLocale(t);if(i.has(o))return!1;let s=a.get(o);if(s)return await s,!1;if(!r.loadCatalog)throw new e.LinguaMissingCatalogError(`No catalog source provided for locale "${o}".`);let c=Promise.resolve(r.loadCatalog(o)).then(e=>{hydrate(o,e),a.delete(o)},e=>{throw a.delete(o),e});return a.set(o,c),await c,!0};return{catalogMap(){return new Map([...i].map(([e,{compiled:t}])=>[e,t]))},hydrate,isLoaded(e){return i.has(n.canonicalLocale(e))},load,state(e){let t={};for(let[e,{catalog:n}]of i)t[e]=n;return{catalogs:t,locale:e,version:1}}}}exports.createCatalogStore=createCatalogStore;
2
2
  //# sourceMappingURL=_resources.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_resources.cjs","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, Catalogs, Locale, TranslationState } from './types';\n\ntype CatalogStoreOptions<C extends Catalog> = {\n readonly catalogs?: Catalogs<C>;\n readonly loadCatalog?: (locale: Locale) => Promise<C> | C;\n};\n\n/** One catalog state machine owns loaded catalogs and in-flight loading work. */\nexport function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>) {\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n const hydrate = (locale: Locale, catalog: C): void => {\n loaded.set(canonicalLocale(locale), { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, catalog] of Object.entries(options.catalogs ?? {})) hydrate(locale, catalog);\n\n const load = async (requestedLocale: Locale): Promise<boolean> => {\n const locale = canonicalLocale(requestedLocale);\n\n if (loaded.has(locale)) return false;\n\n const existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n if (!options.loadCatalog) {\n throw new LinguaMissingCatalogError(`No catalog source provided for locale \"${locale}\".`);\n }\n\n const task = Promise.resolve(options.loadCatalog(locale)).then(\n (catalog) => {\n hydrate(locale, catalog);\n tasks.delete(locale);\n },\n (error: unknown) => {\n tasks.delete(locale);\n throw error;\n },\n );\n\n tasks.set(locale, task);\n await task;\n\n return true;\n };\n\n return {\n catalogMap(): ReadonlyMap<Locale, CompiledCatalog> {\n return new Map([...loaded].map(([locale, { compiled }]) => [locale, compiled]));\n },\n hydrate,\n isLoaded(locale: Locale): boolean {\n return loaded.has(canonicalLocale(locale));\n },\n load,\n state(locale: Locale): TranslationState<C> {\n const catalogs: Catalogs<C> = {};\n\n for (const [loadedLocale, { catalog }] of loaded) catalogs[loadedLocale] = catalog;\n\n return { catalogs, locale, version: 4 };\n },\n };\n}\n"],"mappings":"uFAWA,SAAgB,EAAsC,EAAiC,CACrF,IAAM,EAAS,IAAI,IACb,EAAQ,IAAI,IAEZ,GAAW,EAAgB,IAAqB,CACpD,EAAO,IAAI,EAAA,gBAAgB,CAAM,EAAG,CAAE,UAAS,SAAU,EAAA,eAAe,CAAO,CAAE,CAAC,CACpF,EAEA,IAAK,GAAM,CAAC,EAAQ,KAAY,OAAO,QAAQ,EAAQ,UAAY,CAAC,CAAC,EAAG,EAAQ,EAAQ,CAAO,EAoC/F,MAAO,CACL,YAAmD,CACjD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAM,CAAC,CAAC,KAAK,CAAC,EAAQ,CAAE,eAAgB,CAAC,EAAQ,CAAQ,CAAC,CAAC,CAChF,EACA,UACA,SAAS,EAAyB,CAChC,OAAO,EAAO,IAAI,EAAA,gBAAgB,CAAM,CAAC,CAC3C,EACA,UA1CkB,IAA8C,CAChE,IAAM,EAAS,EAAA,gBAAgB,CAAe,EAE9C,GAAI,EAAO,IAAI,CAAM,EAAG,MAAO,GAE/B,IAAM,EAAW,EAAM,IAAI,CAAM,EAEjC,GAAI,EAGF,OAFA,MAAM,EAEC,GAGT,GAAI,CAAC,EAAQ,YACX,MAAM,IAAI,EAAA,0BAA0B,0CAA0C,EAAO,GAAG,EAG1F,IAAM,EAAO,QAAQ,QAAQ,EAAQ,YAAY,CAAM,CAAC,CAAC,CAAC,KACvD,GAAY,CACX,EAAQ,EAAQ,CAAO,EACvB,EAAM,OAAO,CAAM,CACrB,EACC,GAAmB,CAElB,MADA,EAAM,OAAO,CAAM,EACb,CACR,CACF,EAKA,OAHA,EAAM,IAAI,EAAQ,CAAI,EACtB,MAAM,EAEC,EACT,EAWE,MAAM,EAAqC,CACzC,IAAM,EAAwB,CAAC,EAE/B,IAAK,GAAM,CAAC,EAAc,CAAE,cAAc,EAAQ,EAAS,GAAgB,EAE3E,MAAO,CAAE,WAAU,SAAQ,QAAS,CAAE,CACxC,CACF,CACF"}
1
+ {"version":3,"file":"_resources.cjs","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, Catalogs, Locale, TranslationState } from './types';\n\ntype CatalogStoreOptions<C extends Catalog> = {\n readonly catalogs?: Catalogs<C>;\n readonly loadCatalog?: (locale: Locale) => Promise<C> | C;\n};\n\n/** One catalog state machine owns loaded catalogs and in-flight loading work. */\nexport function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>) {\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n const hydrate = (locale: Locale, catalog: C): void => {\n loaded.set(canonicalLocale(locale), { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, catalog] of Object.entries(options.catalogs ?? {})) hydrate(locale, catalog);\n\n const load = async (requestedLocale: Locale): Promise<boolean> => {\n const locale = canonicalLocale(requestedLocale);\n\n if (loaded.has(locale)) return false;\n\n const existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n if (!options.loadCatalog) {\n throw new LinguaMissingCatalogError(`No catalog source provided for locale \"${locale}\".`);\n }\n\n const task = Promise.resolve(options.loadCatalog(locale)).then(\n (catalog) => {\n hydrate(locale, catalog);\n tasks.delete(locale);\n },\n (error: unknown) => {\n tasks.delete(locale);\n throw error;\n },\n );\n\n tasks.set(locale, task);\n await task;\n\n return true;\n };\n\n return {\n catalogMap(): ReadonlyMap<Locale, CompiledCatalog> {\n return new Map([...loaded].map(([locale, { compiled }]) => [locale, compiled]));\n },\n hydrate,\n isLoaded(locale: Locale): boolean {\n return loaded.has(canonicalLocale(locale));\n },\n load,\n state(locale: Locale): TranslationState<C> {\n const catalogs: Catalogs<C> = {};\n\n for (const [loadedLocale, { catalog }] of loaded) catalogs[loadedLocale] = catalog;\n\n return { catalogs, locale, version: 1 };\n },\n };\n}\n"],"mappings":"uFAWA,SAAgB,mBAAsC,EAAiC,CACrF,IAAM,EAAS,IAAI,IACb,EAAQ,IAAI,IAEZ,SAAW,EAAgB,IAAqB,CACpD,EAAO,IAAI,EAAA,gBAAgB,CAAM,EAAG,CAAE,UAAS,SAAU,EAAA,eAAe,CAAO,CAAE,CAAC,CACpF,EAEA,IAAK,GAAM,CAAC,EAAQ,KAAY,OAAO,QAAQ,EAAQ,UAAY,CAAC,CAAC,EAAG,QAAQ,EAAQ,CAAO,EAE/F,IAAM,KAAO,KAAO,IAA8C,CAChE,IAAM,EAAS,EAAA,gBAAgB,CAAe,EAE9C,GAAI,EAAO,IAAI,CAAM,EAAG,MAAO,GAE/B,IAAM,EAAW,EAAM,IAAI,CAAM,EAEjC,GAAI,EAGF,OAFA,MAAM,EAEC,GAGT,GAAI,CAAC,EAAQ,YACX,MAAM,IAAI,EAAA,0BAA0B,0CAA0C,EAAO,GAAG,EAG1F,IAAM,EAAO,QAAQ,QAAQ,EAAQ,YAAY,CAAM,CAAC,CAAC,CAAC,KACvD,GAAY,CACX,QAAQ,EAAQ,CAAO,EACvB,EAAM,OAAO,CAAM,CACrB,EACC,GAAmB,CAElB,MADA,EAAM,OAAO,CAAM,EACb,CACR,CACF,EAKA,OAHA,EAAM,IAAI,EAAQ,CAAI,EACtB,MAAM,EAEC,EACT,EAEA,MAAO,CACL,YAAmD,CACjD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAM,CAAC,CAAC,KAAK,CAAC,EAAQ,CAAE,eAAgB,CAAC,EAAQ,CAAQ,CAAC,CAAC,CAChF,EACA,QACA,SAAS,EAAyB,CAChC,OAAO,EAAO,IAAI,EAAA,gBAAgB,CAAM,CAAC,CAC3C,EACA,KACA,MAAM,EAAqC,CACzC,IAAM,EAAwB,CAAC,EAE/B,IAAK,GAAM,CAAC,EAAc,CAAE,cAAc,EAAQ,EAAS,GAAgB,EAE3E,MAAO,CAAE,WAAU,SAAQ,QAAS,CAAE,CACxC,CACF,CACF"}
@@ -1,48 +1,2 @@
1
- import { LinguaMissingCatalogError as e } from "./errors.js";
2
- import { compileCatalog as t } from "./_catalog.js";
3
- import { canonicalLocale as n } from "./_locale.js";
4
- //#region src/_resources.ts
5
- function r(r) {
6
- let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = (e, r) => {
7
- i.set(n(e), {
8
- catalog: r,
9
- compiled: t(r)
10
- });
11
- };
12
- for (let [e, t] of Object.entries(r.catalogs ?? {})) o(e, t);
13
- return {
14
- catalogMap() {
15
- return new Map([...i].map(([e, { compiled: t }]) => [e, t]));
16
- },
17
- hydrate: o,
18
- isLoaded(e) {
19
- return i.has(n(e));
20
- },
21
- load: async (t) => {
22
- let s = n(t);
23
- if (i.has(s)) return !1;
24
- let c = a.get(s);
25
- if (c) return await c, !1;
26
- if (!r.loadCatalog) throw new e(`No catalog source provided for locale "${s}".`);
27
- let l = Promise.resolve(r.loadCatalog(s)).then((e) => {
28
- o(s, e), a.delete(s);
29
- }, (e) => {
30
- throw a.delete(s), e;
31
- });
32
- return a.set(s, l), await l, !0;
33
- },
34
- state(e) {
35
- let t = {};
36
- for (let [e, { catalog: n }] of i) t[e] = n;
37
- return {
38
- catalogs: t,
39
- locale: e,
40
- version: 4
41
- };
42
- }
43
- };
44
- }
45
- //#endregion
46
- export { r as createCatalogStore };
47
-
1
+ import{LinguaMissingCatalogError as e}from"./errors.js";import{compileCatalog as t}from"./_catalog.js";import{canonicalLocale as n}from"./_locale.js";function createCatalogStore(r){let i=new Map,a=new Map,hydrate=(e,r)=>{i.set(n(e),{catalog:r,compiled:t(r)})};for(let[e,t]of Object.entries(r.catalogs??{}))hydrate(e,t);let load=async t=>{let o=n(t);if(i.has(o))return!1;let s=a.get(o);if(s)return await s,!1;if(!r.loadCatalog)throw new e(`No catalog source provided for locale "${o}".`);let c=Promise.resolve(r.loadCatalog(o)).then(e=>{hydrate(o,e),a.delete(o)},e=>{throw a.delete(o),e});return a.set(o,c),await c,!0};return{catalogMap(){return new Map([...i].map(([e,{compiled:t}])=>[e,t]))},hydrate,isLoaded(e){return i.has(n(e))},load,state(e){let t={};for(let[e,{catalog:n}]of i)t[e]=n;return{catalogs:t,locale:e,version:1}}}}export{createCatalogStore};
48
2
  //# sourceMappingURL=_resources.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_resources.js","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, Catalogs, Locale, TranslationState } from './types';\n\ntype CatalogStoreOptions<C extends Catalog> = {\n readonly catalogs?: Catalogs<C>;\n readonly loadCatalog?: (locale: Locale) => Promise<C> | C;\n};\n\n/** One catalog state machine owns loaded catalogs and in-flight loading work. */\nexport function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>) {\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n const hydrate = (locale: Locale, catalog: C): void => {\n loaded.set(canonicalLocale(locale), { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, catalog] of Object.entries(options.catalogs ?? {})) hydrate(locale, catalog);\n\n const load = async (requestedLocale: Locale): Promise<boolean> => {\n const locale = canonicalLocale(requestedLocale);\n\n if (loaded.has(locale)) return false;\n\n const existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n if (!options.loadCatalog) {\n throw new LinguaMissingCatalogError(`No catalog source provided for locale \"${locale}\".`);\n }\n\n const task = Promise.resolve(options.loadCatalog(locale)).then(\n (catalog) => {\n hydrate(locale, catalog);\n tasks.delete(locale);\n },\n (error: unknown) => {\n tasks.delete(locale);\n throw error;\n },\n );\n\n tasks.set(locale, task);\n await task;\n\n return true;\n };\n\n return {\n catalogMap(): ReadonlyMap<Locale, CompiledCatalog> {\n return new Map([...loaded].map(([locale, { compiled }]) => [locale, compiled]));\n },\n hydrate,\n isLoaded(locale: Locale): boolean {\n return loaded.has(canonicalLocale(locale));\n },\n load,\n state(locale: Locale): TranslationState<C> {\n const catalogs: Catalogs<C> = {};\n\n for (const [loadedLocale, { catalog }] of loaded) catalogs[loadedLocale] = catalog;\n\n return { catalogs, locale, version: 4 };\n },\n };\n}\n"],"mappings":";;;;AAWA,SAAgB,EAAsC,GAAiC;CACrF,IAAM,oBAAS,IAAI,IAAyE,GACtF,oBAAQ,IAAI,IAA2B,GAEvC,KAAW,GAAgB,MAAqB;EACpD,EAAO,IAAI,EAAgB,CAAM,GAAG;GAAE;GAAS,UAAU,EAAe,CAAO;EAAE,CAAC;CACpF;CAEA,KAAK,IAAM,CAAC,GAAQ,MAAY,OAAO,QAAQ,EAAQ,YAAY,CAAC,CAAC,GAAG,EAAQ,GAAQ,CAAO;CAoC/F,OAAO;EACL,aAAmD;GACjD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAM,CAAC,CAAC,KAAK,CAAC,GAAQ,EAAE,mBAAgB,CAAC,GAAQ,CAAQ,CAAC,CAAC;EAChF;EACA;EACA,SAAS,GAAyB;GAChC,OAAO,EAAO,IAAI,EAAgB,CAAM,CAAC;EAC3C;EACA,aA1CkB,MAA8C;GAChE,IAAM,IAAS,EAAgB,CAAe;GAE9C,IAAI,EAAO,IAAI,CAAM,GAAG,OAAO;GAE/B,IAAM,IAAW,EAAM,IAAI,CAAM;GAEjC,IAAI,GAGF,OAFA,MAAM,GAEC;GAGT,IAAI,CAAC,EAAQ,aACX,MAAM,IAAI,EAA0B,0CAA0C,EAAO,GAAG;GAG1F,IAAM,IAAO,QAAQ,QAAQ,EAAQ,YAAY,CAAM,CAAC,CAAC,CAAC,MACvD,MAAY;IAEX,AADA,EAAQ,GAAQ,CAAO,GACvB,EAAM,OAAO,CAAM;GACrB,IACC,MAAmB;IAElB,MADA,EAAM,OAAO,CAAM,GACb;GACR,CACF;GAKA,OAHA,EAAM,IAAI,GAAQ,CAAI,GACtB,MAAM,GAEC;EACT;EAWE,MAAM,GAAqC;GACzC,IAAM,IAAwB,CAAC;GAE/B,KAAK,IAAM,CAAC,GAAc,EAAE,iBAAc,GAAQ,EAAS,KAAgB;GAE3E,OAAO;IAAE;IAAU;IAAQ,SAAS;GAAE;EACxC;CACF;AACF"}
1
+ {"version":3,"file":"_resources.js","names":[],"sources":["../src/_resources.ts"],"sourcesContent":["import { type CompiledCatalog, compileCatalog } from './_catalog';\nimport { canonicalLocale } from './_locale';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { Catalog, Catalogs, Locale, TranslationState } from './types';\n\ntype CatalogStoreOptions<C extends Catalog> = {\n readonly catalogs?: Catalogs<C>;\n readonly loadCatalog?: (locale: Locale) => Promise<C> | C;\n};\n\n/** One catalog state machine owns loaded catalogs and in-flight loading work. */\nexport function createCatalogStore<C extends Catalog>(options: CatalogStoreOptions<C>) {\n const loaded = new Map<Locale, { readonly catalog: C; readonly compiled: CompiledCatalog }>();\n const tasks = new Map<Locale, Promise<void>>();\n\n const hydrate = (locale: Locale, catalog: C): void => {\n loaded.set(canonicalLocale(locale), { catalog, compiled: compileCatalog(catalog) });\n };\n\n for (const [locale, catalog] of Object.entries(options.catalogs ?? {})) hydrate(locale, catalog);\n\n const load = async (requestedLocale: Locale): Promise<boolean> => {\n const locale = canonicalLocale(requestedLocale);\n\n if (loaded.has(locale)) return false;\n\n const existing = tasks.get(locale);\n\n if (existing) {\n await existing;\n\n return false;\n }\n\n if (!options.loadCatalog) {\n throw new LinguaMissingCatalogError(`No catalog source provided for locale \"${locale}\".`);\n }\n\n const task = Promise.resolve(options.loadCatalog(locale)).then(\n (catalog) => {\n hydrate(locale, catalog);\n tasks.delete(locale);\n },\n (error: unknown) => {\n tasks.delete(locale);\n throw error;\n },\n );\n\n tasks.set(locale, task);\n await task;\n\n return true;\n };\n\n return {\n catalogMap(): ReadonlyMap<Locale, CompiledCatalog> {\n return new Map([...loaded].map(([locale, { compiled }]) => [locale, compiled]));\n },\n hydrate,\n isLoaded(locale: Locale): boolean {\n return loaded.has(canonicalLocale(locale));\n },\n load,\n state(locale: Locale): TranslationState<C> {\n const catalogs: Catalogs<C> = {};\n\n for (const [loadedLocale, { catalog }] of loaded) catalogs[loadedLocale] = catalog;\n\n return { catalogs, locale, version: 1 };\n },\n };\n}\n"],"mappings":"sJAWA,SAAgB,mBAAsC,EAAiC,CACrF,IAAM,EAAS,IAAI,IACb,EAAQ,IAAI,IAEZ,SAAW,EAAgB,IAAqB,CACpD,EAAO,IAAI,EAAgB,CAAM,EAAG,CAAE,UAAS,SAAU,EAAe,CAAO,CAAE,CAAC,CACpF,EAEA,IAAK,GAAM,CAAC,EAAQ,KAAY,OAAO,QAAQ,EAAQ,UAAY,CAAC,CAAC,EAAG,QAAQ,EAAQ,CAAO,EAE/F,IAAM,KAAO,KAAO,IAA8C,CAChE,IAAM,EAAS,EAAgB,CAAe,EAE9C,GAAI,EAAO,IAAI,CAAM,EAAG,MAAO,GAE/B,IAAM,EAAW,EAAM,IAAI,CAAM,EAEjC,GAAI,EAGF,OAFA,MAAM,EAEC,GAGT,GAAI,CAAC,EAAQ,YACX,MAAM,IAAI,EAA0B,0CAA0C,EAAO,GAAG,EAG1F,IAAM,EAAO,QAAQ,QAAQ,EAAQ,YAAY,CAAM,CAAC,CAAC,CAAC,KACvD,GAAY,CACX,QAAQ,EAAQ,CAAO,EACvB,EAAM,OAAO,CAAM,CACrB,EACC,GAAmB,CAElB,MADA,EAAM,OAAO,CAAM,EACb,CACR,CACF,EAKA,OAHA,EAAM,IAAI,EAAQ,CAAI,EACtB,MAAM,EAEC,EACT,EAEA,MAAO,CACL,YAAmD,CACjD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAM,CAAC,CAAC,KAAK,CAAC,EAAQ,CAAE,eAAgB,CAAC,EAAQ,CAAQ,CAAC,CAAC,CAChF,EACA,QACA,SAAS,EAAyB,CAChC,OAAO,EAAO,IAAI,EAAgB,CAAM,CAAC,CAC3C,EACA,KACA,MAAM,EAAqC,CACzC,IAAM,EAAwB,CAAC,EAE/B,IAAK,GAAM,CAAC,EAAc,CAAE,cAAc,EAAQ,EAAS,GAAgB,EAE3E,MAAO,CAAE,WAAU,SAAQ,QAAS,CAAE,CACxC,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- var e=/\{([\p{ID_Continue}-]+)\}/gu;function t(t){let n=[],r=0;for(let i of t.matchAll(e)){let e=i.index??0;e>r&&n.push(t.slice(r,e)),n.push({value:i[1]}),r=e+i[0].length}return r<t.length&&n.push(t.slice(r)),n}function n(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function r(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push({type:`text`,value:i});continue}Object.hasOwn(t,i.value)?r.push({type:`value`,value:t[i.value]}):r.push({type:`text`,value:n(i.value)})}return r}exports.compileTemplate=t,exports.renderParts=r,exports.renderText=n;
1
+ var e=/\{([\p{ID_Continue}-]+)\}/gu;function compileTemplate(t){let n=[],r=0;for(let i of t.matchAll(e)){let e=i.index??0;e>r&&n.push(t.slice(r,e)),n.push({value:i[1]}),r=e+i[0].length}return r<t.length&&n.push(t.slice(r)),n}function renderText(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function renderParts(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push({type:`text`,value:i});continue}Object.hasOwn(t,i.value)?r.push({type:`value`,value:t[i.value]}):r.push({type:`text`,value:n(i.value)})}return r}exports.compileTemplate=compileTemplate,exports.renderParts=renderParts,exports.renderText=renderText;
2
2
  //# sourceMappingURL=_template.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_template.cjs","names":[],"sources":["../src/_template.ts"],"sourcesContent":["import type { Part } from './types';\n\nexport type TemplatePart = string | { readonly value: string };\nexport type Template = readonly TemplatePart[];\n\nconst interpolation = /\\{([\\p{ID_Continue}-]+)\\}/gu;\n\nexport function compileTemplate(value: string): Template {\n const parts: TemplatePart[] = [];\n let offset = 0;\n\n for (const match of value.matchAll(interpolation)) {\n const index = match.index ?? 0;\n\n if (index > offset) parts.push(value.slice(offset, index));\n\n parts.push({ value: match[1] });\n offset = index + match[0].length;\n }\n\n if (offset < value.length) parts.push(value.slice(offset));\n\n return parts;\n}\n\nexport function renderText(\n parts: Template,\n values: Record<string, unknown>,\n missing: (name: string) => string,\n): string {\n return parts\n .map((part) => {\n if (typeof part === 'string') return part;\n\n const value = Object.hasOwn(values, part.value) ? values[part.value] : undefined;\n\n return value == null ? missing(part.value) : String(value);\n })\n .join('');\n}\n\nexport function renderParts<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<Part<V | number>> {\n const result: Array<Part<V | number>> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push({ type: 'text', value: part });\n\n continue;\n }\n\n if (Object.hasOwn(values, part.value)) {\n result.push({ type: 'value', value: values[part.value]! as V | number });\n } else {\n result.push({ type: 'text', value: missing(part.value) });\n }\n }\n\n return result;\n}\n"],"mappings":"AAKA,IAAM,EAAgB,8BAEtB,SAAgB,EAAgB,EAAyB,CACvD,IAAM,EAAwB,CAAC,EAC3B,EAAS,EAEb,IAAK,IAAM,KAAS,EAAM,SAAS,CAAa,EAAG,CACjD,IAAM,EAAQ,EAAM,OAAS,EAEzB,EAAQ,GAAQ,EAAM,KAAK,EAAM,MAAM,EAAQ,CAAK,CAAC,EAEzD,EAAM,KAAK,CAAE,MAAO,EAAM,EAAG,CAAC,EAC9B,EAAS,EAAQ,EAAM,EAAE,CAAC,MAC5B,CAIA,OAFI,EAAS,EAAM,QAAQ,EAAM,KAAK,EAAM,MAAM,CAAM,CAAC,EAElD,CACT,CAEA,SAAgB,EACd,EACA,EACA,EACQ,CACR,OAAO,EACJ,IAAK,GAAS,CACb,GAAI,OAAO,GAAS,SAAU,OAAO,EAErC,IAAM,EAAQ,OAAO,OAAO,EAAQ,EAAK,KAAK,EAAI,EAAO,EAAK,OAAS,IAAA,GAEvE,OAAO,GAAS,KAAO,EAAQ,EAAK,KAAK,EAAI,OAAO,CAAK,CAC3D,CAAC,CAAC,CACD,KAAK,EAAE,CACZ,CAEA,SAAgB,EACd,EACA,EACA,EACyB,CACzB,IAAM,EAAkC,CAAC,EAEzC,IAAK,IAAM,KAAQ,EAAO,CACxB,GAAI,OAAO,GAAS,SAAU,CACxB,IAAS,IAAI,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,CAAK,CAAC,EAE1D,QACF,CAEI,OAAO,OAAO,EAAQ,EAAK,KAAK,EAClC,EAAO,KAAK,CAAE,KAAM,QAAS,MAAO,EAAO,EAAK,MAAsB,CAAC,EAEvE,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,EAAQ,EAAK,KAAK,CAAE,CAAC,CAE5D,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"_template.cjs","names":[],"sources":["../src/_template.ts"],"sourcesContent":["import type { Part } from './types';\n\nexport type TemplatePart = string | { readonly value: string };\nexport type Template = readonly TemplatePart[];\n\nconst interpolation = /\\{([\\p{ID_Continue}-]+)\\}/gu;\n\nexport function compileTemplate(value: string): Template {\n const parts: TemplatePart[] = [];\n let offset = 0;\n\n for (const match of value.matchAll(interpolation)) {\n const index = match.index ?? 0;\n\n if (index > offset) parts.push(value.slice(offset, index));\n\n parts.push({ value: match[1] });\n offset = index + match[0].length;\n }\n\n if (offset < value.length) parts.push(value.slice(offset));\n\n return parts;\n}\n\nexport function renderText(\n parts: Template,\n values: Record<string, unknown>,\n missing: (name: string) => string,\n): string {\n return parts\n .map((part) => {\n if (typeof part === 'string') return part;\n\n const value = Object.hasOwn(values, part.value) ? values[part.value] : undefined;\n\n return value == null ? missing(part.value) : String(value);\n })\n .join('');\n}\n\nexport function renderParts<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<Part<V | number>> {\n const result: Array<Part<V | number>> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push({ type: 'text', value: part });\n\n continue;\n }\n\n if (Object.hasOwn(values, part.value)) {\n result.push({ type: 'value', value: values[part.value]! as V | number });\n } else {\n result.push({ type: 'text', value: missing(part.value) });\n }\n }\n\n return result;\n}\n"],"mappings":"AAKA,IAAM,EAAgB,8BAEtB,SAAgB,gBAAgB,EAAyB,CACvD,IAAM,EAAwB,CAAC,EAC3B,EAAS,EAEb,IAAK,IAAM,KAAS,EAAM,SAAS,CAAa,EAAG,CACjD,IAAM,EAAQ,EAAM,OAAS,EAEzB,EAAQ,GAAQ,EAAM,KAAK,EAAM,MAAM,EAAQ,CAAK,CAAC,EAEzD,EAAM,KAAK,CAAE,MAAO,EAAM,EAAG,CAAC,EAC9B,EAAS,EAAQ,EAAM,EAAE,CAAC,MAC5B,CAIA,OAFI,EAAS,EAAM,QAAQ,EAAM,KAAK,EAAM,MAAM,CAAM,CAAC,EAElD,CACT,CAEA,SAAgB,WACd,EACA,EACA,EACQ,CACR,OAAO,EACJ,IAAK,GAAS,CACb,GAAI,OAAO,GAAS,SAAU,OAAO,EAErC,IAAM,EAAQ,OAAO,OAAO,EAAQ,EAAK,KAAK,EAAI,EAAO,EAAK,OAAS,IAAA,GAEvE,OAAO,GAAS,KAAO,EAAQ,EAAK,KAAK,EAAI,OAAO,CAAK,CAC3D,CAAC,CAAC,CACD,KAAK,EAAE,CACZ,CAEA,SAAgB,YACd,EACA,EACA,EACyB,CACzB,IAAM,EAAkC,CAAC,EAEzC,IAAK,IAAM,KAAQ,EAAO,CACxB,GAAI,OAAO,GAAS,SAAU,CACxB,IAAS,IAAI,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,CAAK,CAAC,EAE1D,QACF,CAEI,OAAO,OAAO,EAAQ,EAAK,KAAK,EAClC,EAAO,KAAK,CAAE,KAAM,QAAS,MAAO,EAAO,EAAK,MAAsB,CAAC,EAEvE,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,EAAQ,EAAK,KAAK,CAAE,CAAC,CAE5D,CAEA,OAAO,CACT"}
package/dist/_template.js CHANGED
@@ -1,41 +1,2 @@
1
- //#region src/_template.ts
2
- var e = /\{([\p{ID_Continue}-]+)\}/gu;
3
- function t(t) {
4
- let n = [], r = 0;
5
- for (let i of t.matchAll(e)) {
6
- let e = i.index ?? 0;
7
- e > r && n.push(t.slice(r, e)), n.push({ value: i[1] }), r = e + i[0].length;
8
- }
9
- return r < t.length && n.push(t.slice(r)), n;
10
- }
11
- function n(e, t, n) {
12
- return e.map((e) => {
13
- if (typeof e == "string") return e;
14
- let r = Object.hasOwn(t, e.value) ? t[e.value] : void 0;
15
- return r == null ? n(e.value) : String(r);
16
- }).join("");
17
- }
18
- function r(e, t, n) {
19
- let r = [];
20
- for (let i of e) {
21
- if (typeof i == "string") {
22
- i !== "" && r.push({
23
- type: "text",
24
- value: i
25
- });
26
- continue;
27
- }
28
- Object.hasOwn(t, i.value) ? r.push({
29
- type: "value",
30
- value: t[i.value]
31
- }) : r.push({
32
- type: "text",
33
- value: n(i.value)
34
- });
35
- }
36
- return r;
37
- }
38
- //#endregion
39
- export { t as compileTemplate, r as renderParts, n as renderText };
40
-
1
+ var e=/\{([\p{ID_Continue}-]+)\}/gu;function compileTemplate(t){let n=[],r=0;for(let i of t.matchAll(e)){let e=i.index??0;e>r&&n.push(t.slice(r,e)),n.push({value:i[1]}),r=e+i[0].length}return r<t.length&&n.push(t.slice(r)),n}function renderText(e,t,n){return e.map(e=>{if(typeof e==`string`)return e;let r=Object.hasOwn(t,e.value)?t[e.value]:void 0;return r==null?n(e.value):String(r)}).join(``)}function renderParts(e,t,n){let r=[];for(let i of e){if(typeof i==`string`){i!==``&&r.push({type:`text`,value:i});continue}Object.hasOwn(t,i.value)?r.push({type:`value`,value:t[i.value]}):r.push({type:`text`,value:n(i.value)})}return r}export{compileTemplate,renderParts,renderText};
41
2
  //# sourceMappingURL=_template.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_template.js","names":[],"sources":["../src/_template.ts"],"sourcesContent":["import type { Part } from './types';\n\nexport type TemplatePart = string | { readonly value: string };\nexport type Template = readonly TemplatePart[];\n\nconst interpolation = /\\{([\\p{ID_Continue}-]+)\\}/gu;\n\nexport function compileTemplate(value: string): Template {\n const parts: TemplatePart[] = [];\n let offset = 0;\n\n for (const match of value.matchAll(interpolation)) {\n const index = match.index ?? 0;\n\n if (index > offset) parts.push(value.slice(offset, index));\n\n parts.push({ value: match[1] });\n offset = index + match[0].length;\n }\n\n if (offset < value.length) parts.push(value.slice(offset));\n\n return parts;\n}\n\nexport function renderText(\n parts: Template,\n values: Record<string, unknown>,\n missing: (name: string) => string,\n): string {\n return parts\n .map((part) => {\n if (typeof part === 'string') return part;\n\n const value = Object.hasOwn(values, part.value) ? values[part.value] : undefined;\n\n return value == null ? missing(part.value) : String(value);\n })\n .join('');\n}\n\nexport function renderParts<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<Part<V | number>> {\n const result: Array<Part<V | number>> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push({ type: 'text', value: part });\n\n continue;\n }\n\n if (Object.hasOwn(values, part.value)) {\n result.push({ type: 'value', value: values[part.value]! as V | number });\n } else {\n result.push({ type: 'text', value: missing(part.value) });\n }\n }\n\n return result;\n}\n"],"mappings":";AAKA,IAAM,IAAgB;AAEtB,SAAgB,EAAgB,GAAyB;CACvD,IAAM,IAAwB,CAAC,GAC3B,IAAS;CAEb,KAAK,IAAM,KAAS,EAAM,SAAS,CAAa,GAAG;EACjD,IAAM,IAAQ,EAAM,SAAS;EAK7B,AAHI,IAAQ,KAAQ,EAAM,KAAK,EAAM,MAAM,GAAQ,CAAK,CAAC,GAEzD,EAAM,KAAK,EAAE,OAAO,EAAM,GAAG,CAAC,GAC9B,IAAS,IAAQ,EAAM,EAAE,CAAC;CAC5B;CAIA,OAFI,IAAS,EAAM,UAAQ,EAAM,KAAK,EAAM,MAAM,CAAM,CAAC,GAElD;AACT;AAEA,SAAgB,EACd,GACA,GACA,GACQ;CACR,OAAO,EACJ,KAAK,MAAS;EACb,IAAI,OAAO,KAAS,UAAU,OAAO;EAErC,IAAM,IAAQ,OAAO,OAAO,GAAQ,EAAK,KAAK,IAAI,EAAO,EAAK,SAAS,KAAA;EAEvE,OAAO,KAAS,OAAO,EAAQ,EAAK,KAAK,IAAI,OAAO,CAAK;CAC3D,CAAC,CAAC,CACD,KAAK,EAAE;AACZ;AAEA,SAAgB,EACd,GACA,GACA,GACyB;CACzB,IAAM,IAAkC,CAAC;CAEzC,KAAK,IAAM,KAAQ,GAAO;EACxB,IAAI,OAAO,KAAS,UAAU;GAC5B,AAAI,MAAS,MAAI,EAAO,KAAK;IAAE,MAAM;IAAQ,OAAO;GAAK,CAAC;GAE1D;EACF;EAEA,AAAI,OAAO,OAAO,GAAQ,EAAK,KAAK,IAClC,EAAO,KAAK;GAAE,MAAM;GAAS,OAAO,EAAO,EAAK;EAAsB,CAAC,IAEvE,EAAO,KAAK;GAAE,MAAM;GAAQ,OAAO,EAAQ,EAAK,KAAK;EAAE,CAAC;CAE5D;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"_template.js","names":[],"sources":["../src/_template.ts"],"sourcesContent":["import type { Part } from './types';\n\nexport type TemplatePart = string | { readonly value: string };\nexport type Template = readonly TemplatePart[];\n\nconst interpolation = /\\{([\\p{ID_Continue}-]+)\\}/gu;\n\nexport function compileTemplate(value: string): Template {\n const parts: TemplatePart[] = [];\n let offset = 0;\n\n for (const match of value.matchAll(interpolation)) {\n const index = match.index ?? 0;\n\n if (index > offset) parts.push(value.slice(offset, index));\n\n parts.push({ value: match[1] });\n offset = index + match[0].length;\n }\n\n if (offset < value.length) parts.push(value.slice(offset));\n\n return parts;\n}\n\nexport function renderText(\n parts: Template,\n values: Record<string, unknown>,\n missing: (name: string) => string,\n): string {\n return parts\n .map((part) => {\n if (typeof part === 'string') return part;\n\n const value = Object.hasOwn(values, part.value) ? values[part.value] : undefined;\n\n return value == null ? missing(part.value) : String(value);\n })\n .join('');\n}\n\nexport function renderParts<V>(\n parts: Template,\n values: Record<string, V | number>,\n missing: (name: string) => string,\n): Array<Part<V | number>> {\n const result: Array<Part<V | number>> = [];\n\n for (const part of parts) {\n if (typeof part === 'string') {\n if (part !== '') result.push({ type: 'text', value: part });\n\n continue;\n }\n\n if (Object.hasOwn(values, part.value)) {\n result.push({ type: 'value', value: values[part.value]! as V | number });\n } else {\n result.push({ type: 'text', value: missing(part.value) });\n }\n }\n\n return result;\n}\n"],"mappings":"AAKA,IAAM,EAAgB,8BAEtB,SAAgB,gBAAgB,EAAyB,CACvD,IAAM,EAAwB,CAAC,EAC3B,EAAS,EAEb,IAAK,IAAM,KAAS,EAAM,SAAS,CAAa,EAAG,CACjD,IAAM,EAAQ,EAAM,OAAS,EAEzB,EAAQ,GAAQ,EAAM,KAAK,EAAM,MAAM,EAAQ,CAAK,CAAC,EAEzD,EAAM,KAAK,CAAE,MAAO,EAAM,EAAG,CAAC,EAC9B,EAAS,EAAQ,EAAM,EAAE,CAAC,MAC5B,CAIA,OAFI,EAAS,EAAM,QAAQ,EAAM,KAAK,EAAM,MAAM,CAAM,CAAC,EAElD,CACT,CAEA,SAAgB,WACd,EACA,EACA,EACQ,CACR,OAAO,EACJ,IAAK,GAAS,CACb,GAAI,OAAO,GAAS,SAAU,OAAO,EAErC,IAAM,EAAQ,OAAO,OAAO,EAAQ,EAAK,KAAK,EAAI,EAAO,EAAK,OAAS,IAAA,GAEvE,OAAO,GAAS,KAAO,EAAQ,EAAK,KAAK,EAAI,OAAO,CAAK,CAC3D,CAAC,CAAC,CACD,KAAK,EAAE,CACZ,CAEA,SAAgB,YACd,EACA,EACA,EACyB,CACzB,IAAM,EAAkC,CAAC,EAEzC,IAAK,IAAM,KAAQ,EAAO,CACxB,GAAI,OAAO,GAAS,SAAU,CACxB,IAAS,IAAI,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,CAAK,CAAC,EAE1D,QACF,CAEI,OAAO,OAAO,EAAQ,EAAK,KAAK,EAClC,EAAO,KAAK,CAAE,KAAM,QAAS,MAAO,EAAO,EAAK,MAAsB,CAAC,EAEvE,EAAO,KAAK,CAAE,KAAM,OAAQ,MAAO,EAAQ,EAAK,KAAK,CAAE,CAAC,CAE5D,CAEA,OAAO,CACT"}
package/dist/catalog.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs"),t=require("./_catalog.cjs");function n(n){if(typeof n==`object`&&n&&`serialize`in n&&`getSnapshot`in n){let r=n,i=r.serialize().catalogs[r.locale];if(!i)throw new e.LinguaMissingCatalogError(`No catalog loaded for locale "${r.locale}".`);return[...t.compileCatalog(i).keys()]}return[...t.compileCatalog(n).keys()]}exports.catalogKeys=n;
1
+ const e=require("./_catalog.cjs");function catalogKeys(t){return[...e.compileCatalog(t).keys()]}exports.catalogKeys=catalogKeys;
2
2
  //# sourceMappingURL=catalog.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.cjs","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { I18n } from './i18n';\nimport type { Catalog, MessageKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `MessageKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass an `I18n` instance to enumerate keys from its current locale catalog\n * without specifying a locale explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n *\n * // From an i18n instance — uses current locale's catalog\n * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(i18n: I18n<C>): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<MessageKey<Catalog>> {\n if (typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source) {\n const i18n = source as I18n;\n const catalog = i18n.serialize().catalogs[i18n.locale];\n\n if (!catalog) throw new LinguaMissingCatalogError(`No catalog loaded for locale \"${i18n.locale}\".`);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n }\n\n return [...compileCatalog(source as Catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n}\n"],"mappings":"4DA6BA,SAAgB,EAAY,EAAqD,CAC/E,GAAI,OAAO,GAAW,UAAY,GAAmB,cAAe,GAAU,gBAAiB,EAAQ,CACrG,IAAM,EAAO,EACP,EAAU,EAAK,UAAU,CAAC,CAAC,SAAS,EAAK,QAE/C,GAAI,CAAC,EAAS,MAAM,IAAI,EAAA,0BAA0B,iCAAiC,EAAK,OAAO,GAAG,EAElG,MAAO,CAAC,GAAG,EAAA,eAAe,CAAO,CAAC,CAAC,KAAK,CAAC,CAC3C,CAEA,MAAO,CAAC,GAAG,EAAA,eAAe,CAAiB,CAAC,CAAC,KAAK,CAAC,CACrD"}
1
+ {"version":3,"file":"catalog.cjs","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport type { Catalog, MessageKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `MessageKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass any catalog subtree to enumerate group-scoped keys. For an `I18n`\n * instance, pass its current locale catalog explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n * const navKeys = catalogKeys(messages.nav); // ['home', 'settings']\n *\n * // From an i18n instance — read the current locale's catalog first\n * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });\n * const state = i18n.serialize();\n * const allKeys = catalogKeys(state.catalogs[state.locale]);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>> {\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<MessageKey<C>>;\n}\n"],"mappings":"kCA2BA,SAAgB,YAA+B,EAA0C,CACvF,MAAO,CAAC,GAAG,EAAA,eAAe,CAAO,CAAC,CAAC,KAAK,CAAC,CAC3C"}
package/dist/catalog.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { I18n } from './i18n';
2
1
  import type { Catalog, MessageKey } from './types';
3
2
  /** Enumerate every message key in a catalog as a dotted path.
4
3
  *
@@ -7,8 +6,8 @@ import type { Catalog, MessageKey } from './types';
7
6
  * level. Use this to derive key arrays from the catalog itself instead of
8
7
  * maintaining a parallel list that can go stale.
9
8
  *
10
- * Pass an `I18n` instance to enumerate keys from its current locale catalog
11
- * without specifying a locale explicitly.
9
+ * Pass any catalog subtree to enumerate group-scoped keys. For an `I18n`
10
+ * instance, pass its current locale catalog explicitly.
12
11
  *
13
12
  * @example
14
13
  * ```ts
@@ -16,12 +15,13 @@ import type { Catalog, MessageKey } from './types';
16
15
  * nav: { home: '...', settings: '...' },
17
16
  * };
18
17
  * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']
18
+ * const navKeys = catalogKeys(messages.nav); // ['home', 'settings']
19
19
  *
20
- * // From an i18n instance — uses current locale's catalog
20
+ * // From an i18n instance — read the current locale's catalog first
21
21
  * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });
22
- * const allKeys = catalogKeys(i18n);
22
+ * const state = i18n.serialize();
23
+ * const allKeys = catalogKeys(state.catalogs[state.locale]);
23
24
  * ```
24
25
  */
25
- export declare function catalogKeys<C extends Catalog>(i18n: I18n<C>): ReadonlyArray<MessageKey<C>>;
26
26
  export declare function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>>;
27
27
  //# sourceMappingURL=catalog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5F,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAEvF"}
package/dist/catalog.js CHANGED
@@ -1,15 +1,2 @@
1
- import { LinguaMissingCatalogError as e } from "./errors.js";
2
- import { compileCatalog as t } from "./_catalog.js";
3
- //#region src/catalog.ts
4
- function n(n) {
5
- if (typeof n == "object" && n && "serialize" in n && "getSnapshot" in n) {
6
- let r = n, i = r.serialize().catalogs[r.locale];
7
- if (!i) throw new e(`No catalog loaded for locale "${r.locale}".`);
8
- return [...t(i).keys()];
9
- }
10
- return [...t(n).keys()];
11
- }
12
- //#endregion
13
- export { n as catalogKeys };
14
-
1
+ import{compileCatalog as e}from"./_catalog.js";function catalogKeys(t){return[...e(t).keys()]}export{catalogKeys};
15
2
  //# sourceMappingURL=catalog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport { LinguaMissingCatalogError } from './errors';\nimport type { I18n } from './i18n';\nimport type { Catalog, MessageKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `MessageKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass an `I18n` instance to enumerate keys from its current locale catalog\n * without specifying a locale explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n *\n * // From an i18n instance — uses current locale's catalog\n * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });\n * const allKeys = catalogKeys(i18n);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(i18n: I18n<C>): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>>;\nexport function catalogKeys(source: unknown): ReadonlyArray<MessageKey<Catalog>> {\n if (typeof source === 'object' && source !== null && 'serialize' in source && 'getSnapshot' in source) {\n const i18n = source as I18n;\n const catalog = i18n.serialize().catalogs[i18n.locale];\n\n if (!catalog) throw new LinguaMissingCatalogError(`No catalog loaded for locale \"${i18n.locale}\".`);\n\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n }\n\n return [...compileCatalog(source as Catalog).keys()] as unknown as ReadonlyArray<MessageKey<Catalog>>;\n}\n"],"mappings":";;;AA6BA,SAAgB,EAAY,GAAqD;CAC/E,IAAI,OAAO,KAAW,YAAY,KAAmB,eAAe,KAAU,iBAAiB,GAAQ;EACrG,IAAM,IAAO,GACP,IAAU,EAAK,UAAU,CAAC,CAAC,SAAS,EAAK;EAE/C,IAAI,CAAC,GAAS,MAAM,IAAI,EAA0B,iCAAiC,EAAK,OAAO,GAAG;EAElG,OAAO,CAAC,GAAG,EAAe,CAAO,CAAC,CAAC,KAAK,CAAC;CAC3C;CAEA,OAAO,CAAC,GAAG,EAAe,CAAiB,CAAC,CAAC,KAAK,CAAC;AACrD"}
1
+ {"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import { compileCatalog } from './_catalog';\nimport type { Catalog, MessageKey } from './types';\n\n/** Enumerate every message key in a catalog as a dotted path.\n *\n * Traverses nested grouping objects and explicit `{ plural: ... }` messages,\n * producing the same dotted paths that `MessageKey<C>` represents at the type\n * level. Use this to derive key arrays from the catalog itself instead of\n * maintaining a parallel list that can go stale.\n *\n * Pass any catalog subtree to enumerate group-scoped keys. For an `I18n`\n * instance, pass its current locale catalog explicitly.\n *\n * @example\n * ```ts\n * const messages = {\n * nav: { home: '...', settings: '...' },\n * };\n * const keys = catalogKeys(messages); // ['nav.home', 'nav.settings']\n * const navKeys = catalogKeys(messages.nav); // ['home', 'settings']\n *\n * // From an i18n instance — read the current locale's catalog first\n * const i18n = createI18n({ catalogs: { en: messages }, locale: 'en' });\n * const state = i18n.serialize();\n * const allKeys = catalogKeys(state.catalogs[state.locale]);\n * ```\n */\nexport function catalogKeys<C extends Catalog>(catalog: C): ReadonlyArray<MessageKey<C>> {\n return [...compileCatalog(catalog).keys()] as unknown as ReadonlyArray<MessageKey<C>>;\n}\n"],"mappings":"+CA2BA,SAAgB,YAA+B,EAA0C,CACvF,MAAO,CAAC,GAAG,EAAe,CAAO,CAAC,CAAC,KAAK,CAAC,CAC3C"}
package/dist/errors.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{constructor(){super(`Operation called on a disposed i18n instance.`)}},n=class extends e{},r=class extends e{},i=class extends e{},a=class extends e{},o=class extends e{},s=class extends e{},c=class extends e{};exports.LinguaDisposedError=t,exports.LinguaError=e,exports.LinguaInvalidCatalogError=n,exports.LinguaInvalidLocaleError=r,exports.LinguaInvalidPluralCountError=i,exports.LinguaInvalidStateError=a,exports.LinguaMissingCatalogError=o,exports.LinguaMissingKeyError=s,exports.LinguaMissingValueError=c;
1
+ var LinguaError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},LinguaDisposedError=class extends LinguaError{constructor(){super(`Operation called on a disposed i18n instance.`)}},LinguaInvalidCatalogError=class extends LinguaError{},LinguaInvalidLocaleError=class extends LinguaError{},LinguaInvalidPluralCountError=class extends LinguaError{},LinguaInvalidStateError=class extends LinguaError{},LinguaMissingCatalogError=class extends LinguaError{},LinguaMissingKeyError=class extends LinguaError{},LinguaMissingValueError=class extends LinguaError{};exports.LinguaDisposedError=LinguaDisposedError,exports.LinguaError=LinguaError,exports.LinguaInvalidCatalogError=LinguaInvalidCatalogError,exports.LinguaInvalidLocaleError=LinguaInvalidLocaleError,exports.LinguaInvalidPluralCountError=LinguaInvalidPluralCountError,exports.LinguaInvalidStateError=LinguaInvalidStateError,exports.LinguaMissingCatalogError=LinguaMissingCatalogError,exports.LinguaMissingKeyError=LinguaMissingKeyError,exports.LinguaMissingValueError=LinguaMissingValueError;
2
2
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export class LinguaError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed i18n instance.');\n }\n}\n\nexport class LinguaInvalidCatalogError extends LinguaError {}\nexport class LinguaInvalidLocaleError extends LinguaError {}\nexport class LinguaInvalidPluralCountError extends LinguaError {}\nexport class LinguaInvalidStateError extends LinguaError {}\nexport class LinguaMissingCatalogError extends LinguaError {}\nexport class LinguaMissingKeyError extends LinguaError {}\nexport class LinguaMissingValueError extends LinguaError {}\n"],"mappings":"AAAA,IAAa,EAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,EAAb,cAAyC,CAAY,CACnD,aAAc,CACZ,MAAM,+CAA+C,CACvD,CACF,EAEa,EAAb,cAA+C,CAAY,CAAC,EAC/C,EAAb,cAA8C,CAAY,CAAC,EAC9C,EAAb,cAAmD,CAAY,CAAC,EACnD,EAAb,cAA6C,CAAY,CAAC,EAC7C,EAAb,cAA+C,CAAY,CAAC,EAC/C,EAAb,cAA2C,CAAY,CAAC,EAC3C,EAAb,cAA6C,CAAY,CAAC"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export class LinguaError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class LinguaDisposedError extends LinguaError {\n constructor() {\n super('Operation called on a disposed i18n instance.');\n }\n}\n\nexport class LinguaInvalidCatalogError extends LinguaError {}\nexport class LinguaInvalidLocaleError extends LinguaError {}\nexport class LinguaInvalidPluralCountError extends LinguaError {}\nexport class LinguaInvalidStateError extends LinguaError {}\nexport class LinguaMissingCatalogError extends LinguaError {}\nexport class LinguaMissingKeyError extends LinguaError {}\nexport class LinguaMissingValueError extends LinguaError {}\n"],"mappings":"AAAA,IAAa,YAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,oBAAb,cAAyC,WAAY,CACnD,aAAc,CACZ,MAAM,+CAA+C,CACvD,CACF,EAEa,0BAAb,cAA+C,WAAY,CAAC,EAC/C,yBAAb,cAA8C,WAAY,CAAC,EAC9C,8BAAb,cAAmD,WAAY,CAAC,EACnD,wBAAb,cAA6C,WAAY,CAAC,EAC7C,0BAAb,cAA+C,WAAY,CAAC,EAC/C,sBAAb,cAA2C,WAAY,CAAC,EAC3C,wBAAb,cAA6C,WAAY,CAAC"}
package/dist/errors.js CHANGED
@@ -1,14 +1,2 @@
1
- //#region src/errors.ts
2
- var e = class extends Error {
3
- constructor(e, t) {
4
- super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
5
- }
6
- }, t = class extends e {
7
- constructor() {
8
- super("Operation called on a disposed i18n instance.");
9
- }
10
- }, n = class extends e {}, r = class extends e {}, i = class extends e {}, a = class extends e {}, o = class extends e {}, s = class extends e {}, c = class extends e {};
11
- //#endregion
12
- export { t as LinguaDisposedError, e as LinguaError, n as LinguaInvalidCatalogError, r as LinguaInvalidLocaleError, i as LinguaInvalidPluralCountError, a as LinguaInvalidStateError, o as LinguaMissingCatalogError, s as LinguaMissingKeyError, c as LinguaMissingValueError };
13
-
1
+ var LinguaError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},LinguaDisposedError=class extends LinguaError{constructor(){super(`Operation called on a disposed i18n instance.`)}},LinguaInvalidCatalogError=class extends LinguaError{},LinguaInvalidLocaleError=class extends LinguaError{},LinguaInvalidPluralCountError=class extends LinguaError{},LinguaInvalidStateError=class extends LinguaError{},LinguaMissingCatalogError=class extends LinguaError{},LinguaMissingKeyError=class extends LinguaError{},LinguaMissingValueError=class extends LinguaError{};export{LinguaDisposedError,LinguaError,LinguaInvalidCatalogError,LinguaInvalidLocaleError,LinguaInvalidPluralCountError,LinguaInvalidStateError,LinguaMissingCatalogError,LinguaMissingKeyError,LinguaMissingValueError};
14
2
  //# sourceMappingURL=errors.js.map