@internationalized/string 3.2.5 → 3.2.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAQD,MAAM,yCAAmB,IAAI;AAC7B,MAAM,0CAAoB,IAAI;AAMvB,MAAM;IASX,8EAA8E,GAC9E,OAAO,GAAM,EAAE,SAAqB,EAAU;QAC5C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;QAC9D,OAAO,OAAO,YAAY,aAAa,QAAQ,WAAW,IAAI,IAAI;IACpE;IAEU,OAAO,KAAa,EAAE,OAAuC,EAAE,OAA4B,UAAU,
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAQD,MAAM,yCAAmB,IAAI;AAC7B,MAAM,0CAAoB,IAAI;AAMvB,MAAM;IASX,8EAA8E,GAC9E,OAAO,GAAM,EAAE,SAAqB,EAAU;QAC5C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;QAC9D,OAAO,OAAO,YAAY,aAAa,QAAQ,WAAW,IAAI,IAAI;IACpE;IAEU,OAAO,KAAa,EAAE,OAAuC,EAAE,OAA4B,UAAU,EAAU;QACvH,IAAI,MAAM,OAAO,CAAC,MAAM,MAAM;QAC9B,IAAI,KACF,OAAO,OAAO,QAAQ,aAAa,QAAQ;QAG7C,IAAI,MAAM,IAAI,CAAC,MAAM,GAAG,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;QAEA,IAAI,WAAW,YAAY,MAAM,CAAC;QAClC,MAAM,OAAO,CAAC,SAAS,IAAI,QAAQ,KAAK;QACxC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAEU,OAAO,KAAa,EAAU;QACtC,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;QACA,OAAO,aAAa,MAAM,CAAC;IAC7B;IAEU,OAAO,OAAuC,EAAE,KAAa,EAAU;QAC/E,IAAI,MAAM,OAAO,CAAC,MAAM,IAAI,QAAQ,KAAK;QACzC,OAAO,OAAO,QAAQ,aAAa,QAAQ;IAC7C;IAzCA,YAAY,MAAc,EAAE,OAAwC,CAAE;QACpE,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF","sources":["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\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'): string {\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): string {\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): string {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"LocalizedStringFormatter.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GAQD,MAAM,yCAAmB,IAAI;AAC7B,MAAM,0CAAoB,IAAI;AAMvB,MAAM;IASX,8EAA8E,GAC9E,OAAO,GAAM,EAAE,SAAqB,EAAU;QAC5C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,MAAM;QAC9D,OAAO,OAAO,YAAY,aAAa,QAAQ,WAAW,IAAI,IAAI;IACpE;IAEU,OAAO,KAAa,EAAE,OAAuC,EAAE,OAA4B,UAAU,
|
|
1
|
+
{"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E,IAAI,CAAC,MAAM,GAAG;QACd,IAAI,CAAC,OAAO,GAAG;IACjB;AAuCF","sources":["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\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'): string {\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): string {\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): string {\n let opt = options[value] || options.other;\n return typeof opt === 'function' ? opt() : opt;\n }\n}\n"],"names":[],"version":3,"file":"LocalizedStringFormatter.module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAcA,6BAA6B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,eAAe,IAAI;IAC1E,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC7B,CAAC;AAMF;;;GAGG;AACH,uCAAuC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM;gBAItF,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,GAAE,MAAgB;IAS7E,+DAA+D;IAC/D,kBAAkB,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;IAU7C,0DAA0D;IAC1D,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAUjD,MAAM,CAAC,6BAA6B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,0BAA0B,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;CAyBjK;ACxED,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,CAAC;AAC9E,8BAA8B,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE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,CAAC,CAAC,GAAG,IAAI;CAyBjK;ACxED,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,CAAC;AAC9E,8BAA8B,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,yBAAyB,GAAG,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC;AACrH,sBAAsB,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;AAK9C;;;GAGG;AACH,sCAAsC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,eAAe,GAAG,MAAM;gBAIrF,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,0BAA0B,CAAC,EAAE,CAAC,CAAC;IAKpE,gFAAgF;IAChF,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM;IAK7C,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,IAAI,GAAE,KAAK,cAA2B,GAAG,MAAM;IAkBxH,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IASvC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAIjF","sources":["packages/@internationalized/string/src/packages/@internationalized/string/src/LocalizedStringDictionary.ts","packages/@internationalized/string/src/packages/@internationalized/string/src/LocalizedStringFormatter.ts","packages/@internationalized/string/src/packages/@internationalized/string/src/index.ts","packages/@internationalized/string/src/index.ts"],"sourcesContent":[null,null,null,"/*\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"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internationalized/string",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"description": "Internationalized string formatting and locale negotiation",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "9b66d270572f482948afee95622a85cdf68ed408"
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ export class LocalizedStringFormatter<K extends string = string, T extends Local
|
|
|
38
38
|
return typeof message === 'function' ? message(variables, this) : message;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal') {
|
|
41
|
+
protected plural(count: number, options: Record<string, InternalString>, type: Intl.PluralRuleType = 'cardinal'): string {
|
|
42
42
|
let opt = options['=' + count];
|
|
43
43
|
if (opt) {
|
|
44
44
|
return typeof opt === 'function' ? opt() : opt;
|
|
@@ -56,7 +56,7 @@ export class LocalizedStringFormatter<K extends string = string, T extends Local
|
|
|
56
56
|
return typeof opt === 'function' ? opt() : opt;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
protected number(value: number) {
|
|
59
|
+
protected number(value: number): string {
|
|
60
60
|
let numberFormat = numberFormatCache.get(this.locale);
|
|
61
61
|
if (!numberFormat) {
|
|
62
62
|
numberFormat = new Intl.NumberFormat(this.locale);
|
|
@@ -65,7 +65,7 @@ export class LocalizedStringFormatter<K extends string = string, T extends Local
|
|
|
65
65
|
return numberFormat.format(value);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
protected select(options: Record<string, InternalString>, value: string) {
|
|
68
|
+
protected select(options: Record<string, InternalString>, value: string): string {
|
|
69
69
|
let opt = options[value] || options.other;
|
|
70
70
|
return typeof opt === 'function' ? opt() : opt;
|
|
71
71
|
}
|