@formatjs/ecma402-abstract 2.3.0 → 2.3.1
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.
|
@@ -16,6 +16,7 @@ var CARET_S_UNICODE_REGEX = new RegExp("^".concat(regex_generated_1.S_UNICODE_RE
|
|
|
16
16
|
var S_DOLLAR_UNICODE_REGEX = new RegExp("".concat(regex_generated_1.S_UNICODE_REGEX.source, "$"));
|
|
17
17
|
var CLDR_NUMBER_PATTERN = /[#0](?:[\.,][#0]+)*/g;
|
|
18
18
|
function formatToParts(numberResult, data, pl, options) {
|
|
19
|
+
var _a;
|
|
19
20
|
var sign = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
|
|
20
21
|
var notation = options.notation, style = options.style, numberingSystem = options.numberingSystem;
|
|
21
22
|
var defaultNumberingSystem = data.numbers.nu[0];
|
|
@@ -124,7 +125,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
124
125
|
// We only need to handle scientific and engineering notation here.
|
|
125
126
|
numberParts.push.apply(numberParts, partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
126
127
|
// If compact number pattern exists, do not insert group separators.
|
|
127
|
-
!compactNumberPattern &&
|
|
128
|
+
!compactNumberPattern && ((_a = options.useGrouping) !== null && _a !== void 0 ? _a : true), decimalNumberPattern, style, options.roundingIncrement, (0, GetUnsignedRoundingMode_1.GetUnsignedRoundingMode)(options.roundingMode, sign === -1)));
|
|
128
129
|
break;
|
|
129
130
|
}
|
|
130
131
|
case '-':
|
|
@@ -176,8 +177,8 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
176
177
|
// Do {0} and {1} substitution
|
|
177
178
|
var unitPatternParts = unitPattern.split(/(\{[01]\})/g);
|
|
178
179
|
var result = [];
|
|
179
|
-
for (var
|
|
180
|
-
var part = unitPatternParts_1[
|
|
180
|
+
for (var _b = 0, unitPatternParts_1 = unitPatternParts; _b < unitPatternParts_1.length; _b++) {
|
|
181
|
+
var part = unitPatternParts_1[_b];
|
|
181
182
|
switch (part) {
|
|
182
183
|
case '{0}':
|
|
183
184
|
result.push.apply(result, numberParts);
|
|
@@ -210,7 +211,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
210
211
|
// See: http://unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
|
|
211
212
|
// If cannot find unit in the simple pattern, it must be "per" compound pattern.
|
|
212
213
|
// Implementation note: we are not following TR-35 here because we need to format to parts!
|
|
213
|
-
var
|
|
214
|
+
var _c = unit.split('-per-'), numeratorUnit = _c[0], denominatorUnit = _c[1];
|
|
214
215
|
unitData = data.units.simple[numeratorUnit];
|
|
215
216
|
var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber.times(constants_1.TEN.pow(exponent)).toNumber(), data.units.simple[numeratorUnit][unitDisplay]);
|
|
216
217
|
var perUnitPattern = data.units.simple[denominatorUnit].perUnit[unitDisplay];
|
|
@@ -230,8 +231,8 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
230
231
|
}
|
|
231
232
|
var result = [];
|
|
232
233
|
// We need spacing around "{0}" because they are not treated as "unit" parts, but "literal".
|
|
233
|
-
for (var
|
|
234
|
-
var part = _d
|
|
234
|
+
for (var _d = 0, _e = unitPattern.split(/(\s*\{0\}\s*)/); _d < _e.length; _d++) {
|
|
235
|
+
var part = _e[_d];
|
|
235
236
|
var interpolateMatch = /^(\s*)\{0\}(\s*)$/.exec(part);
|
|
236
237
|
if (interpolateMatch) {
|
|
237
238
|
// Space before "{0}"
|
|
@@ -298,8 +299,17 @@ decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
|
|
|
298
299
|
// unless the rounded number is greater than 10000:
|
|
299
300
|
// NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
|
|
300
301
|
// NumberFormat('de').format(1234) //=> "1.234"
|
|
301
|
-
|
|
302
|
-
|
|
302
|
+
var shouldUseGrouping = false;
|
|
303
|
+
if (useGrouping === 'always') {
|
|
304
|
+
shouldUseGrouping = true;
|
|
305
|
+
}
|
|
306
|
+
else if (useGrouping === 'min2') {
|
|
307
|
+
shouldUseGrouping = x.greaterThanOrEqualTo(10000);
|
|
308
|
+
}
|
|
309
|
+
else if (useGrouping === 'auto' || useGrouping) {
|
|
310
|
+
shouldUseGrouping = notation !== 'compact' || x.greaterThanOrEqualTo(10000);
|
|
311
|
+
}
|
|
312
|
+
if (shouldUseGrouping) {
|
|
303
313
|
// a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
|
|
304
314
|
// For currency we should use `currencyGroup` instead of generic `group`
|
|
305
315
|
var groupSepSymbol = style === 'currency' && symbols.currencyGroup != null
|
|
@@ -12,6 +12,7 @@ var CARET_S_UNICODE_REGEX = new RegExp("^".concat(S_UNICODE_REGEX.source));
|
|
|
12
12
|
var S_DOLLAR_UNICODE_REGEX = new RegExp("".concat(S_UNICODE_REGEX.source, "$"));
|
|
13
13
|
var CLDR_NUMBER_PATTERN = /[#0](?:[\.,][#0]+)*/g;
|
|
14
14
|
export default function formatToParts(numberResult, data, pl, options) {
|
|
15
|
+
var _a;
|
|
15
16
|
var sign = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
|
|
16
17
|
var notation = options.notation, style = options.style, numberingSystem = options.numberingSystem;
|
|
17
18
|
var defaultNumberingSystem = data.numbers.nu[0];
|
|
@@ -120,7 +121,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
120
121
|
// We only need to handle scientific and engineering notation here.
|
|
121
122
|
numberParts.push.apply(numberParts, partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
122
123
|
// If compact number pattern exists, do not insert group separators.
|
|
123
|
-
!compactNumberPattern &&
|
|
124
|
+
!compactNumberPattern && ((_a = options.useGrouping) !== null && _a !== void 0 ? _a : true), decimalNumberPattern, style, options.roundingIncrement, GetUnsignedRoundingMode(options.roundingMode, sign === -1)));
|
|
124
125
|
break;
|
|
125
126
|
}
|
|
126
127
|
case '-':
|
|
@@ -172,8 +173,8 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
172
173
|
// Do {0} and {1} substitution
|
|
173
174
|
var unitPatternParts = unitPattern.split(/(\{[01]\})/g);
|
|
174
175
|
var result = [];
|
|
175
|
-
for (var
|
|
176
|
-
var part = unitPatternParts_1[
|
|
176
|
+
for (var _b = 0, unitPatternParts_1 = unitPatternParts; _b < unitPatternParts_1.length; _b++) {
|
|
177
|
+
var part = unitPatternParts_1[_b];
|
|
177
178
|
switch (part) {
|
|
178
179
|
case '{0}':
|
|
179
180
|
result.push.apply(result, numberParts);
|
|
@@ -206,7 +207,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
206
207
|
// See: http://unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
|
|
207
208
|
// If cannot find unit in the simple pattern, it must be "per" compound pattern.
|
|
208
209
|
// Implementation note: we are not following TR-35 here because we need to format to parts!
|
|
209
|
-
var
|
|
210
|
+
var _c = unit.split('-per-'), numeratorUnit = _c[0], denominatorUnit = _c[1];
|
|
210
211
|
unitData = data.units.simple[numeratorUnit];
|
|
211
212
|
var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), data.units.simple[numeratorUnit][unitDisplay]);
|
|
212
213
|
var perUnitPattern = data.units.simple[denominatorUnit].perUnit[unitDisplay];
|
|
@@ -226,8 +227,8 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
226
227
|
}
|
|
227
228
|
var result = [];
|
|
228
229
|
// We need spacing around "{0}" because they are not treated as "unit" parts, but "literal".
|
|
229
|
-
for (var
|
|
230
|
-
var part = _d
|
|
230
|
+
for (var _d = 0, _e = unitPattern.split(/(\s*\{0\}\s*)/); _d < _e.length; _d++) {
|
|
231
|
+
var part = _e[_d];
|
|
231
232
|
var interpolateMatch = /^(\s*)\{0\}(\s*)$/.exec(part);
|
|
232
233
|
if (interpolateMatch) {
|
|
233
234
|
// Space before "{0}"
|
|
@@ -294,8 +295,17 @@ decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
|
|
|
294
295
|
// unless the rounded number is greater than 10000:
|
|
295
296
|
// NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
|
|
296
297
|
// NumberFormat('de').format(1234) //=> "1.234"
|
|
297
|
-
|
|
298
|
-
|
|
298
|
+
var shouldUseGrouping = false;
|
|
299
|
+
if (useGrouping === 'always') {
|
|
300
|
+
shouldUseGrouping = true;
|
|
301
|
+
}
|
|
302
|
+
else if (useGrouping === 'min2') {
|
|
303
|
+
shouldUseGrouping = x.greaterThanOrEqualTo(10000);
|
|
304
|
+
}
|
|
305
|
+
else if (useGrouping === 'auto' || useGrouping) {
|
|
306
|
+
shouldUseGrouping = notation !== 'compact' || x.greaterThanOrEqualTo(10000);
|
|
307
|
+
}
|
|
308
|
+
if (shouldUseGrouping) {
|
|
299
309
|
// a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
|
|
300
310
|
// For currency we should use `currencyGroup` instead of generic `group`
|
|
301
311
|
var groupSepSymbol = style === 'currency' && symbols.currencyGroup != null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/ecma402-abstract",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "A collection of implementation for ECMAScript abstract operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"decimal.js": "10",
|
|
18
18
|
"tslib": "2",
|
|
19
|
-
"@formatjs/
|
|
20
|
-
"@formatjs/
|
|
19
|
+
"@formatjs/intl-localematcher": "0.5.9",
|
|
20
|
+
"@formatjs/fast-memoize": "2.2.5"
|
|
21
21
|
},
|
|
22
22
|
"author": "Long Ho <holevietlong@gmail.com",
|
|
23
23
|
"bugs": {
|