@formatjs/ecma402-abstract 1.0.3 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/262.d.ts +79 -0
- package/262.d.ts.map +1 -0
- package/262.js +336 -0
- package/_validate_dist-base_options.optionsvalid.d.ts +2 -1
- package/_validate_dist-esm_options.optionsvalid.d.ts +2 -1
- package/index.d.ts +33 -0
- package/index.d.ts.map +1 -1
- package/index.js +52 -11
- package/lib/262.d.ts +79 -0
- package/lib/262.d.ts.map +1 -0
- package/lib/262.js +312 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +33 -0
- package/lib/src/CanonicalizeLocaleList.d.ts +6 -0
- package/lib/src/CanonicalizeLocaleList.d.ts.map +1 -0
- package/lib/src/CanonicalizeLocaleList.js +8 -0
- package/lib/src/CanonicalizeTimeZoneName.d.ts +9 -0
- package/lib/src/CanonicalizeTimeZoneName.d.ts.map +1 -0
- package/lib/src/CanonicalizeTimeZoneName.js +17 -0
- package/lib/src/DateTimeFormat/BasicFormatMatcher.d.ts +8 -0
- package/lib/src/DateTimeFormat/BasicFormatMatcher.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/BasicFormatMatcher.js +61 -0
- package/lib/src/DateTimeFormat/BestFitFormatMatcher.d.ts +17 -0
- package/lib/src/DateTimeFormat/BestFitFormatMatcher.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/BestFitFormatMatcher.js +119 -0
- package/lib/src/DateTimeFormat/DateTimeStyleFormat.d.ts +3 -0
- package/lib/src/DateTimeFormat/DateTimeStyleFormat.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/DateTimeStyleFormat.js +50 -0
- package/lib/src/DateTimeFormat/FormatDateTime.d.ts +8 -0
- package/lib/src/DateTimeFormat/FormatDateTime.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/FormatDateTime.js +15 -0
- package/lib/src/DateTimeFormat/FormatDateTimeToParts.d.ts +10 -0
- package/lib/src/DateTimeFormat/FormatDateTimeToParts.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/FormatDateTimeToParts.js +21 -0
- package/lib/src/DateTimeFormat/InitializeDateTimeFormat.d.ts +18 -0
- package/lib/src/DateTimeFormat/InitializeDateTimeFormat.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/InitializeDateTimeFormat.js +163 -0
- package/lib/src/DateTimeFormat/PartitionDateTimePattern.d.ts +13 -0
- package/lib/src/DateTimeFormat/PartitionDateTimePattern.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/PartitionDateTimePattern.js +176 -0
- package/lib/src/DateTimeFormat/ToDateTimeOptions.d.ts +9 -0
- package/lib/src/DateTimeFormat/ToDateTimeOptions.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/ToDateTimeOptions.js +57 -0
- package/lib/src/DateTimeFormat/ToLocalTime.d.ts +24 -0
- package/lib/src/DateTimeFormat/ToLocalTime.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/ToLocalTime.js +49 -0
- package/lib/src/DateTimeFormat/skeleton.d.ts +9 -0
- package/lib/src/DateTimeFormat/skeleton.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/skeleton.js +163 -0
- package/lib/src/DateTimeFormat/utils.d.ts +10 -0
- package/lib/src/DateTimeFormat/utils.d.ts.map +1 -0
- package/lib/src/DateTimeFormat/utils.js +18 -0
- package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts +2 -0
- package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts.map +1 -0
- package/lib/src/DisplayNames/CanonicalCodeForDisplayNames.js +33 -0
- package/lib/src/GetOption.js +1 -1
- package/lib/src/IsValidTimeZoneName.d.ts +10 -0
- package/lib/src/IsValidTimeZoneName.d.ts.map +1 -0
- package/lib/src/IsValidTimeZoneName.js +11 -0
- package/lib/src/NumberFormat/ComputeExponent.d.ts +12 -0
- package/lib/src/NumberFormat/ComputeExponent.d.ts.map +1 -0
- package/lib/src/NumberFormat/ComputeExponent.js +39 -0
- package/lib/src/NumberFormat/ComputeExponentForMagnitude.d.ts +10 -0
- package/lib/src/NumberFormat/ComputeExponentForMagnitude.d.ts.map +1 -0
- package/lib/src/NumberFormat/ComputeExponentForMagnitude.js +60 -0
- package/lib/src/NumberFormat/CurrencyDigits.d.ts +7 -0
- package/lib/src/NumberFormat/CurrencyDigits.d.ts.map +1 -0
- package/lib/src/NumberFormat/CurrencyDigits.js +10 -0
- package/lib/src/NumberFormat/FormatNumericToParts.d.ts +5 -0
- package/lib/src/NumberFormat/FormatNumericToParts.d.ts.map +1 -0
- package/lib/src/NumberFormat/FormatNumericToParts.js +14 -0
- package/lib/src/NumberFormat/FormatNumericToString.js +1 -1
- package/lib/src/NumberFormat/InitializeNumberFormat.d.ts +13 -0
- package/lib/src/NumberFormat/InitializeNumberFormat.d.ts.map +1 -0
- package/lib/src/NumberFormat/InitializeNumberFormat.js +71 -0
- package/lib/src/NumberFormat/PartitionNumberPattern.d.ts +8 -0
- package/lib/src/NumberFormat/PartitionNumberPattern.d.ts.map +1 -0
- package/lib/src/NumberFormat/PartitionNumberPattern.js +74 -0
- package/lib/src/NumberFormat/SetNumberFormatUnitOptions.d.ts +8 -0
- package/lib/src/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +1 -0
- package/lib/src/NumberFormat/SetNumberFormatUnitOptions.js +39 -0
- package/lib/src/NumberFormat/digit-mapping.json +1 -0
- package/lib/src/NumberFormat/format_to_parts.d.ts +22 -0
- package/lib/src/NumberFormat/format_to_parts.d.ts.map +1 -0
- package/lib/src/NumberFormat/format_to_parts.js +421 -0
- package/lib/src/PluralRules/GetOperands.d.ts +32 -0
- package/lib/src/PluralRules/GetOperands.d.ts.map +1 -0
- package/lib/src/PluralRules/GetOperands.js +47 -0
- package/lib/src/PluralRules/InitializePluralRules.d.ts +9 -0
- package/lib/src/PluralRules/InitializePluralRules.d.ts.map +1 -0
- package/lib/src/PluralRules/InitializePluralRules.js +20 -0
- package/lib/src/PluralRules/ResolvePlural.d.ts +13 -0
- package/lib/src/PluralRules/ResolvePlural.d.ts.map +1 -0
- package/lib/src/PluralRules/ResolvePlural.js +25 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTime.d.ts +5 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTime.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTime.js +10 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts +5 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/FormatRelativeTimeToParts.js +18 -0
- package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts +9 -0
- package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/InitializeRelativeTimeFormat.js +32 -0
- package/lib/src/RelativeTimeFormat/MakePartsList.d.ts +3 -0
- package/lib/src/RelativeTimeFormat/MakePartsList.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/MakePartsList.js +27 -0
- package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts +5 -0
- package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/PartitionRelativeTimePattern.js +54 -0
- package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts +7 -0
- package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts.map +1 -0
- package/lib/src/RelativeTimeFormat/SingularRelativeTimeUnit.js +36 -0
- package/lib/src/SupportedLocales.js +1 -1
- package/lib/src/data.js +1 -1
- package/lib/types/core.js +1 -0
- package/lib/types/date-time.d.ts +112 -0
- package/lib/types/date-time.d.ts.map +1 -0
- package/lib/types/date-time.js +1 -0
- package/lib/types/displaynames.js +1 -0
- package/lib/types/list.js +1 -0
- package/lib/types/number.d.ts +44 -0
- package/lib/types/number.d.ts.map +1 -1
- package/lib/types/number.js +1 -0
- package/lib/types/plural-rules.d.ts +6 -0
- package/lib/types/plural-rules.d.ts.map +1 -1
- package/lib/types/plural-rules.js +1 -0
- package/lib/types/relative-time.d.ts +63 -0
- package/lib/types/relative-time.d.ts.map +1 -1
- package/lib/types/relative-time.js +1 -0
- package/package.json +2 -6
- package/src/CanonicalizeLocaleList.d.ts +6 -0
- package/src/CanonicalizeLocaleList.d.ts.map +1 -0
- package/src/CanonicalizeLocaleList.js +12 -0
- package/src/CanonicalizeTimeZoneName.d.ts +9 -0
- package/src/CanonicalizeTimeZoneName.d.ts.map +1 -0
- package/src/CanonicalizeTimeZoneName.js +21 -0
- package/src/DateTimeFormat/BasicFormatMatcher.d.ts +8 -0
- package/src/DateTimeFormat/BasicFormatMatcher.d.ts.map +1 -0
- package/src/DateTimeFormat/BasicFormatMatcher.js +65 -0
- package/src/DateTimeFormat/BestFitFormatMatcher.d.ts +17 -0
- package/src/DateTimeFormat/BestFitFormatMatcher.d.ts.map +1 -0
- package/src/DateTimeFormat/BestFitFormatMatcher.js +124 -0
- package/src/DateTimeFormat/DateTimeStyleFormat.d.ts +3 -0
- package/src/DateTimeFormat/DateTimeStyleFormat.d.ts.map +1 -0
- package/src/DateTimeFormat/DateTimeStyleFormat.js +54 -0
- package/src/DateTimeFormat/FormatDateTime.d.ts +8 -0
- package/src/DateTimeFormat/FormatDateTime.d.ts.map +1 -0
- package/src/DateTimeFormat/FormatDateTime.js +19 -0
- package/src/DateTimeFormat/FormatDateTimeToParts.d.ts +10 -0
- package/src/DateTimeFormat/FormatDateTimeToParts.d.ts.map +1 -0
- package/src/DateTimeFormat/FormatDateTimeToParts.js +25 -0
- package/src/DateTimeFormat/InitializeDateTimeFormat.d.ts +18 -0
- package/src/DateTimeFormat/InitializeDateTimeFormat.d.ts.map +1 -0
- package/src/DateTimeFormat/InitializeDateTimeFormat.js +167 -0
- package/src/DateTimeFormat/PartitionDateTimePattern.d.ts +13 -0
- package/src/DateTimeFormat/PartitionDateTimePattern.d.ts.map +1 -0
- package/src/DateTimeFormat/PartitionDateTimePattern.js +180 -0
- package/src/DateTimeFormat/ToDateTimeOptions.d.ts +9 -0
- package/src/DateTimeFormat/ToDateTimeOptions.d.ts.map +1 -0
- package/src/DateTimeFormat/ToDateTimeOptions.js +61 -0
- package/src/DateTimeFormat/ToLocalTime.d.ts +24 -0
- package/src/DateTimeFormat/ToLocalTime.d.ts.map +1 -0
- package/src/DateTimeFormat/ToLocalTime.js +53 -0
- package/src/DateTimeFormat/skeleton.d.ts +9 -0
- package/src/DateTimeFormat/skeleton.d.ts.map +1 -0
- package/src/DateTimeFormat/skeleton.js +167 -0
- package/src/DateTimeFormat/utils.d.ts +10 -0
- package/src/DateTimeFormat/utils.d.ts.map +1 -0
- package/src/DateTimeFormat/utils.js +21 -0
- package/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts +2 -0
- package/src/DisplayNames/CanonicalCodeForDisplayNames.d.ts.map +1 -0
- package/src/DisplayNames/CanonicalCodeForDisplayNames.js +37 -0
- package/src/GetOption.js +2 -5
- package/src/IsValidTimeZoneName.d.ts +10 -0
- package/src/IsValidTimeZoneName.d.ts.map +1 -0
- package/src/IsValidTimeZoneName.js +15 -0
- package/src/NumberFormat/ComputeExponent.d.ts +12 -0
- package/src/NumberFormat/ComputeExponent.d.ts.map +1 -0
- package/src/NumberFormat/ComputeExponent.js +43 -0
- package/src/NumberFormat/ComputeExponentForMagnitude.d.ts +10 -0
- package/src/NumberFormat/ComputeExponentForMagnitude.d.ts.map +1 -0
- package/src/NumberFormat/ComputeExponentForMagnitude.js +64 -0
- package/src/NumberFormat/CurrencyDigits.d.ts +7 -0
- package/src/NumberFormat/CurrencyDigits.d.ts.map +1 -0
- package/src/NumberFormat/CurrencyDigits.js +14 -0
- package/src/NumberFormat/FormatNumericToParts.d.ts +5 -0
- package/src/NumberFormat/FormatNumericToParts.d.ts.map +1 -0
- package/src/NumberFormat/FormatNumericToParts.js +18 -0
- package/src/NumberFormat/FormatNumericToString.js +2 -5
- package/src/NumberFormat/InitializeNumberFormat.d.ts +13 -0
- package/src/NumberFormat/InitializeNumberFormat.d.ts.map +1 -0
- package/src/NumberFormat/InitializeNumberFormat.js +75 -0
- package/src/NumberFormat/PartitionNumberPattern.d.ts +8 -0
- package/src/NumberFormat/PartitionNumberPattern.d.ts.map +1 -0
- package/src/NumberFormat/PartitionNumberPattern.js +81 -0
- package/src/NumberFormat/SetNumberFormatUnitOptions.d.ts +8 -0
- package/src/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +1 -0
- package/src/NumberFormat/SetNumberFormatUnitOptions.js +43 -0
- package/src/NumberFormat/digit-mapping.json +1 -0
- package/src/NumberFormat/format_to_parts.d.ts +22 -0
- package/src/NumberFormat/format_to_parts.d.ts.map +1 -0
- package/src/NumberFormat/format_to_parts.js +443 -0
- package/src/PluralRules/GetOperands.d.ts +32 -0
- package/src/PluralRules/GetOperands.d.ts.map +1 -0
- package/src/PluralRules/GetOperands.js +51 -0
- package/src/PluralRules/InitializePluralRules.d.ts +9 -0
- package/src/PluralRules/InitializePluralRules.d.ts.map +1 -0
- package/src/PluralRules/InitializePluralRules.js +24 -0
- package/src/PluralRules/ResolvePlural.d.ts +13 -0
- package/src/PluralRules/ResolvePlural.d.ts.map +1 -0
- package/src/PluralRules/ResolvePlural.js +29 -0
- package/src/RelativeTimeFormat/FormatRelativeTime.d.ts +5 -0
- package/src/RelativeTimeFormat/FormatRelativeTime.d.ts.map +1 -0
- package/src/RelativeTimeFormat/FormatRelativeTime.js +14 -0
- package/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts +5 -0
- package/src/RelativeTimeFormat/FormatRelativeTimeToParts.d.ts.map +1 -0
- package/src/RelativeTimeFormat/FormatRelativeTimeToParts.js +22 -0
- package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts +9 -0
- package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.d.ts.map +1 -0
- package/src/RelativeTimeFormat/InitializeRelativeTimeFormat.js +36 -0
- package/src/RelativeTimeFormat/MakePartsList.d.ts +3 -0
- package/src/RelativeTimeFormat/MakePartsList.d.ts.map +1 -0
- package/src/RelativeTimeFormat/MakePartsList.js +31 -0
- package/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts +5 -0
- package/src/RelativeTimeFormat/PartitionRelativeTimePattern.d.ts.map +1 -0
- package/src/RelativeTimeFormat/PartitionRelativeTimePattern.js +58 -0
- package/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts +7 -0
- package/src/RelativeTimeFormat/SingularRelativeTimeUnit.d.ts.map +1 -0
- package/src/RelativeTimeFormat/SingularRelativeTimeUnit.js +40 -0
- package/src/SupportedLocales.js +2 -5
- package/src/data.js +1 -1
- package/types/date-time.d.ts +112 -0
- package/types/date-time.d.ts.map +1 -0
- package/types/date-time.js +2 -0
- package/types/number.d.ts +44 -0
- package/types/number.d.ts.map +1 -1
- package/types/plural-rules.d.ts +6 -0
- package/types/plural-rules.d.ts.map +1 -1
- package/types/relative-time.d.ts +63 -0
- package/types/relative-time.d.ts.map +1 -1
- package/types.js +1 -1
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { ToRawFixed } from './ToRawFixed';
|
|
2
|
+
import * as digitMapping from './digit-mapping.json';
|
|
3
|
+
// This is from: unicode-12.1.0/General_Category/Symbol/regex.js
|
|
4
|
+
// IE11 does not support unicode flag, otherwise this is just /\p{S}/u.
|
|
5
|
+
var S_UNICODE_REGEX = /[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20BF\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B98-\u2BFF\u2CE5-\u2CEA\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uFB29\uFBB2-\uFBC1\uFDFC\uFDFD\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9B\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDE8\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD10-\uDD6C\uDD70-\uDDAC\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED5\uDEE0-\uDEEC\uDEF0-\uDEFA\uDF00-\uDF73\uDF80-\uDFD8\uDFE0-\uDFEB]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDD00-\uDD0B\uDD0D-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDE53\uDE60-\uDE6D\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95]/;
|
|
6
|
+
// /^\p{S}/u
|
|
7
|
+
var CARET_S_UNICODE_REGEX = new RegExp("^" + S_UNICODE_REGEX.source);
|
|
8
|
+
// /\p{S}$/u
|
|
9
|
+
var S_DOLLAR_UNICODE_REGEX = new RegExp(S_UNICODE_REGEX.source + "$");
|
|
10
|
+
var CLDR_NUMBER_PATTERN = /[#0](?:[\.,][#0]+)*/g;
|
|
11
|
+
export default function formatToParts(numberResult, data, pl, options) {
|
|
12
|
+
var sign = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
|
|
13
|
+
var notation = options.notation, style = options.style, numberingSystem = options.numberingSystem;
|
|
14
|
+
var defaultNumberingSystem = data.numbers.nu[0];
|
|
15
|
+
// #region Part 1: partition and interpolate the CLDR number pattern.
|
|
16
|
+
// ----------------------------------------------------------
|
|
17
|
+
var compactNumberPattern = null;
|
|
18
|
+
if (notation === 'compact' && magnitude) {
|
|
19
|
+
compactNumberPattern = getCompactDisplayPattern(numberResult, pl, data, style, options.compactDisplay, options.currencyDisplay, numberingSystem);
|
|
20
|
+
}
|
|
21
|
+
// This is used multiple times
|
|
22
|
+
var nonNameCurrencyPart;
|
|
23
|
+
if (style === 'currency' && options.currencyDisplay !== 'name') {
|
|
24
|
+
var byCurrencyDisplay = data.currencies[options.currency];
|
|
25
|
+
if (byCurrencyDisplay) {
|
|
26
|
+
switch (options.currencyDisplay) {
|
|
27
|
+
case 'code':
|
|
28
|
+
nonNameCurrencyPart = options.currency;
|
|
29
|
+
break;
|
|
30
|
+
case 'symbol':
|
|
31
|
+
nonNameCurrencyPart = byCurrencyDisplay.symbol;
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
nonNameCurrencyPart = byCurrencyDisplay.narrow;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Fallback for unknown currency
|
|
40
|
+
nonNameCurrencyPart = options.currency;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var numberPattern;
|
|
44
|
+
if (!compactNumberPattern) {
|
|
45
|
+
// Note: if the style is unit, or is currency and the currency display is name,
|
|
46
|
+
// its unit parts will be interpolated in part 2. So here we can fallback to decimal.
|
|
47
|
+
if (style === 'decimal' ||
|
|
48
|
+
style === 'unit' ||
|
|
49
|
+
(style === 'currency' && options.currencyDisplay === 'name')) {
|
|
50
|
+
// Shortcut for decimal
|
|
51
|
+
var decimalData = data.numbers.decimal[numberingSystem] ||
|
|
52
|
+
data.numbers.decimal[defaultNumberingSystem];
|
|
53
|
+
numberPattern = getPatternForSign(decimalData.standard, sign);
|
|
54
|
+
}
|
|
55
|
+
else if (style === 'currency') {
|
|
56
|
+
var currencyData = data.numbers.currency[numberingSystem] ||
|
|
57
|
+
data.numbers.currency[defaultNumberingSystem];
|
|
58
|
+
// We replace number pattern part with `0` for easier postprocessing.
|
|
59
|
+
numberPattern = getPatternForSign(currencyData[options.currencySign], sign);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// percent
|
|
63
|
+
var percentPattern = data.numbers.percent[numberingSystem] ||
|
|
64
|
+
data.numbers.percent[defaultNumberingSystem];
|
|
65
|
+
numberPattern = getPatternForSign(percentPattern, sign);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
numberPattern = compactNumberPattern;
|
|
70
|
+
}
|
|
71
|
+
// Extract the decimal number pattern string. It looks like "#,##0,00", which will later be
|
|
72
|
+
// used to infer decimal group sizes.
|
|
73
|
+
var decimalNumberPattern = CLDR_NUMBER_PATTERN.exec(numberPattern)[0];
|
|
74
|
+
// Now we start to substitute patterns
|
|
75
|
+
// 1. replace strings like `0` and `#,##0.00` with `{0}`
|
|
76
|
+
// 2. unquote characters (invariant: the quoted characters does not contain the special tokens)
|
|
77
|
+
numberPattern = numberPattern
|
|
78
|
+
.replace(CLDR_NUMBER_PATTERN, '{0}')
|
|
79
|
+
.replace(/'(.)'/g, '$1');
|
|
80
|
+
// Handle currency spacing (both compact and non-compact).
|
|
81
|
+
if (style === 'currency' && options.currencyDisplay !== 'name') {
|
|
82
|
+
var currencyData = data.numbers.currency[numberingSystem] ||
|
|
83
|
+
data.numbers.currency[defaultNumberingSystem];
|
|
84
|
+
// See `currencySpacing` substitution rule in TR-35.
|
|
85
|
+
// Here we always assume the currencyMatch is "[:^S:]" and surroundingMatch is "[:digit:]".
|
|
86
|
+
//
|
|
87
|
+
// Example 1: for pattern "#,##0.00¤" with symbol "US$", we replace "¤" with the symbol,
|
|
88
|
+
// but insert an extra non-break space before the symbol, because "[:^S:]" matches "U" in
|
|
89
|
+
// "US$" and "[:digit:]" matches the latn numbering system digits.
|
|
90
|
+
//
|
|
91
|
+
// Example 2: for pattern "¤#,##0.00" with symbol "US$", there is no spacing between symbol
|
|
92
|
+
// and number, because `$` does not match "[:^S:]".
|
|
93
|
+
//
|
|
94
|
+
// Implementation note: here we do the best effort to infer the insertion.
|
|
95
|
+
// We also assume that `beforeInsertBetween` and `afterInsertBetween` will never be `;`.
|
|
96
|
+
var afterCurrency = currencyData.currencySpacing.afterInsertBetween;
|
|
97
|
+
if (afterCurrency && !S_DOLLAR_UNICODE_REGEX.test(nonNameCurrencyPart)) {
|
|
98
|
+
numberPattern = numberPattern.replace('¤{0}', "\u00A4" + afterCurrency + "{0}");
|
|
99
|
+
}
|
|
100
|
+
var beforeCurrency = currencyData.currencySpacing.beforeInsertBetween;
|
|
101
|
+
if (beforeCurrency && !CARET_S_UNICODE_REGEX.test(nonNameCurrencyPart)) {
|
|
102
|
+
numberPattern = numberPattern.replace('{0}¤', "{0}" + beforeCurrency + "\u00A4");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// The following tokens are special: `{0}`, `¤`, `%`, `-`, `+`, `{c:...}.
|
|
106
|
+
var numberPatternParts = numberPattern.split(/({c:[^}]+}|\{0\}|[¤%\-\+])/g);
|
|
107
|
+
var numberParts = [];
|
|
108
|
+
var symbols = data.numbers.symbols[numberingSystem] ||
|
|
109
|
+
data.numbers.symbols[defaultNumberingSystem];
|
|
110
|
+
for (var _i = 0, numberPatternParts_1 = numberPatternParts; _i < numberPatternParts_1.length; _i++) {
|
|
111
|
+
var part = numberPatternParts_1[_i];
|
|
112
|
+
if (!part) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
switch (part) {
|
|
116
|
+
case '{0}': {
|
|
117
|
+
// We only need to handle scientific and engineering notation here.
|
|
118
|
+
numberParts.push.apply(numberParts, paritionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
119
|
+
// If compact number pattern exists, do not insert group separators.
|
|
120
|
+
!compactNumberPattern && options.useGrouping, decimalNumberPattern));
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case '-':
|
|
124
|
+
numberParts.push({ type: 'minusSign', value: symbols.minusSign });
|
|
125
|
+
break;
|
|
126
|
+
case '+':
|
|
127
|
+
numberParts.push({ type: 'plusSign', value: symbols.plusSign });
|
|
128
|
+
break;
|
|
129
|
+
case '%':
|
|
130
|
+
numberParts.push({ type: 'percentSign', value: symbols.percentSign });
|
|
131
|
+
break;
|
|
132
|
+
case '¤':
|
|
133
|
+
// Computed above when handling currency spacing.
|
|
134
|
+
numberParts.push({ type: 'currency', value: nonNameCurrencyPart });
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
if (/^\{c:/.test(part)) {
|
|
138
|
+
numberParts.push({
|
|
139
|
+
type: 'compact',
|
|
140
|
+
value: part.substring(3, part.length - 1),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// literal
|
|
145
|
+
numberParts.push({ type: 'literal', value: part });
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// #endregion
|
|
151
|
+
// #region Part 2: interpolate unit pattern if necessary.
|
|
152
|
+
// ----------------------------------------------
|
|
153
|
+
switch (style) {
|
|
154
|
+
case 'currency': {
|
|
155
|
+
// `currencyDisplay: 'name'` has similar pattern handling as units.
|
|
156
|
+
if (options.currencyDisplay === 'name') {
|
|
157
|
+
var unitPattern = (data.numbers.currency[numberingSystem] ||
|
|
158
|
+
data.numbers.currency[defaultNumberingSystem]).unitPattern;
|
|
159
|
+
// Select plural
|
|
160
|
+
var unitName = void 0;
|
|
161
|
+
var currencyNameData = data.currencies[options.currency];
|
|
162
|
+
if (currencyNameData) {
|
|
163
|
+
unitName = selectPlural(pl, numberResult.roundedNumber * Math.pow(10, exponent), currencyNameData.displayName);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Fallback for unknown currency
|
|
167
|
+
unitName = options.currency;
|
|
168
|
+
}
|
|
169
|
+
// Do {0} and {1} substitution
|
|
170
|
+
var unitPatternParts = unitPattern.split(/(\{[01]\})/g);
|
|
171
|
+
var result = [];
|
|
172
|
+
for (var _a = 0, unitPatternParts_1 = unitPatternParts; _a < unitPatternParts_1.length; _a++) {
|
|
173
|
+
var part = unitPatternParts_1[_a];
|
|
174
|
+
switch (part) {
|
|
175
|
+
case '{0}':
|
|
176
|
+
result.push.apply(result, numberParts);
|
|
177
|
+
break;
|
|
178
|
+
case '{1}':
|
|
179
|
+
result.push({ type: 'currency', value: unitName });
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
if (part) {
|
|
183
|
+
result.push({ type: 'literal', value: part });
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
return numberParts;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
case 'unit': {
|
|
195
|
+
var unit = options.unit, unitDisplay = options.unitDisplay;
|
|
196
|
+
var unitData = data.units.simple[unit];
|
|
197
|
+
var unitPattern = void 0;
|
|
198
|
+
if (unitData) {
|
|
199
|
+
// Simple unit pattern
|
|
200
|
+
unitPattern = selectPlural(pl, numberResult.roundedNumber * Math.pow(10, exponent), data.units.simple[unit][unitDisplay]);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// See: http://unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
|
|
204
|
+
// If cannot find unit in the simple pattern, it must be "per" compound pattern.
|
|
205
|
+
// Implementation note: we are not following TR-35 here because we need to format to parts!
|
|
206
|
+
var _b = unit.split('-per-'), numeratorUnit = _b[0], denominatorUnit = _b[1];
|
|
207
|
+
unitData = data.units.simple[numeratorUnit];
|
|
208
|
+
var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber * Math.pow(10, exponent), data.units.simple[numeratorUnit][unitDisplay]);
|
|
209
|
+
var perUnitPattern = data.units.simple[denominatorUnit].perUnit[unitDisplay];
|
|
210
|
+
if (perUnitPattern) {
|
|
211
|
+
// perUnitPattern exists, combine it with numeratorUnitPattern
|
|
212
|
+
unitPattern = perUnitPattern.replace('{0}', numeratorUnitPattern);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// get compoundUnit pattern (e.g. "{0} per {1}"), repalce {0} with numerator pattern and {1} with
|
|
216
|
+
// the denominator pattern in singular form.
|
|
217
|
+
var perPattern = data.units.compound.per[unitDisplay];
|
|
218
|
+
var denominatorPattern = selectPlural(pl, 1, data.units.simple[denominatorUnit][unitDisplay]);
|
|
219
|
+
unitPattern = unitPattern = perPattern
|
|
220
|
+
.replace('{0}', numeratorUnitPattern)
|
|
221
|
+
.replace('{1}', denominatorPattern.replace('{0}', ''));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
var result = [];
|
|
225
|
+
// We need spacing around "{0}" because they are not treated as "unit" parts, but "literal".
|
|
226
|
+
for (var _c = 0, _d = unitPattern.split(/(\s*\{0\}\s*)/); _c < _d.length; _c++) {
|
|
227
|
+
var part = _d[_c];
|
|
228
|
+
var interpolateMatch = /^(\s*)\{0\}(\s*)$/.exec(part);
|
|
229
|
+
if (interpolateMatch) {
|
|
230
|
+
// Space before "{0}"
|
|
231
|
+
if (interpolateMatch[1]) {
|
|
232
|
+
result.push({ type: 'literal', value: interpolateMatch[1] });
|
|
233
|
+
}
|
|
234
|
+
// "{0}" itself
|
|
235
|
+
result.push.apply(result, numberParts);
|
|
236
|
+
// Space after "{0}"
|
|
237
|
+
if (interpolateMatch[2]) {
|
|
238
|
+
result.push({ type: 'literal', value: interpolateMatch[2] });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (part) {
|
|
242
|
+
result.push({ type: 'unit', value: part });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
default:
|
|
248
|
+
return numberParts;
|
|
249
|
+
}
|
|
250
|
+
// #endregion
|
|
251
|
+
}
|
|
252
|
+
// A subset of https://tc39.es/ecma402/#sec-partitionnotationsubpattern
|
|
253
|
+
// Plus the exponent parts handling.
|
|
254
|
+
function paritionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem, useGrouping,
|
|
255
|
+
/**
|
|
256
|
+
* This is the decimal number pattern without signs or symbols.
|
|
257
|
+
* It is used to infer the group size when `useGrouping` is true.
|
|
258
|
+
*
|
|
259
|
+
* A typical value looks like "#,##0.00" (primary group size is 3).
|
|
260
|
+
* Some locales like Hindi has secondary group size of 2 (e.g. "#,##,##0.00").
|
|
261
|
+
*/
|
|
262
|
+
decimalNumberPattern) {
|
|
263
|
+
var result = [];
|
|
264
|
+
// eslint-disable-next-line prefer-const
|
|
265
|
+
var n = numberResult.formattedString, x = numberResult.roundedNumber;
|
|
266
|
+
if (isNaN(x)) {
|
|
267
|
+
return [{ type: 'nan', value: n }];
|
|
268
|
+
}
|
|
269
|
+
else if (!isFinite(x)) {
|
|
270
|
+
return [{ type: 'infinity', value: n }];
|
|
271
|
+
}
|
|
272
|
+
var digitReplacementTable = digitMapping[numberingSystem];
|
|
273
|
+
if (digitReplacementTable) {
|
|
274
|
+
n = n.replace(/\d/g, function (digit) { return digitReplacementTable[+digit] || digit; });
|
|
275
|
+
}
|
|
276
|
+
// TODO: Else use an implementation dependent algorithm to map n to the appropriate
|
|
277
|
+
// representation of n in the given numbering system.
|
|
278
|
+
var decimalSepIndex = n.indexOf('.');
|
|
279
|
+
var integer;
|
|
280
|
+
var fraction;
|
|
281
|
+
if (decimalSepIndex > 0) {
|
|
282
|
+
integer = n.slice(0, decimalSepIndex);
|
|
283
|
+
fraction = n.slice(decimalSepIndex + 1);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
integer = n;
|
|
287
|
+
}
|
|
288
|
+
// #region Grouping integer digits
|
|
289
|
+
// The weird compact and x >= 10000 check is to ensure consistency with Node.js and Chrome.
|
|
290
|
+
// Note that `de` does not have compact form for thousands, but Node.js does not insert grouping separator
|
|
291
|
+
// unless the rounded number is greater than 10000:
|
|
292
|
+
// NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
|
|
293
|
+
// NumberFormat('de').format(1234) //=> "1.234"
|
|
294
|
+
if (useGrouping && (notation !== 'compact' || x >= 10000)) {
|
|
295
|
+
var groupSepSymbol = symbols.group;
|
|
296
|
+
var groups = [];
|
|
297
|
+
// > There may be two different grouping sizes: The primary grouping size used for the least
|
|
298
|
+
// > significant integer group, and the secondary grouping size used for more significant groups.
|
|
299
|
+
// > If a pattern contains multiple grouping separators, the interval between the last one and the
|
|
300
|
+
// > end of the integer defines the primary grouping size, and the interval between the last two
|
|
301
|
+
// > defines the secondary grouping size. All others are ignored.
|
|
302
|
+
var integerNumberPattern = decimalNumberPattern.split('.')[0];
|
|
303
|
+
var patternGroups = integerNumberPattern.split(',');
|
|
304
|
+
var primaryGroupingSize = 3;
|
|
305
|
+
var secondaryGroupingSize = 3;
|
|
306
|
+
if (patternGroups.length > 1) {
|
|
307
|
+
primaryGroupingSize = patternGroups[patternGroups.length - 1].length;
|
|
308
|
+
}
|
|
309
|
+
if (patternGroups.length > 2) {
|
|
310
|
+
secondaryGroupingSize = patternGroups[patternGroups.length - 2].length;
|
|
311
|
+
}
|
|
312
|
+
var i = integer.length - primaryGroupingSize;
|
|
313
|
+
if (i > 0) {
|
|
314
|
+
// Slice the least significant integer group
|
|
315
|
+
groups.push(integer.slice(i, i + primaryGroupingSize));
|
|
316
|
+
// Then iteratively push the more signicant groups
|
|
317
|
+
// TODO: handle surrogate pairs in some numbering system digits
|
|
318
|
+
for (i -= secondaryGroupingSize; i > 0; i -= secondaryGroupingSize) {
|
|
319
|
+
groups.push(integer.slice(i, i + secondaryGroupingSize));
|
|
320
|
+
}
|
|
321
|
+
groups.push(integer.slice(0, i + secondaryGroupingSize));
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
groups.push(integer);
|
|
325
|
+
}
|
|
326
|
+
while (groups.length > 0) {
|
|
327
|
+
var integerGroup = groups.pop();
|
|
328
|
+
result.push({ type: 'integer', value: integerGroup });
|
|
329
|
+
if (groups.length > 0) {
|
|
330
|
+
result.push({ type: 'group', value: groupSepSymbol });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
result.push({ type: 'integer', value: integer });
|
|
336
|
+
}
|
|
337
|
+
// #endregion
|
|
338
|
+
if (fraction !== undefined) {
|
|
339
|
+
result.push({ type: 'decimal', value: symbols.decimal }, { type: 'fraction', value: fraction });
|
|
340
|
+
}
|
|
341
|
+
if ((notation === 'scientific' || notation === 'engineering') &&
|
|
342
|
+
isFinite(x)) {
|
|
343
|
+
result.push({ type: 'exponentSeparator', value: symbols.exponential });
|
|
344
|
+
if (exponent < 0) {
|
|
345
|
+
result.push({ type: 'exponentMinusSign', value: symbols.minusSign });
|
|
346
|
+
exponent = -exponent;
|
|
347
|
+
}
|
|
348
|
+
var exponentResult = ToRawFixed(exponent, 0, 0);
|
|
349
|
+
result.push({
|
|
350
|
+
type: 'exponentInteger',
|
|
351
|
+
value: exponentResult.formattedString,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
function getPatternForSign(pattern, sign) {
|
|
357
|
+
if (pattern.indexOf(';') < 0) {
|
|
358
|
+
pattern = pattern + ";-" + pattern;
|
|
359
|
+
}
|
|
360
|
+
var _a = pattern.split(';'), zeroPattern = _a[0], negativePattern = _a[1];
|
|
361
|
+
switch (sign) {
|
|
362
|
+
case 0:
|
|
363
|
+
return zeroPattern;
|
|
364
|
+
case -1:
|
|
365
|
+
return negativePattern;
|
|
366
|
+
default:
|
|
367
|
+
return negativePattern.indexOf('-') >= 0
|
|
368
|
+
? negativePattern.replace(/-/g, '+')
|
|
369
|
+
: "+" + zeroPattern;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// Find the CLDR pattern for compact notation based on the magnitude of data and style.
|
|
373
|
+
//
|
|
374
|
+
// Example return value: "¤ {c:laki}000;¤{c:laki} -0" (`sw` locale):
|
|
375
|
+
// - Notice the `{c:...}` token that wraps the compact literal.
|
|
376
|
+
// - The consecutive zeros are normalized to single zero to match CLDR_NUMBER_PATTERN.
|
|
377
|
+
//
|
|
378
|
+
// Returning null means the compact display pattern cannot be found.
|
|
379
|
+
function getCompactDisplayPattern(numberResult, pl, data, style, compactDisplay, currencyDisplay, numberingSystem) {
|
|
380
|
+
var _a;
|
|
381
|
+
var roundedNumber = numberResult.roundedNumber, sign = numberResult.sign, magnitude = numberResult.magnitude;
|
|
382
|
+
var magnitudeKey = String(Math.pow(10, magnitude));
|
|
383
|
+
var defaultNumberingSystem = data.numbers.nu[0];
|
|
384
|
+
var pattern;
|
|
385
|
+
if (style === 'currency' && currencyDisplay !== 'name') {
|
|
386
|
+
var byNumberingSystem = data.numbers.currency;
|
|
387
|
+
var currencyData = byNumberingSystem[numberingSystem] ||
|
|
388
|
+
byNumberingSystem[defaultNumberingSystem];
|
|
389
|
+
// NOTE: compact notation ignores currencySign!
|
|
390
|
+
var compactPluralRules = (_a = currencyData.short) === null || _a === void 0 ? void 0 : _a[magnitudeKey];
|
|
391
|
+
if (!compactPluralRules) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
pattern = selectPlural(pl, roundedNumber, compactPluralRules);
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
var byNumberingSystem = data.numbers.decimal;
|
|
398
|
+
var byCompactDisplay = byNumberingSystem[numberingSystem] ||
|
|
399
|
+
byNumberingSystem[defaultNumberingSystem];
|
|
400
|
+
var compactPlaralRule = byCompactDisplay[compactDisplay][magnitudeKey];
|
|
401
|
+
if (!compactPlaralRule) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
pattern = selectPlural(pl, roundedNumber, compactPlaralRule);
|
|
405
|
+
}
|
|
406
|
+
// See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
|
|
407
|
+
// > If the value is precisely “0”, either explicit or defaulted, then the normal number format
|
|
408
|
+
// > pattern for that sort of object is supplied.
|
|
409
|
+
if (pattern === '0') {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
pattern = getPatternForSign(pattern, sign)
|
|
413
|
+
// Extract compact literal from the pattern
|
|
414
|
+
.replace(/([^\s;\-\+\d¤]+)/g, '{c:$1}')
|
|
415
|
+
// We replace one or more zeros with a single zero so it matches `CLDR_NUMBER_PATTERN`.
|
|
416
|
+
.replace(/0+/, '0');
|
|
417
|
+
return pattern;
|
|
418
|
+
}
|
|
419
|
+
function selectPlural(pl, x, rules) {
|
|
420
|
+
return rules[pl.select(x)] || rules.other;
|
|
421
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface OperandsRecord {
|
|
2
|
+
/**
|
|
3
|
+
* Absolute value of the source number (integer and decimals)
|
|
4
|
+
*/
|
|
5
|
+
Number: number;
|
|
6
|
+
/**
|
|
7
|
+
* Number of digits of `number`
|
|
8
|
+
*/
|
|
9
|
+
IntegerDigits: number;
|
|
10
|
+
/**
|
|
11
|
+
* Number of visible fraction digits in [[Number]], with trailing zeroes.
|
|
12
|
+
*/
|
|
13
|
+
NumberOfFractionDigits: number;
|
|
14
|
+
/**
|
|
15
|
+
* Number of visible fraction digits in [[Number]], without trailing zeroes.
|
|
16
|
+
*/
|
|
17
|
+
NumberOfFractionDigitsWithoutTrailing: number;
|
|
18
|
+
/**
|
|
19
|
+
* Number of visible fractional digits in [[Number]], with trailing zeroes.
|
|
20
|
+
*/
|
|
21
|
+
FractionDigits: number;
|
|
22
|
+
/**
|
|
23
|
+
* Number of visible fractional digits in [[Number]], without trailing zeroes.
|
|
24
|
+
*/
|
|
25
|
+
FractionDigitsWithoutTrailing: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
|
|
29
|
+
* @param s
|
|
30
|
+
*/
|
|
31
|
+
export declare function GetOperands(s: string): OperandsRecord;
|
|
32
|
+
//# sourceMappingURL=GetOperands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetOperands.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/ecma402-abstract/src/PluralRules/GetOperands.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,qCAAqC,EAAE,MAAM,CAAC;IAC9C;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,6BAA6B,EAAE,MAAM,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,cAAc,CAyCrD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { invariant } from '../utils';
|
|
2
|
+
import { ToNumber } from '../../262';
|
|
3
|
+
/**
|
|
4
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
|
|
5
|
+
* @param s
|
|
6
|
+
*/
|
|
7
|
+
export function GetOperands(s) {
|
|
8
|
+
invariant(typeof s === 'string', "GetOperands should have been called with a string");
|
|
9
|
+
var n = ToNumber(s);
|
|
10
|
+
invariant(isFinite(n), 'n should be finite');
|
|
11
|
+
var dp = s.indexOf('.');
|
|
12
|
+
var iv;
|
|
13
|
+
var f;
|
|
14
|
+
var v;
|
|
15
|
+
var fv = '';
|
|
16
|
+
if (dp === -1) {
|
|
17
|
+
iv = n;
|
|
18
|
+
f = 0;
|
|
19
|
+
v = 0;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
iv = s.slice(0, dp);
|
|
23
|
+
fv = s.slice(dp, s.length);
|
|
24
|
+
f = ToNumber(fv);
|
|
25
|
+
v = fv.length;
|
|
26
|
+
}
|
|
27
|
+
var i = Math.abs(ToNumber(iv));
|
|
28
|
+
var w;
|
|
29
|
+
var t;
|
|
30
|
+
if (f !== 0) {
|
|
31
|
+
var ft = fv.replace(/0+$/, '');
|
|
32
|
+
w = ft.length;
|
|
33
|
+
t = ToNumber(ft);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
w = 0;
|
|
37
|
+
t = 0;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
Number: n,
|
|
41
|
+
IntegerDigits: i,
|
|
42
|
+
NumberOfFractionDigits: v,
|
|
43
|
+
NumberOfFractionDigitsWithoutTrailing: w,
|
|
44
|
+
FractionDigits: f,
|
|
45
|
+
FractionDigitsWithoutTrailing: t,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluralRulesInternal, PluralRulesData } from '../../types/plural-rules';
|
|
2
|
+
export declare function InitializePluralRules(pl: Intl.PluralRules, locales: string | string[] | undefined, options: Intl.PluralRulesOptions | undefined, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots, }: {
|
|
3
|
+
availableLocales: string[];
|
|
4
|
+
relevantExtensionKeys: string[];
|
|
5
|
+
localeData: Record<string, PluralRulesData>;
|
|
6
|
+
getDefaultLocale(): string;
|
|
7
|
+
getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
|
|
8
|
+
}): Intl.PluralRules;
|
|
9
|
+
//# sourceMappingURL=InitializePluralRules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitializePluralRules.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/ecma402-abstract/src/PluralRules/InitializePluralRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AAO9E,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,IAAI,CAAC,WAAW,EACpB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACtC,OAAO,EAAE,IAAI,CAAC,kBAAkB,GAAG,SAAS,EAC5C,EACE,gBAAgB,EAChB,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,EAAE;IACD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,gBAAgB,IAAI,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC;CAC7D,oBAkCF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CanonicalizeLocaleList } from '../CanonicalizeLocaleList';
|
|
2
|
+
import { ToObject } from '../../262';
|
|
3
|
+
import { GetOption } from '../GetOption';
|
|
4
|
+
import { SetNumberFormatDigitOptions } from '../NumberFormat/SetNumberFormatDigitOptions';
|
|
5
|
+
import { ResolveLocale } from '../ResolveLocale';
|
|
6
|
+
export function InitializePluralRules(pl, locales, options, _a) {
|
|
7
|
+
var availableLocales = _a.availableLocales, relevantExtensionKeys = _a.relevantExtensionKeys, localeData = _a.localeData, getDefaultLocale = _a.getDefaultLocale, getInternalSlots = _a.getInternalSlots;
|
|
8
|
+
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
9
|
+
var opt = Object.create(null);
|
|
10
|
+
var opts = options === undefined ? Object.create(null) : ToObject(options);
|
|
11
|
+
var internalSlots = getInternalSlots(pl);
|
|
12
|
+
internalSlots.initializedPluralRules = true;
|
|
13
|
+
var matcher = GetOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
|
|
14
|
+
opt.localeMatcher = matcher;
|
|
15
|
+
internalSlots.type = GetOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal');
|
|
16
|
+
SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, 'standard');
|
|
17
|
+
var r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
|
|
18
|
+
internalSlots.locale = r.locale;
|
|
19
|
+
return pl;
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LDMLPluralRule, PluralRulesInternal } from '../../types/plural-rules';
|
|
2
|
+
import { OperandsRecord } from './GetOperands';
|
|
3
|
+
/**
|
|
4
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
|
|
5
|
+
* @param pl
|
|
6
|
+
* @param n
|
|
7
|
+
* @param PluralRuleSelect Has to pass in bc it's implementation-specific
|
|
8
|
+
*/
|
|
9
|
+
export declare function ResolvePlural(pl: Intl.PluralRules, n: number, { getInternalSlots, PluralRuleSelect, }: {
|
|
10
|
+
getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal;
|
|
11
|
+
PluralRuleSelect: (locale: string, type: 'cardinal' | 'ordinal', n: number, operands: OperandsRecord) => LDMLPluralRule;
|
|
12
|
+
}): LDMLPluralRule;
|
|
13
|
+
//# sourceMappingURL=ResolvePlural.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResolvePlural.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/ecma402-abstract/src/PluralRules/ResolvePlural.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAE7E,OAAO,EAAc,cAAc,EAAC,MAAM,eAAe,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,IAAI,CAAC,WAAW,EACpB,CAAC,EAAE,MAAM,EACT,EACE,gBAAgB,EAChB,gBAAgB,GACjB,EAAE;IACD,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC;IAC5D,gBAAgB,EAAE,CAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,cAAc,KACrB,cAAc,CAAC;CACrB,GACA,cAAc,CAgBhB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { invariant } from '../utils';
|
|
2
|
+
import { Type } from '../../262';
|
|
3
|
+
import { FormatNumericToString } from '../NumberFormat/FormatNumericToString';
|
|
4
|
+
import { GetOperands } from './GetOperands';
|
|
5
|
+
/**
|
|
6
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
|
|
7
|
+
* @param pl
|
|
8
|
+
* @param n
|
|
9
|
+
* @param PluralRuleSelect Has to pass in bc it's implementation-specific
|
|
10
|
+
*/
|
|
11
|
+
export function ResolvePlural(pl, n, _a) {
|
|
12
|
+
var getInternalSlots = _a.getInternalSlots, PluralRuleSelect = _a.PluralRuleSelect;
|
|
13
|
+
var internalSlots = getInternalSlots(pl);
|
|
14
|
+
invariant(Type(internalSlots) === 'Object', 'pl has to be an object');
|
|
15
|
+
invariant('initializedPluralRules' in internalSlots, 'pluralrules must be initialized');
|
|
16
|
+
invariant(Type(n) === 'Number', 'n must be a number');
|
|
17
|
+
if (!isFinite(n)) {
|
|
18
|
+
return 'other';
|
|
19
|
+
}
|
|
20
|
+
var locale = internalSlots.locale, type = internalSlots.type;
|
|
21
|
+
var res = FormatNumericToString(internalSlots, n);
|
|
22
|
+
var s = res.formattedString;
|
|
23
|
+
var operands = GetOperands(s);
|
|
24
|
+
return PluralRuleSelect(locale, type, n, operands);
|
|
25
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RelativeTimeFormat, RelativeTimeFormattableUnit, RelativeTimeFormatInternal } from '../../types/relative-time';
|
|
2
|
+
export declare function FormatRelativeTime(rtf: RelativeTimeFormat, value: number, unit: RelativeTimeFormattableUnit, implDetails: {
|
|
3
|
+
getInternalSlots(rtf: RelativeTimeFormat): RelativeTimeFormatInternal;
|
|
4
|
+
}): string;
|
|
5
|
+
//# sourceMappingURL=FormatRelativeTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatRelativeTime.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/ecma402-abstract/src/RelativeTimeFormat/FormatRelativeTime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAGnC,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,kBAAkB,EACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,2BAA2B,EACjC,WAAW,EAAE;IACX,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,0BAA0B,CAAC;CACvE,GACA,MAAM,CAOR"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PartitionRelativeTimePattern } from './PartitionRelativeTimePattern';
|
|
2
|
+
export function FormatRelativeTime(rtf, value, unit, implDetails) {
|
|
3
|
+
var parts = PartitionRelativeTimePattern(rtf, value, unit, implDetails);
|
|
4
|
+
var result = '';
|
|
5
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
6
|
+
var part = parts_1[_i];
|
|
7
|
+
result += part.value;
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RelativeTimeFormat, RelativeTimeFormattableUnit, RelativeTimePart, RelativeTimeFormatInternal } from '../../types/relative-time';
|
|
2
|
+
export declare function FormatRelativeTimeToParts(rtf: RelativeTimeFormat, value: number, unit: RelativeTimeFormattableUnit, implDetails: {
|
|
3
|
+
getInternalSlots(rtf: RelativeTimeFormat): RelativeTimeFormatInternal;
|
|
4
|
+
}): RelativeTimePart[];
|
|
5
|
+
//# sourceMappingURL=FormatRelativeTimeToParts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatRelativeTimeToParts.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/ecma402-abstract/src/RelativeTimeFormat/FormatRelativeTimeToParts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,gBAAgB,EAChB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAInC,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,kBAAkB,EACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,2BAA2B,EACjC,WAAW,EAAE;IACX,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,0BAA0B,CAAC;CACvE,GACA,gBAAgB,EAAE,CAepB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PartitionRelativeTimePattern } from './PartitionRelativeTimePattern';
|
|
2
|
+
import { ArrayCreate } from '../../262';
|
|
3
|
+
export function FormatRelativeTimeToParts(rtf, value, unit, implDetails) {
|
|
4
|
+
var parts = PartitionRelativeTimePattern(rtf, value, unit, implDetails);
|
|
5
|
+
var result = ArrayCreate(0);
|
|
6
|
+
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
7
|
+
var part = parts_1[_i];
|
|
8
|
+
var o = {
|
|
9
|
+
type: part.type,
|
|
10
|
+
value: part.value,
|
|
11
|
+
};
|
|
12
|
+
if ('unit' in part) {
|
|
13
|
+
o.unit = part.unit;
|
|
14
|
+
}
|
|
15
|
+
result.push(o);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RelativeTimeFormat, IntlRelativeTimeFormatOptions, RelativeTimeFormatInternal, LocaleFieldsData } from '../../types/relative-time';
|
|
2
|
+
export declare function InitializeRelativeTimeFormat(rtf: RelativeTimeFormat, locales: string | string[] | undefined, options: IntlRelativeTimeFormatOptions | undefined, { getInternalSlots, availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, }: {
|
|
3
|
+
getInternalSlots(rtf: RelativeTimeFormat): RelativeTimeFormatInternal;
|
|
4
|
+
availableLocales: string[];
|
|
5
|
+
relevantExtensionKeys: string[];
|
|
6
|
+
localeData: Record<string, LocaleFieldsData>;
|
|
7
|
+
getDefaultLocale(): string;
|
|
8
|
+
}): RelativeTimeFormat;
|
|
9
|
+
//# sourceMappingURL=InitializeRelativeTimeFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitializeRelativeTimeFormat.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/ecma402-abstract/src/RelativeTimeFormat/InitializeRelativeTimeFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,0BAA0B,EAC1B,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAQnC,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,kBAAkB,EACvB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACtC,OAAO,EAAE,6BAA6B,GAAG,SAAS,EAClD,EACE,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,UAAU,EACV,gBAAgB,GACjB,EAAE;IACD,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,0BAA0B,CAAC;IACtE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC7C,gBAAgB,IAAI,MAAM,CAAC;CAC5B,sBAyDF"}
|