@formatjs/ecma402-abstract 2.3.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/262.d.ts +1 -1
  2. package/262.js +42 -68
  3. package/CanonicalizeLocaleList.js +1 -4
  4. package/CanonicalizeTimeZoneName.js +1 -4
  5. package/CoerceOptionsToObject.js +3 -6
  6. package/DefaultNumberOption.js +1 -4
  7. package/GetNumberOption.js +3 -6
  8. package/GetOption.js +3 -6
  9. package/GetOptionsObject.js +1 -4
  10. package/GetStringOrBooleanOption.js +3 -6
  11. package/IsSanctionedSimpleUnitIdentifier.js +5 -10
  12. package/IsValidTimeZoneName.js +1 -4
  13. package/IsWellFormedCurrencyCode.js +1 -4
  14. package/IsWellFormedUnitIdentifier.js +5 -8
  15. package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
  16. package/NumberFormat/ApplyUnsignedRoundingMode.js +5 -8
  17. package/NumberFormat/CollapseNumberRange.d.ts +1 -1
  18. package/NumberFormat/CollapseNumberRange.js +1 -4
  19. package/NumberFormat/ComputeExponent.d.ts +2 -2
  20. package/NumberFormat/ComputeExponent.js +8 -12
  21. package/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -2
  22. package/NumberFormat/ComputeExponentForMagnitude.js +6 -10
  23. package/NumberFormat/CurrencyDigits.js +3 -6
  24. package/NumberFormat/FormatApproximately.d.ts +1 -1
  25. package/NumberFormat/FormatApproximately.js +1 -4
  26. package/NumberFormat/FormatNumeric.d.ts +2 -2
  27. package/NumberFormat/FormatNumeric.js +3 -6
  28. package/NumberFormat/FormatNumericRange.d.ts +2 -2
  29. package/NumberFormat/FormatNumericRange.js +3 -6
  30. package/NumberFormat/FormatNumericRangeToParts.d.ts +2 -2
  31. package/NumberFormat/FormatNumericRangeToParts.js +3 -6
  32. package/NumberFormat/FormatNumericToParts.d.ts +2 -2
  33. package/NumberFormat/FormatNumericToParts.js +5 -8
  34. package/NumberFormat/FormatNumericToString.d.ts +2 -2
  35. package/NumberFormat/FormatNumericToString.js +16 -19
  36. package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
  37. package/NumberFormat/GetUnsignedRoundingMode.js +1 -4
  38. package/NumberFormat/InitializeNumberFormat.d.ts +1 -1
  39. package/NumberFormat/InitializeNumberFormat.js +23 -26
  40. package/NumberFormat/PartitionNumberPattern.d.ts +2 -2
  41. package/NumberFormat/PartitionNumberPattern.js +12 -16
  42. package/NumberFormat/PartitionNumberRangePattern.d.ts +2 -2
  43. package/NumberFormat/PartitionNumberRangePattern.js +12 -15
  44. package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  45. package/NumberFormat/SetNumberFormatDigitOptions.js +18 -21
  46. package/NumberFormat/SetNumberFormatUnitOptions.d.ts +1 -1
  47. package/NumberFormat/SetNumberFormatUnitOptions.js +15 -18
  48. package/NumberFormat/ToRawFixed.d.ts +2 -2
  49. package/NumberFormat/ToRawFixed.js +10 -14
  50. package/NumberFormat/ToRawPrecision.d.ts +2 -2
  51. package/NumberFormat/ToRawPrecision.js +19 -23
  52. package/NumberFormat/digit-mapping.generated.js +1 -4
  53. package/NumberFormat/format_to_parts.d.ts +2 -2
  54. package/NumberFormat/format_to_parts.js +18 -22
  55. package/PartitionPattern.js +3 -6
  56. package/SupportedLocales.js +8 -11
  57. package/ToIntlMathematicalValue.d.ts +1 -1
  58. package/ToIntlMathematicalValue.js +12 -16
  59. package/constants.d.ts +1 -1
  60. package/constants.js +4 -8
  61. package/data.js +3 -6
  62. package/index.d.ts +47 -47
  63. package/index.js +45 -66
  64. package/package.json +13 -11
  65. package/regex.generated.js +1 -4
  66. package/types/core.js +1 -2
  67. package/types/date-time.js +2 -5
  68. package/types/displaynames.d.ts +1 -1
  69. package/types/displaynames.js +1 -2
  70. package/types/list.d.ts +1 -1
  71. package/types/list.js +1 -2
  72. package/types/number.d.ts +3 -3
  73. package/types/number.js +1 -2
  74. package/types/plural-rules.d.ts +2 -2
  75. package/types/plural-rules.js +1 -2
  76. package/types/relative-time.d.ts +2 -2
  77. package/types/relative-time.js +1 -2
  78. package/utils.js +28 -40
  79. package/lib/262.d.ts +0 -93
  80. package/lib/262.js +0 -400
  81. package/lib/CanonicalizeLocaleList.d.ts +0 -5
  82. package/lib/CanonicalizeLocaleList.js +0 -8
  83. package/lib/CanonicalizeTimeZoneName.d.ts +0 -8
  84. package/lib/CanonicalizeTimeZoneName.js +0 -17
  85. package/lib/CoerceOptionsToObject.d.ts +0 -6
  86. package/lib/CoerceOptionsToObject.js +0 -12
  87. package/lib/DefaultNumberOption.d.ts +0 -8
  88. package/lib/DefaultNumberOption.js +0 -18
  89. package/lib/GetNumberOption.d.ts +0 -9
  90. package/lib/GetNumberOption.js +0 -13
  91. package/lib/GetOption.d.ts +0 -9
  92. package/lib/GetOption.js +0 -31
  93. package/lib/GetOptionsObject.d.ts +0 -6
  94. package/lib/GetOptionsObject.js +0 -14
  95. package/lib/GetStringOrBooleanOption.d.ts +0 -10
  96. package/lib/GetStringOrBooleanOption.js +0 -31
  97. package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +0 -13
  98. package/lib/IsSanctionedSimpleUnitIdentifier.js +0 -63
  99. package/lib/IsValidTimeZoneName.d.ts +0 -9
  100. package/lib/IsValidTimeZoneName.js +0 -17
  101. package/lib/IsWellFormedCurrencyCode.d.ts +0 -4
  102. package/lib/IsWellFormedCurrencyCode.js +0 -21
  103. package/lib/IsWellFormedUnitIdentifier.d.ts +0 -5
  104. package/lib/IsWellFormedUnitIdentifier.js +0 -28
  105. package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts +0 -3
  106. package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +0 -33
  107. package/lib/NumberFormat/CollapseNumberRange.d.ts +0 -8
  108. package/lib/NumberFormat/CollapseNumberRange.js +0 -50
  109. package/lib/NumberFormat/ComputeExponent.d.ts +0 -10
  110. package/lib/NumberFormat/ComputeExponent.js +0 -34
  111. package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -8
  112. package/lib/NumberFormat/ComputeExponentForMagnitude.js +0 -65
  113. package/lib/NumberFormat/CurrencyDigits.d.ts +0 -6
  114. package/lib/NumberFormat/CurrencyDigits.js +0 -10
  115. package/lib/NumberFormat/FormatApproximately.d.ts +0 -5
  116. package/lib/NumberFormat/FormatApproximately.js +0 -9
  117. package/lib/NumberFormat/FormatNumeric.d.ts +0 -3
  118. package/lib/NumberFormat/FormatNumeric.js +0 -5
  119. package/lib/NumberFormat/FormatNumericRange.d.ts +0 -8
  120. package/lib/NumberFormat/FormatNumericRange.js +0 -11
  121. package/lib/NumberFormat/FormatNumericRangeToParts.d.ts +0 -8
  122. package/lib/NumberFormat/FormatNumericRangeToParts.js +0 -16
  123. package/lib/NumberFormat/FormatNumericToParts.d.ts +0 -5
  124. package/lib/NumberFormat/FormatNumericToParts.js +0 -14
  125. package/lib/NumberFormat/FormatNumericToString.d.ts +0 -9
  126. package/lib/NumberFormat/FormatNumericToString.js +0 -84
  127. package/lib/NumberFormat/GetUnsignedRoundingMode.d.ts +0 -2
  128. package/lib/NumberFormat/GetUnsignedRoundingMode.js +0 -28
  129. package/lib/NumberFormat/InitializeNumberFormat.d.ts +0 -12
  130. package/lib/NumberFormat/InitializeNumberFormat.js +0 -66
  131. package/lib/NumberFormat/PartitionNumberPattern.d.ts +0 -6
  132. package/lib/NumberFormat/PartitionNumberPattern.js +0 -126
  133. package/lib/NumberFormat/PartitionNumberRangePattern.d.ts +0 -8
  134. package/lib/NumberFormat/PartitionNumberRangePattern.js +0 -40
  135. package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -5
  136. package/lib/NumberFormat/SetNumberFormatDigitOptions.js +0 -179
  137. package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -5
  138. package/lib/NumberFormat/SetNumberFormatUnitOptions.js +0 -50
  139. package/lib/NumberFormat/ToRawFixed.d.ts +0 -9
  140. package/lib/NumberFormat/ToRawFixed.js +0 -119
  141. package/lib/NumberFormat/ToRawPrecision.d.ts +0 -9
  142. package/lib/NumberFormat/ToRawPrecision.js +0 -148
  143. package/lib/NumberFormat/digit-mapping.generated.d.ts +0 -1
  144. package/lib/NumberFormat/digit-mapping.generated.js +0 -782
  145. package/lib/NumberFormat/format_to_parts.d.ts +0 -24
  146. package/lib/NumberFormat/format_to_parts.js +0 -447
  147. package/lib/PartitionPattern.d.ts +0 -9
  148. package/lib/PartitionPattern.js +0 -36
  149. package/lib/SupportedLocales.d.ts +0 -9
  150. package/lib/SupportedLocales.js +0 -20
  151. package/lib/ToIntlMathematicalValue.d.ts +0 -2
  152. package/lib/ToIntlMathematicalValue.js +0 -27
  153. package/lib/constants.d.ts +0 -4
  154. package/lib/constants.js +0 -4
  155. package/lib/data.d.ts +0 -5
  156. package/lib/data.js +0 -13
  157. package/lib/index.d.ts +0 -47
  158. package/lib/index.js +0 -45
  159. package/lib/regex.generated.d.ts +0 -1
  160. package/lib/regex.generated.js +0 -2
  161. package/lib/types/core.d.ts +0 -10
  162. package/lib/types/core.js +0 -1
  163. package/lib/types/date-time.d.ts +0 -135
  164. package/lib/types/date-time.js +0 -6
  165. package/lib/types/displaynames.d.ts +0 -65
  166. package/lib/types/displaynames.js +0 -1
  167. package/lib/types/list.d.ts +0 -18
  168. package/lib/types/list.js +0 -1
  169. package/lib/types/number.d.ts +0 -173
  170. package/lib/types/number.js +0 -1
  171. package/lib/types/plural-rules.d.ts +0 -16
  172. package/lib/types/plural-rules.js +0 -1
  173. package/lib/types/relative-time.d.ts +0 -40
  174. package/lib/types/relative-time.js +0 -1
  175. package/lib/utils.d.ts +0 -30
  176. package/lib/utils.js +0 -135
@@ -1,24 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatLocaleInternalData, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsNotation, NumberFormatOptionsStyle, NumberFormatOptionsUnitDisplay, NumberFormatPart, RoundingModeType, UseGroupingType } from '../types/number';
3
- interface NumberResult {
4
- formattedString: string;
5
- roundedNumber: Decimal;
6
- sign: -1 | 0 | 1;
7
- exponent: number;
8
- magnitude: number;
9
- }
10
- export default function formatToParts(numberResult: NumberResult, data: NumberFormatLocaleInternalData, pl: Intl.PluralRules, options: {
11
- numberingSystem: string;
12
- useGrouping?: UseGroupingType;
13
- style: NumberFormatOptionsStyle;
14
- notation: NumberFormatOptionsNotation;
15
- compactDisplay?: NumberFormatOptionsCompactDisplay;
16
- currency?: string;
17
- currencyDisplay?: NumberFormatOptionsCurrencyDisplay;
18
- currencySign?: NumberFormatOptionsCurrencySign;
19
- unit?: string;
20
- unitDisplay?: NumberFormatOptionsUnitDisplay;
21
- roundingIncrement: number;
22
- roundingMode: RoundingModeType;
23
- }): NumberFormatPart[];
24
- export {};
@@ -1,447 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { S_UNICODE_REGEX } from '../regex.generated';
3
- import { digitMapping } from './digit-mapping.generated';
4
- import { GetUnsignedRoundingMode } from './GetUnsignedRoundingMode';
5
- import { ToRawFixed } from './ToRawFixed';
6
- // This is from: unicode-12.1.0/General_Category/Symbol/regex.js
7
- // IE11 does not support unicode flag, otherwise this is just /\p{S}/u.
8
- // /^\p{S}/u
9
- var CARET_S_UNICODE_REGEX = new RegExp("^".concat(S_UNICODE_REGEX.source));
10
- // /\p{S}$/u
11
- var S_DOLLAR_UNICODE_REGEX = new RegExp("".concat(S_UNICODE_REGEX.source, "$"));
12
- var CLDR_NUMBER_PATTERN = /[#0](?:[\.,][#0]+)*/g;
13
- export default function formatToParts(numberResult, data, pl, options) {
14
- var _a;
15
- var sign = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
16
- var notation = options.notation, style = options.style, numberingSystem = options.numberingSystem;
17
- var defaultNumberingSystem = data.numbers.nu[0];
18
- // #region Part 1: partition and interpolate the CLDR number pattern.
19
- // ----------------------------------------------------------
20
- var compactNumberPattern = null;
21
- if (notation === 'compact' && magnitude) {
22
- compactNumberPattern = getCompactDisplayPattern(numberResult, pl, data, style, options.compactDisplay, options.currencyDisplay, numberingSystem);
23
- }
24
- // This is used multiple times
25
- var nonNameCurrencyPart;
26
- if (style === 'currency' && options.currencyDisplay !== 'name') {
27
- var byCurrencyDisplay = data.currencies[options.currency];
28
- if (byCurrencyDisplay) {
29
- switch (options.currencyDisplay) {
30
- case 'code':
31
- nonNameCurrencyPart = options.currency;
32
- break;
33
- case 'symbol':
34
- nonNameCurrencyPart = byCurrencyDisplay.symbol;
35
- break;
36
- default:
37
- nonNameCurrencyPart = byCurrencyDisplay.narrow;
38
- break;
39
- }
40
- }
41
- else {
42
- // Fallback for unknown currency
43
- nonNameCurrencyPart = options.currency;
44
- }
45
- }
46
- var numberPattern;
47
- if (!compactNumberPattern) {
48
- // Note: if the style is unit, or is currency and the currency display is name,
49
- // its unit parts will be interpolated in part 2. So here we can fallback to decimal.
50
- if (style === 'decimal' ||
51
- style === 'unit' ||
52
- (style === 'currency' && options.currencyDisplay === 'name')) {
53
- // Shortcut for decimal
54
- var decimalData = data.numbers.decimal[numberingSystem] ||
55
- data.numbers.decimal[defaultNumberingSystem];
56
- numberPattern = getPatternForSign(decimalData.standard, sign);
57
- }
58
- else if (style === 'currency') {
59
- var currencyData = data.numbers.currency[numberingSystem] ||
60
- data.numbers.currency[defaultNumberingSystem];
61
- // We replace number pattern part with `0` for easier postprocessing.
62
- numberPattern = getPatternForSign(currencyData[options.currencySign], sign);
63
- }
64
- else {
65
- // percent
66
- var percentPattern = data.numbers.percent[numberingSystem] ||
67
- data.numbers.percent[defaultNumberingSystem];
68
- numberPattern = getPatternForSign(percentPattern, sign);
69
- }
70
- }
71
- else {
72
- numberPattern = compactNumberPattern;
73
- }
74
- // Extract the decimal number pattern string. It looks like "#,##0,00", which will later be
75
- // used to infer decimal group sizes.
76
- var decimalNumberPattern = CLDR_NUMBER_PATTERN.exec(numberPattern)[0];
77
- // Now we start to substitute patterns
78
- // 1. replace strings like `0` and `#,##0.00` with `{0}`
79
- // 2. unquote characters (invariant: the quoted characters does not contain the special tokens)
80
- numberPattern = numberPattern
81
- .replace(CLDR_NUMBER_PATTERN, '{0}')
82
- .replace(/'(.)'/g, '$1');
83
- // Handle currency spacing (both compact and non-compact).
84
- if (style === 'currency' && options.currencyDisplay !== 'name') {
85
- var currencyData = data.numbers.currency[numberingSystem] ||
86
- data.numbers.currency[defaultNumberingSystem];
87
- // See `currencySpacing` substitution rule in TR-35.
88
- // Here we always assume the currencyMatch is "[:^S:]" and surroundingMatch is "[:digit:]".
89
- //
90
- // Example 1: for pattern "#,##0.00¤" with symbol "US$", we replace "¤" with the symbol,
91
- // but insert an extra non-break space before the symbol, because "[:^S:]" matches "U" in
92
- // "US$" and "[:digit:]" matches the latn numbering system digits.
93
- //
94
- // Example 2: for pattern "¤#,##0.00" with symbol "US$", there is no spacing between symbol
95
- // and number, because `$` does not match "[:^S:]".
96
- //
97
- // Implementation note: here we do the best effort to infer the insertion.
98
- // We also assume that `beforeInsertBetween` and `afterInsertBetween` will never be `;`.
99
- var afterCurrency = currencyData.currencySpacing.afterInsertBetween;
100
- if (afterCurrency && !S_DOLLAR_UNICODE_REGEX.test(nonNameCurrencyPart)) {
101
- numberPattern = numberPattern.replace('¤{0}', "\u00A4".concat(afterCurrency, "{0}"));
102
- }
103
- var beforeCurrency = currencyData.currencySpacing.beforeInsertBetween;
104
- if (beforeCurrency && !CARET_S_UNICODE_REGEX.test(nonNameCurrencyPart)) {
105
- numberPattern = numberPattern.replace('{0}¤', "{0}".concat(beforeCurrency, "\u00A4"));
106
- }
107
- }
108
- // The following tokens are special: `{0}`, `¤`, `%`, `-`, `+`, `{c:...}.
109
- var numberPatternParts = numberPattern.split(/({c:[^}]+}|\{0\}|[¤%\-\+])/g);
110
- var numberParts = [];
111
- var symbols = data.numbers.symbols[numberingSystem] ||
112
- data.numbers.symbols[defaultNumberingSystem];
113
- for (var _i = 0, numberPatternParts_1 = numberPatternParts; _i < numberPatternParts_1.length; _i++) {
114
- var part = numberPatternParts_1[_i];
115
- if (!part) {
116
- continue;
117
- }
118
- switch (part) {
119
- case '{0}': {
120
- // We only need to handle scientific and engineering notation here.
121
- numberParts.push.apply(numberParts, partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
122
- // If compact number pattern exists, do not insert group separators.
123
- !compactNumberPattern && ((_a = options.useGrouping) !== null && _a !== void 0 ? _a : true), decimalNumberPattern, style, options.roundingIncrement, GetUnsignedRoundingMode(options.roundingMode, sign === -1)));
124
- break;
125
- }
126
- case '-':
127
- numberParts.push({ type: 'minusSign', value: symbols.minusSign });
128
- break;
129
- case '+':
130
- numberParts.push({ type: 'plusSign', value: symbols.plusSign });
131
- break;
132
- case '%':
133
- numberParts.push({ type: 'percentSign', value: symbols.percentSign });
134
- break;
135
- case '¤':
136
- // Computed above when handling currency spacing.
137
- numberParts.push({ type: 'currency', value: nonNameCurrencyPart });
138
- break;
139
- default:
140
- if (/^\{c:/.test(part)) {
141
- numberParts.push({
142
- type: 'compact',
143
- value: part.substring(3, part.length - 1),
144
- });
145
- }
146
- else {
147
- // literal
148
- numberParts.push({ type: 'literal', value: part });
149
- }
150
- break;
151
- }
152
- }
153
- // #endregion
154
- // #region Part 2: interpolate unit pattern if necessary.
155
- // ----------------------------------------------
156
- switch (style) {
157
- case 'currency': {
158
- // `currencyDisplay: 'name'` has similar pattern handling as units.
159
- if (options.currencyDisplay === 'name') {
160
- var unitPattern = (data.numbers.currency[numberingSystem] ||
161
- data.numbers.currency[defaultNumberingSystem]).unitPattern;
162
- // Select plural
163
- var unitName = void 0;
164
- var currencyNameData = data.currencies[options.currency];
165
- if (currencyNameData) {
166
- unitName = selectPlural(pl, numberResult.roundedNumber
167
- .times(Decimal.pow(10, exponent))
168
- .toNumber(), currencyNameData.displayName);
169
- }
170
- else {
171
- // Fallback for unknown currency
172
- unitName = options.currency;
173
- }
174
- // Do {0} and {1} substitution
175
- var unitPatternParts = unitPattern.split(/(\{[01]\})/g);
176
- var result = [];
177
- for (var _b = 0, unitPatternParts_1 = unitPatternParts; _b < unitPatternParts_1.length; _b++) {
178
- var part = unitPatternParts_1[_b];
179
- switch (part) {
180
- case '{0}':
181
- result.push.apply(result, numberParts);
182
- break;
183
- case '{1}':
184
- result.push({ type: 'currency', value: unitName });
185
- break;
186
- default:
187
- if (part) {
188
- result.push({ type: 'literal', value: part });
189
- }
190
- break;
191
- }
192
- }
193
- return result;
194
- }
195
- else {
196
- return numberParts;
197
- }
198
- }
199
- case 'unit': {
200
- var unit = options.unit, unitDisplay = options.unitDisplay;
201
- var unitData = data.units.simple[unit];
202
- var unitPattern = void 0;
203
- if (unitData) {
204
- // Simple unit pattern
205
- unitPattern = selectPlural(pl, numberResult.roundedNumber
206
- .times(Decimal.pow(10, exponent))
207
- .toNumber(), data.units.simple[unit][unitDisplay]);
208
- }
209
- else {
210
- // See: http://unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
211
- // If cannot find unit in the simple pattern, it must be "per" compound pattern.
212
- // Implementation note: we are not following TR-35 here because we need to format to parts!
213
- var _c = unit.split('-per-'), numeratorUnit = _c[0], denominatorUnit = _c[1];
214
- unitData = data.units.simple[numeratorUnit];
215
- var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber
216
- .times(Decimal.pow(10, exponent))
217
- .toNumber(), data.units.simple[numeratorUnit][unitDisplay]);
218
- var perUnitPattern = data.units.simple[denominatorUnit].perUnit[unitDisplay];
219
- if (perUnitPattern) {
220
- // perUnitPattern exists, combine it with numeratorUnitPattern
221
- unitPattern = perUnitPattern.replace('{0}', numeratorUnitPattern);
222
- }
223
- else {
224
- // get compoundUnit pattern (e.g. "{0} per {1}"), repalce {0} with numerator pattern and {1} with
225
- // the denominator pattern in singular form.
226
- var perPattern = data.units.compound.per[unitDisplay];
227
- var denominatorPattern = selectPlural(pl, 1, data.units.simple[denominatorUnit][unitDisplay]);
228
- unitPattern = unitPattern = perPattern
229
- .replace('{0}', numeratorUnitPattern)
230
- .replace('{1}', denominatorPattern.replace('{0}', ''));
231
- }
232
- }
233
- var result = [];
234
- // We need spacing around "{0}" because they are not treated as "unit" parts, but "literal".
235
- for (var _d = 0, _e = unitPattern.split(/(\s*\{0\}\s*)/); _d < _e.length; _d++) {
236
- var part = _e[_d];
237
- var interpolateMatch = /^(\s*)\{0\}(\s*)$/.exec(part);
238
- if (interpolateMatch) {
239
- // Space before "{0}"
240
- if (interpolateMatch[1]) {
241
- result.push({ type: 'literal', value: interpolateMatch[1] });
242
- }
243
- // "{0}" itself
244
- result.push.apply(result, numberParts);
245
- // Space after "{0}"
246
- if (interpolateMatch[2]) {
247
- result.push({ type: 'literal', value: interpolateMatch[2] });
248
- }
249
- }
250
- else if (part) {
251
- result.push({ type: 'unit', value: part });
252
- }
253
- }
254
- return result;
255
- }
256
- default:
257
- return numberParts;
258
- }
259
- // #endregion
260
- }
261
- // A subset of https://tc39.es/ecma402/#sec-partitionnotationsubpattern
262
- // Plus the exponent parts handling.
263
- function partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem, useGrouping,
264
- /**
265
- * This is the decimal number pattern without signs or symbols.
266
- * It is used to infer the group size when `useGrouping` is true.
267
- *
268
- * A typical value looks like "#,##0.00" (primary group size is 3).
269
- * Some locales like Hindi has secondary group size of 2 (e.g. "#,##,##0.00").
270
- */
271
- decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
272
- var result = [];
273
- // eslint-disable-next-line prefer-const
274
- var n = numberResult.formattedString, x = numberResult.roundedNumber;
275
- if (x.isNaN()) {
276
- return [{ type: 'nan', value: n }];
277
- }
278
- else if (!x.isFinite()) {
279
- return [{ type: 'infinity', value: n }];
280
- }
281
- var digitReplacementTable = digitMapping[numberingSystem];
282
- if (digitReplacementTable) {
283
- n = n.replace(/\d/g, function (digit) { return digitReplacementTable[+digit] || digit; });
284
- }
285
- // TODO: Else use an implementation dependent algorithm to map n to the appropriate
286
- // representation of n in the given numbering system.
287
- var decimalSepIndex = n.indexOf('.');
288
- var integer;
289
- var fraction;
290
- if (decimalSepIndex > 0) {
291
- integer = n.slice(0, decimalSepIndex);
292
- fraction = n.slice(decimalSepIndex + 1);
293
- }
294
- else {
295
- integer = n;
296
- }
297
- // #region Grouping integer digits
298
- // The weird compact and x >= 10000 check is to ensure consistency with Node.js and Chrome.
299
- // Note that `de` does not have compact form for thousands, but Node.js does not insert grouping separator
300
- // unless the rounded number is greater than 10000:
301
- // NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
302
- // NumberFormat('de').format(1234) //=> "1.234"
303
- var shouldUseGrouping = false;
304
- if (useGrouping === 'always') {
305
- shouldUseGrouping = true;
306
- }
307
- else if (useGrouping === 'min2') {
308
- shouldUseGrouping = x.greaterThanOrEqualTo(10000);
309
- }
310
- else if (useGrouping === 'auto' || useGrouping) {
311
- shouldUseGrouping = notation !== 'compact' || x.greaterThanOrEqualTo(10000);
312
- }
313
- if (shouldUseGrouping) {
314
- // a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
315
- // For currency we should use `currencyGroup` instead of generic `group`
316
- var groupSepSymbol = style === 'currency' && symbols.currencyGroup != null
317
- ? symbols.currencyGroup
318
- : symbols.group;
319
- var groups = [];
320
- // > There may be two different grouping sizes: The primary grouping size used for the least
321
- // > significant integer group, and the secondary grouping size used for more significant groups.
322
- // > If a pattern contains multiple grouping separators, the interval between the last one and the
323
- // > end of the integer defines the primary grouping size, and the interval between the last two
324
- // > defines the secondary grouping size. All others are ignored.
325
- var integerNumberPattern = decimalNumberPattern.split('.')[0];
326
- var patternGroups = integerNumberPattern.split(',');
327
- var primaryGroupingSize = 3;
328
- var secondaryGroupingSize = 3;
329
- if (patternGroups.length > 1) {
330
- primaryGroupingSize = patternGroups[patternGroups.length - 1].length;
331
- }
332
- if (patternGroups.length > 2) {
333
- secondaryGroupingSize = patternGroups[patternGroups.length - 2].length;
334
- }
335
- var i = integer.length - primaryGroupingSize;
336
- if (i > 0) {
337
- // Slice the least significant integer group
338
- groups.push(integer.slice(i, i + primaryGroupingSize));
339
- // Then iteratively push the more signicant groups
340
- // TODO: handle surrogate pairs in some numbering system digits
341
- for (i -= secondaryGroupingSize; i > 0; i -= secondaryGroupingSize) {
342
- groups.push(integer.slice(i, i + secondaryGroupingSize));
343
- }
344
- groups.push(integer.slice(0, i + secondaryGroupingSize));
345
- }
346
- else {
347
- groups.push(integer);
348
- }
349
- while (groups.length > 0) {
350
- var integerGroup = groups.pop();
351
- result.push({ type: 'integer', value: integerGroup });
352
- if (groups.length > 0) {
353
- result.push({ type: 'group', value: groupSepSymbol });
354
- }
355
- }
356
- }
357
- else {
358
- result.push({ type: 'integer', value: integer });
359
- }
360
- // #endregion
361
- if (fraction !== undefined) {
362
- var decimalSepSymbol = style === 'currency' && symbols.currencyDecimal != null
363
- ? symbols.currencyDecimal
364
- : symbols.decimal;
365
- result.push({ type: 'decimal', value: decimalSepSymbol }, { type: 'fraction', value: fraction });
366
- }
367
- if ((notation === 'scientific' || notation === 'engineering') &&
368
- x.isFinite()) {
369
- result.push({ type: 'exponentSeparator', value: symbols.exponential });
370
- if (exponent < 0) {
371
- result.push({ type: 'exponentMinusSign', value: symbols.minusSign });
372
- exponent = -exponent;
373
- }
374
- var exponentResult = ToRawFixed(new Decimal(exponent), 0, 0, roundingIncrement, unsignedRoundingMode);
375
- result.push({
376
- type: 'exponentInteger',
377
- value: exponentResult.formattedString,
378
- });
379
- }
380
- return result;
381
- }
382
- function getPatternForSign(pattern, sign) {
383
- if (pattern.indexOf(';') < 0) {
384
- pattern = "".concat(pattern, ";-").concat(pattern);
385
- }
386
- var _a = pattern.split(';'), zeroPattern = _a[0], negativePattern = _a[1];
387
- switch (sign) {
388
- case 0:
389
- return zeroPattern;
390
- case -1:
391
- return negativePattern;
392
- default:
393
- return negativePattern.indexOf('-') >= 0
394
- ? negativePattern.replace(/-/g, '+')
395
- : "+".concat(zeroPattern);
396
- }
397
- }
398
- // Find the CLDR pattern for compact notation based on the magnitude of data and style.
399
- //
400
- // Example return value: "¤ {c:laki}000;¤{c:laki} -0" (`sw` locale):
401
- // - Notice the `{c:...}` token that wraps the compact literal.
402
- // - The consecutive zeros are normalized to single zero to match CLDR_NUMBER_PATTERN.
403
- //
404
- // Returning null means the compact display pattern cannot be found.
405
- function getCompactDisplayPattern(numberResult, pl, data, style, compactDisplay, currencyDisplay, numberingSystem) {
406
- var _a;
407
- var roundedNumber = numberResult.roundedNumber, sign = numberResult.sign, magnitude = numberResult.magnitude;
408
- var magnitudeKey = String(Math.pow(10, magnitude));
409
- var defaultNumberingSystem = data.numbers.nu[0];
410
- var pattern;
411
- if (style === 'currency' && currencyDisplay !== 'name') {
412
- var byNumberingSystem = data.numbers.currency;
413
- var currencyData = byNumberingSystem[numberingSystem] ||
414
- byNumberingSystem[defaultNumberingSystem];
415
- // NOTE: compact notation ignores currencySign!
416
- var compactPluralRules = (_a = currencyData.short) === null || _a === void 0 ? void 0 : _a[magnitudeKey];
417
- if (!compactPluralRules) {
418
- return null;
419
- }
420
- pattern = selectPlural(pl, roundedNumber.toNumber(), compactPluralRules);
421
- }
422
- else {
423
- var byNumberingSystem = data.numbers.decimal;
424
- var byCompactDisplay = byNumberingSystem[numberingSystem] ||
425
- byNumberingSystem[defaultNumberingSystem];
426
- var compactPlaralRule = byCompactDisplay[compactDisplay][magnitudeKey];
427
- if (!compactPlaralRule) {
428
- return null;
429
- }
430
- pattern = selectPlural(pl, roundedNumber.toNumber(), compactPlaralRule);
431
- }
432
- // See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
433
- // > If the value is precisely “0”, either explicit or defaulted, then the normal number format
434
- // > pattern for that sort of object is supplied.
435
- if (pattern === '0') {
436
- return null;
437
- }
438
- pattern = getPatternForSign(pattern, sign)
439
- // Extract compact literal from the pattern
440
- .replace(/([^\s;\-\+\d¤]+)/g, '{c:$1}')
441
- // We replace one or more zeros with a single zero so it matches `CLDR_NUMBER_PATTERN`.
442
- .replace(/0+/, '0');
443
- return pattern;
444
- }
445
- function selectPlural(pl, x, rules) {
446
- return rules[pl.select(x)] || rules.other;
447
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Partition a pattern into a list of literals and placeholders
3
- * https://tc39.es/ecma402/#sec-partitionpattern
4
- * @param pattern
5
- */
6
- export declare function PartitionPattern<T extends string>(pattern: string): Array<{
7
- type: T;
8
- value: string | undefined;
9
- }>;
@@ -1,36 +0,0 @@
1
- import { invariant } from './utils';
2
- /**
3
- * Partition a pattern into a list of literals and placeholders
4
- * https://tc39.es/ecma402/#sec-partitionpattern
5
- * @param pattern
6
- */
7
- export function PartitionPattern(pattern) {
8
- var result = [];
9
- var beginIndex = pattern.indexOf('{');
10
- var endIndex = 0;
11
- var nextIndex = 0;
12
- var length = pattern.length;
13
- while (beginIndex < pattern.length && beginIndex > -1) {
14
- endIndex = pattern.indexOf('}', beginIndex);
15
- invariant(endIndex > beginIndex, "Invalid pattern ".concat(pattern));
16
- if (beginIndex > nextIndex) {
17
- result.push({
18
- type: 'literal',
19
- value: pattern.substring(nextIndex, beginIndex),
20
- });
21
- }
22
- result.push({
23
- type: pattern.substring(beginIndex + 1, endIndex),
24
- value: undefined,
25
- });
26
- nextIndex = endIndex + 1;
27
- beginIndex = pattern.indexOf('{', nextIndex);
28
- }
29
- if (nextIndex < length) {
30
- result.push({
31
- type: 'literal',
32
- value: pattern.substring(nextIndex, length),
33
- });
34
- }
35
- return result;
36
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-supportedlocales
3
- * @param availableLocales
4
- * @param requestedLocales
5
- * @param options
6
- */
7
- export declare function SupportedLocales(availableLocales: Set<string>, requestedLocales: string[], options?: {
8
- localeMatcher?: 'best fit' | 'lookup';
9
- }): string[];
@@ -1,20 +0,0 @@
1
- import { LookupSupportedLocales } from '@formatjs/intl-localematcher';
2
- import { ToObject } from './262';
3
- import { GetOption } from './GetOption';
4
- /**
5
- * https://tc39.es/ecma402/#sec-supportedlocales
6
- * @param availableLocales
7
- * @param requestedLocales
8
- * @param options
9
- */
10
- export function SupportedLocales(availableLocales, requestedLocales, options) {
11
- var matcher = 'best fit';
12
- if (options !== undefined) {
13
- options = ToObject(options);
14
- matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
15
- }
16
- if (matcher === 'best fit') {
17
- return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
18
- }
19
- return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
20
- }
@@ -1,2 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- export declare function ToIntlMathematicalValue(input: unknown): Decimal;
@@ -1,27 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { ToPrimitive } from './262';
3
- export function ToIntlMathematicalValue(input) {
4
- var primValue = ToPrimitive(input, 'number');
5
- if (typeof primValue === 'bigint') {
6
- return new Decimal(primValue);
7
- }
8
- // IMPL
9
- if (primValue === undefined) {
10
- return new Decimal(NaN);
11
- }
12
- if (primValue === true) {
13
- return new Decimal(1);
14
- }
15
- if (primValue === false) {
16
- return new Decimal(0);
17
- }
18
- if (primValue === null) {
19
- return new Decimal(0);
20
- }
21
- try {
22
- return new Decimal(primValue);
23
- }
24
- catch (e) {
25
- return new Decimal(NaN);
26
- }
27
- }
@@ -1,4 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- export declare const TEN: Decimal;
3
- export declare const ZERO: Decimal;
4
- export declare const NEGATIVE_ZERO: Decimal;
package/lib/constants.js DELETED
@@ -1,4 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- export var TEN = new Decimal(10);
3
- export var ZERO = new Decimal(0);
4
- export var NEGATIVE_ZERO = new Decimal(-0);
package/lib/data.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare class MissingLocaleDataError extends Error {
2
- type: string;
3
- }
4
- export declare function isMissingLocaleDataError(e: Error): e is MissingLocaleDataError;
5
- export {};
package/lib/data.js DELETED
@@ -1,13 +0,0 @@
1
- import { __extends } from "tslib";
2
- var MissingLocaleDataError = /** @class */ (function (_super) {
3
- __extends(MissingLocaleDataError, _super);
4
- function MissingLocaleDataError() {
5
- var _this = _super !== null && _super.apply(this, arguments) || this;
6
- _this.type = 'MISSING_LOCALE_DATA';
7
- return _this;
8
- }
9
- return MissingLocaleDataError;
10
- }(Error));
11
- export function isMissingLocaleDataError(e) {
12
- return e.type === 'MISSING_LOCALE_DATA';
13
- }
package/lib/index.d.ts DELETED
@@ -1,47 +0,0 @@
1
- export * from './CanonicalizeLocaleList';
2
- export * from './CanonicalizeTimeZoneName';
3
- export * from './CoerceOptionsToObject';
4
- export * from './GetNumberOption';
5
- export * from './GetOption';
6
- export * from './GetOptionsObject';
7
- export * from './GetStringOrBooleanOption';
8
- export * from './IsSanctionedSimpleUnitIdentifier';
9
- export * from './IsValidTimeZoneName';
10
- export * from './IsWellFormedCurrencyCode';
11
- export * from './IsWellFormedUnitIdentifier';
12
- export * from './NumberFormat/ApplyUnsignedRoundingMode';
13
- export * from './NumberFormat/CollapseNumberRange';
14
- export * from './NumberFormat/ComputeExponent';
15
- export * from './NumberFormat/ComputeExponentForMagnitude';
16
- export * from './NumberFormat/CurrencyDigits';
17
- export { default as _formatToParts } from './NumberFormat/format_to_parts';
18
- export * from './NumberFormat/FormatApproximately';
19
- export * from './NumberFormat/FormatNumeric';
20
- export * from './NumberFormat/FormatNumericRange';
21
- export * from './NumberFormat/FormatNumericRangeToParts';
22
- export * from './NumberFormat/FormatNumericToParts';
23
- export * from './NumberFormat/FormatNumericToString';
24
- export * from './NumberFormat/GetUnsignedRoundingMode';
25
- export * from './NumberFormat/InitializeNumberFormat';
26
- export * from './NumberFormat/PartitionNumberPattern';
27
- export * from './NumberFormat/PartitionNumberRangePattern';
28
- export * from './NumberFormat/SetNumberFormatDigitOptions';
29
- export * from './NumberFormat/SetNumberFormatUnitOptions';
30
- export * from './NumberFormat/ToRawFixed';
31
- export * from './NumberFormat/ToRawPrecision';
32
- export * from './PartitionPattern';
33
- export * from './SupportedLocales';
34
- export { createDataProperty, defineProperty, getInternalSlot, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
35
- export type { LiteralPart } from './utils';
36
- export * from './262';
37
- export { isMissingLocaleDataError } from './data';
38
- export type { LocaleData } from './types/core';
39
- export * from './types/date-time';
40
- export * from './types/displaynames';
41
- export * from './types/list';
42
- export * from './types/number';
43
- export * from './types/plural-rules';
44
- export * from './types/relative-time';
45
- export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
46
- export { ZERO } from './constants';
47
- export { ToIntlMathematicalValue } from './ToIntlMathematicalValue';