@internationalized/string 3.0.1-nightly.3598 → 3.0.1-nightly.3600

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -4,7 +4,27 @@ function $parcel$export(e, n, v, s) {
4
4
 
5
5
  $parcel$export(module.exports, "LocalizedStringDictionary", () => $f80be5fd4d03dda9$export$c17fa47878dc55b6);
6
6
  $parcel$export(module.exports, "LocalizedStringFormatter", () => $3e95fbf3429967d1$export$2f817fcdc4b89ae0);
7
- class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
7
+ /*
8
+ * Copyright 2022 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ /*
18
+ * Copyright 2022 Adobe. All rights reserved.
19
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
20
+ * you may not use this file except in compliance with the License. You may obtain a copy
21
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software distributed under
24
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
25
+ * OF ANY KIND, either express or implied. See the License for the specific language
26
+ * governing permissions and limitations under the License.
27
+ */ class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
8
28
  /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
9
29
  let strings = this.strings[locale];
10
30
  if (!strings) {
@@ -15,7 +35,7 @@ class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
15
35
  if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
16
36
  return string;
17
37
  }
18
- constructor(messages, defaultLocale = 'en-US'){
38
+ constructor(messages, defaultLocale = "en-US"){
19
39
  // Clone messages so we don't modify the original object.
20
40
  this.strings = {
21
41
  ...messages
@@ -23,7 +43,7 @@ class $f80be5fd4d03dda9$export$c17fa47878dc55b6 {
23
43
  this.defaultLocale = defaultLocale;
24
44
  }
25
45
  }
26
- function $f80be5fd4d03dda9$var$getStringsForLocale(locale, strings, defaultLocale = 'en-US') {
46
+ function $f80be5fd4d03dda9$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
27
47
  // If there is an exact match, use it.
28
48
  if (strings[locale]) return strings[locale];
29
49
  // Attempt to find the closest match by language.
@@ -34,7 +54,7 @@ function $f80be5fd4d03dda9$var$getStringsForLocale(locale, strings, defaultLocal
34
54
  let language = $f80be5fd4d03dda9$var$getLanguage(locale);
35
55
  if (strings[language]) return strings[language];
36
56
  for(let key in strings){
37
- if (key.startsWith(language + '-')) return strings[key];
57
+ if (key.startsWith(language + "-")) return strings[key];
38
58
  }
39
59
  // Nothing close, use english.
40
60
  return strings[defaultLocale];
@@ -43,21 +63,31 @@ function $f80be5fd4d03dda9$var$getLanguage(locale) {
43
63
  // @ts-ignore
44
64
  if (Intl.Locale) // @ts-ignore
45
65
  return new Intl.Locale(locale).language;
46
- return locale.split('-')[0];
66
+ return locale.split("-")[0];
47
67
  }
48
68
 
49
69
 
50
- const $3e95fbf3429967d1$var$pluralRulesCache = new Map();
70
+ /*
71
+ * Copyright 2022 Adobe. All rights reserved.
72
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
73
+ * you may not use this file except in compliance with the License. You may obtain a copy
74
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
75
+ *
76
+ * Unless required by applicable law or agreed to in writing, software distributed under
77
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
78
+ * OF ANY KIND, either express or implied. See the License for the specific language
79
+ * governing permissions and limitations under the License.
80
+ */ const $3e95fbf3429967d1$var$pluralRulesCache = new Map();
51
81
  const $3e95fbf3429967d1$var$numberFormatCache = new Map();
52
82
  class $3e95fbf3429967d1$export$2f817fcdc4b89ae0 {
53
83
  /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
54
84
  let message = this.strings.getStringForLocale(key, this.locale);
55
- return typeof message === 'function' ? message(variables, this) : message;
85
+ return typeof message === "function" ? message(variables, this) : message;
56
86
  }
57
- plural(count, options, type = 'cardinal') {
58
- let opt = options['=' + count];
59
- if (opt) return typeof opt === 'function' ? opt() : opt;
60
- let key = this.locale + ':' + type;
87
+ plural(count, options, type = "cardinal") {
88
+ let opt = options["=" + count];
89
+ if (opt) return typeof opt === "function" ? opt() : opt;
90
+ let key = this.locale + ":" + type;
61
91
  let pluralRules = $3e95fbf3429967d1$var$pluralRulesCache.get(key);
62
92
  if (!pluralRules) {
63
93
  pluralRules = new Intl.PluralRules(this.locale, {
@@ -67,7 +97,7 @@ class $3e95fbf3429967d1$export$2f817fcdc4b89ae0 {
67
97
  }
68
98
  let selected = pluralRules.select(count);
69
99
  opt = options[selected] || options.other;
70
- return typeof opt === 'function' ? opt() : opt;
100
+ return typeof opt === "function" ? opt() : opt;
71
101
  }
72
102
  number(value) {
73
103
  let numberFormat = $3e95fbf3429967d1$var$numberFormatCache.get(this.locale);
@@ -79,7 +109,7 @@ class $3e95fbf3429967d1$export$2f817fcdc4b89ae0 {
79
109
  }
80
110
  select(options, value) {
81
111
  let opt = options[value] || options.other;
82
- return typeof opt === 'function' ? opt() : opt;
112
+ return typeof opt === "function" ? opt() : opt;
83
113
  }
84
114
  constructor(locale, strings){
85
115
  this.locale = locale;
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;MCsBa,yCAAyB;IAUpC,EAA+D,AAA/D,2DAA+D,AAA/D,EAA+D,CAC/D,kBAAkB,CAAC,GAAM,EAAE,MAAc,EAAK,CAAC;QAC7C,GAAG,CAAC,OAAO,GAAG,IAAI,C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C,MAAM,EAAE,CAAC;sBAAA,IAAI;YAAA,CAAC;YACtD,sCAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW;QACvC,CAAC;QAED,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK;QACvC,GAAG,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,KAAK;QACxC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAU,YAAG,GAAG,KAAK,GAAG;IAChD,CAAC;IAES,MAAM,CAAC,KAAa,EAAE,CAAC;QAC/B,GAAG,CAAC,YAAY,GAAG,uCAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM;QACpD,EAAE,GAAG,YAAY,EAAE,CAAC;YAClB,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM;YAChD,uCAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY;QACjD,CAAC;QACD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK;IAClC,CAAC;IAES,MAAM,CAAC,OAAuC,EAAE,KAAa,EAAE,CAAC;QACxE,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK;QACzC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAU,YAAG,GAAG,KAAK,GAAG;IAChD,CAAC;gBAzCW,MAAc,EAAE,OAAwC,CAAE,CAAC;QACrE,IAAI,CAAC,MAAM,GAAG,MAAM;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO;IACxB,CAAC;;;","sources":["packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n this.strings = {...messages};\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,AAUO,MAAM;IAUX,6DAA6D,GAC7D,mBAAmB,GAAM,EAAE,MAAc,EAAK;QAC5C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO;QAClC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa;YACtE,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG;QACzB,CAAC;QAED,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC,EAAE;QAG5E,OAAO;IACT;IApBA,YAAY,QAAgC,EAAE,gBAAwB,OAAO,CAAE;QAC7E,yDAAyD;QACzD,IAAI,CAAC,OAAO,GAAG;YAAC,GAAG,QAAQ;QAAA;QAC3B,IAAI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AC;QACvC,IAAI,CAAC,aAAa;YAChB,cAAc,IAAI,KAAK,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;sBAAC;YAAI;YACrD,uCAAiB,GAAG,CAAC,KAAK;QAC5B,CAAC;QAED,IAAI,WAAW,YAAY,MAAM,CAAC;QAClC,MAAM,OAAO,CAAC,SAAS,IAAI,QAAQ,KAAK;QACxC,OAAO,OAAO,QAAQ,aAAa,QAAQ,GAAG;IAChD;IAEU,OAAO,KAAa,EAAE;QAC9B,IAAI,eAAe,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM;QACpD,IAAI,CAAC,cAAc;YACjB,eAAe,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC,MAAM;YAChD,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE;QACrC,CAAC;QACD,OAAO,aAAa,MAAM,CAAC;IAC7B;IAEU,OAAO,OAAuC,EAAE,KAAa,EAAE;QACvE,IAAI,MAAM,OAAO,CAAC,MAAM,IAAI,QAAQ,KAAK;QACzC,OAAO,OAAO,QAAQ,aAAa,QAAQ,GAAG;IAChD;IAzCA,YAAY,MAAc,EAAE,OAAwC,CAAE;QACpE,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF;","sources":["packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n this.strings = {...messages};\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.mjs CHANGED
@@ -1,4 +1,24 @@
1
- class $5b160d28a433310d$export$c17fa47878dc55b6 {
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ /*
12
+ * Copyright 2022 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */ class $5b160d28a433310d$export$c17fa47878dc55b6 {
2
22
  /** Returns a localized string for the given key and locale. */ getStringForLocale(key, locale) {
3
23
  let strings = this.strings[locale];
4
24
  if (!strings) {
@@ -9,7 +29,7 @@ class $5b160d28a433310d$export$c17fa47878dc55b6 {
9
29
  if (!string) throw new Error(`Could not find intl message ${key} in ${locale} locale`);
10
30
  return string;
11
31
  }
12
- constructor(messages, defaultLocale = 'en-US'){
32
+ constructor(messages, defaultLocale = "en-US"){
13
33
  // Clone messages so we don't modify the original object.
14
34
  this.strings = {
15
35
  ...messages
@@ -17,7 +37,7 @@ class $5b160d28a433310d$export$c17fa47878dc55b6 {
17
37
  this.defaultLocale = defaultLocale;
18
38
  }
19
39
  }
20
- function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocale = 'en-US') {
40
+ function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocale = "en-US") {
21
41
  // If there is an exact match, use it.
22
42
  if (strings[locale]) return strings[locale];
23
43
  // Attempt to find the closest match by language.
@@ -28,7 +48,7 @@ function $5b160d28a433310d$var$getStringsForLocale(locale, strings, defaultLocal
28
48
  let language = $5b160d28a433310d$var$getLanguage(locale);
29
49
  if (strings[language]) return strings[language];
30
50
  for(let key in strings){
31
- if (key.startsWith(language + '-')) return strings[key];
51
+ if (key.startsWith(language + "-")) return strings[key];
32
52
  }
33
53
  // Nothing close, use english.
34
54
  return strings[defaultLocale];
@@ -37,21 +57,31 @@ function $5b160d28a433310d$var$getLanguage(locale) {
37
57
  // @ts-ignore
38
58
  if (Intl.Locale) // @ts-ignore
39
59
  return new Intl.Locale(locale).language;
40
- return locale.split('-')[0];
60
+ return locale.split("-")[0];
41
61
  }
42
62
 
43
63
 
44
- const $6db58dc88e78b024$var$pluralRulesCache = new Map();
64
+ /*
65
+ * Copyright 2022 Adobe. All rights reserved.
66
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
67
+ * you may not use this file except in compliance with the License. You may obtain a copy
68
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
69
+ *
70
+ * Unless required by applicable law or agreed to in writing, software distributed under
71
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
72
+ * OF ANY KIND, either express or implied. See the License for the specific language
73
+ * governing permissions and limitations under the License.
74
+ */ const $6db58dc88e78b024$var$pluralRulesCache = new Map();
45
75
  const $6db58dc88e78b024$var$numberFormatCache = new Map();
46
76
  class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
47
77
  /** Formats a localized string for the given key with the provided variables. */ format(key, variables) {
48
78
  let message = this.strings.getStringForLocale(key, this.locale);
49
- return typeof message === 'function' ? message(variables, this) : message;
79
+ return typeof message === "function" ? message(variables, this) : message;
50
80
  }
51
- plural(count, options, type = 'cardinal') {
52
- let opt = options['=' + count];
53
- if (opt) return typeof opt === 'function' ? opt() : opt;
54
- let key = this.locale + ':' + type;
81
+ plural(count, options, type = "cardinal") {
82
+ let opt = options["=" + count];
83
+ if (opt) return typeof opt === "function" ? opt() : opt;
84
+ let key = this.locale + ":" + type;
55
85
  let pluralRules = $6db58dc88e78b024$var$pluralRulesCache.get(key);
56
86
  if (!pluralRules) {
57
87
  pluralRules = new Intl.PluralRules(this.locale, {
@@ -61,7 +91,7 @@ class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
61
91
  }
62
92
  let selected = pluralRules.select(count);
63
93
  opt = options[selected] || options.other;
64
- return typeof opt === 'function' ? opt() : opt;
94
+ return typeof opt === "function" ? opt() : opt;
65
95
  }
66
96
  number(value) {
67
97
  let numberFormat = $6db58dc88e78b024$var$numberFormatCache.get(this.locale);
@@ -73,7 +103,7 @@ class $6db58dc88e78b024$export$2f817fcdc4b89ae0 {
73
103
  }
74
104
  select(options, value) {
75
105
  let opt = options[value] || options.other;
76
- return typeof opt === 'function' ? opt() : opt;
106
+ return typeof opt === "function" ? opt() : opt;
77
107
  }
78
108
  constructor(locale, strings){
79
109
  this.locale = locale;
@@ -1 +1 @@
1
- {"mappings":"MCsBa,yCAAyB;IAUpC,EAA+D,AAA/D,2DAA+D,AAA/D,EAA+D,CAC/D,kBAAkB,CAAC,GAAM,EAAE,MAAc,EA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G,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;sBAAA,IAAI;YAAA,CAAC;YACtD,sCAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW;QACvC,CAAC;QAED,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK;QACvC,GAAG,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,KAAK;QACxC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAU,YAAG,GAAG,KAAK,GAAG;IAChD,CAAC;IAES,MAAM,CAAC,KAAa,EAAE,CAAC;QAC/B,GAAG,CAAC,YAAY,GAAG,uCAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM;QACpD,EAAE,GAAG,YAAY,EAAE,CAAC;YAClB,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM;YAChD,uCAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY;QACjD,CAAC;QACD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK;IAClC,CAAC;IAES,MAAM,CAAC,OAAuC,EAAE,KAAa,EAAE,CAAC;QACxE,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK;QACzC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAU,YAAG,GAAG,KAAK,GAAG;IAChD,CAAC;gBAzCW,MAAc,EAAE,OAAwC,CAAE,CAAC;QACrE,IAAI,CAAC,MAAM,GAAG,MAAM;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO;IACxB,CAAC;;;","sources":["packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n this.strings = {...messages};\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,AAUO,MAAM;IAUX,6DAA6D,GAC7D,mBAAmB,GAAM,EAAE,MAAc,EAAK;QAC5C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO;QAClC,IAAI,CAAC,SAAS;YACZ,UAAU,0CAAoB,QAAQ,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa;YACtE,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG;QACzB,CAAC;QAED,IAAI,SAAS,OAAO,CAAC,IAAI;QACzB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE,IAAI,IAAI,EAAE,OAAO,OAAO,CAAC,EAAE;QAG5E,OAAO;IACT;IApBA,YAAY,QAAgC,EAAE,gBAAwB,OAAO,CAAE;QAC7E,yDAAyD;QACzD,IAAI,CAAC,OAAO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G,MAAM;QAC9B,IAAI,cAAc,uCAAiB,GAAG,CAAC;QACvC,IAAI,CAAC,aAAa;YAChB,cAAc,IAAI,KAAK,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE;sBAAC;YAAI;YACrD,uCAAiB,GAAG,CAAC,KAAK;QAC5B,CAAC;QAED,IAAI,WAAW,YAAY,MAAM,CAAC;QAClC,MAAM,OAAO,CAAC,SAAS,IAAI,QAAQ,KAAK;QACxC,OAAO,OAAO,QAAQ,aAAa,QAAQ,GAAG;IAChD;IAEU,OAAO,KAAa,EAAE;QAC9B,IAAI,eAAe,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM;QACpD,IAAI,CAAC,cAAc;YACjB,eAAe,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC,MAAM;YAChD,wCAAkB,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE;QACrC,CAAC;QACD,OAAO,aAAa,MAAM,CAAC;IAC7B;IAEU,OAAO,OAAuC,EAAE,KAAa,EAAE;QACvE,IAAI,MAAM,OAAO,CAAC,MAAM,IAAI,QAAQ,KAAK;QACzC,OAAO,OAAO,QAAQ,aAAa,QAAQ,GAAG;IAChD;IAzCA,YAAY,MAAc,EAAE,OAAwC,CAAE;QACpE,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF;","sources":["packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/LocalizedStringFormatter.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {Variables, LocalizedString} from './LocalizedStringFormatter';\nexport type {LocalizedStrings} from './LocalizedStringDictionary';\nexport {LocalizedStringDictionary} from './LocalizedStringDictionary';\nexport {LocalizedStringFormatter} from './LocalizedStringFormatter';\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedString} from './LocalizedStringFormatter';\n\nexport type LocalizedStrings<K extends string, T extends LocalizedString> = {\n [lang: string]: Record<K, T>\n};\n\n/**\n * Stores a mapping of localized strings. Can be used to find the\n * closest available string for a given locale.\n */\nexport class LocalizedStringDictionary<K extends string = string, T extends LocalizedString = string> {\n private strings: LocalizedStrings<K, T>;\n private defaultLocale: string;\n\n constructor(messages: LocalizedStrings<K, T>, defaultLocale: string = 'en-US') {\n // Clone messages so we don't modify the original object.\n this.strings = {...messages};\n this.defaultLocale = defaultLocale;\n }\n\n /** Returns a localized string for the given key and locale. */\n getStringForLocale(key: K, locale: string): T {\n let strings = this.strings[locale];\n if (!strings) {\n strings = getStringsForLocale(locale, this.strings, this.defaultLocale);\n this.strings[locale] = strings;\n }\n\n let string = strings[key];\n if (!string) {\n throw new Error(`Could not find intl message ${key} in ${locale} locale`);\n }\n\n return string;\n }\n}\n\nfunction getStringsForLocale<K extends string, T extends LocalizedString>(locale: string, strings: LocalizedStrings<K, T>, defaultLocale = 'en-US') {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n // This could be replaced with Intl.LocaleMatcher once it is supported.\n // https://github.com/tc39/proposal-intl-localematcher\n let language = getLanguage(locale);\n if (strings[language]) {\n return strings[language];\n }\n\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings[defaultLocale];\n}\n\nfunction getLanguage(locale: string) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\n}\n","/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {LocalizedStringDictionary} from './LocalizedStringDictionary';\n\nexport type Variables = Record<string, string | number | boolean> | undefined;\nexport type LocalizedString = string | ((args: Variables, formatter?: LocalizedStringFormatter<any, any>) => string);\ntype InternalString = string | (() => string);\n\nconst pluralRulesCache = new Map<string, Intl.PluralRules>();\nconst numberFormatCache = new Map<string, Intl.NumberFormat>();\n\n/**\n * Formats localized strings from a LocalizedStringDictionary. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers for the locale.\n */\nexport class LocalizedStringFormatter<K extends string = string, T extends LocalizedString = string> {\n private locale: string;\n private strings: LocalizedStringDictionary<K, T>;\n\n constructor(locale: string, strings: LocalizedStringDictionary<K, T>) {\n this.locale = locale;\n this.strings = strings;\n }\n\n /** Formats a localized string for the given key with the provided variables. */\n format(key: K, variables?: Variables): string {\n let message = this.strings.getStringForLocale(key, this.locale);\n return typeof message === 'function' ? message(variables, this) : message;\n }\n\n protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {\n let opt = options['=' + count];\n if (opt) {\n return typeof opt === 'function' ? opt() : opt;\n }\n\n let key = this.locale + ':' + type;\n let pluralRules = pluralRulesCache.get(key);\n if (!pluralRules) {\n pluralRules = new Intl.PluralRules(this.locale, {type});\n pluralRulesCache.set(key, pluralRules);\n }\n\n let selected = pluralRules.select(count);\n opt = options[selected] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n\n protected number(value: number) {\n let numberFormat = numberFormatCache.get(this.locale);\n if (!numberFormat) {\n numberFormat = new Intl.NumberFormat(this.locale);\n numberFormatCache.set(this.locale, numberFormat);\n }\n return numberFormat.format(value);\n }\n\n protected select(options: Record<string, InternalString>, value: string) {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internationalized/string",
3
- "version": "3.0.1-nightly.3598+810579b67",
3
+ "version": "3.0.1-nightly.3600+bfce84fee",
4
4
  "description": "Internationalized string formatting and locale negotiation",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,10 +22,10 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@babel/runtime": "^7.6.2"
25
+ "@swc/helpers": "^0.4.14"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "810579b671791f1593108f62cdc1893de3a220e3"
30
+ "gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169"
31
31
  }