@formatjs/ecma402-abstract 1.18.2 → 1.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NumberFormatLocaleInternalData, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsNotation, NumberFormatOptionsStyle, NumberFormatOptionsUnitDisplay, NumberFormatPart, UseGroupingType } from '../types/number';
|
|
2
2
|
interface NumberResult {
|
|
3
3
|
formattedString: string;
|
|
4
4
|
roundedNumber: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var regex_generated_1 = require("../regex.generated");
|
|
3
4
|
var ToRawFixed_1 = require("./ToRawFixed");
|
|
4
5
|
var digit_mapping_generated_1 = require("./digit-mapping.generated");
|
|
5
|
-
var regex_generated_1 = require("../regex.generated");
|
|
6
6
|
// This is from: unicode-12.1.0/General_Category/Symbol/regex.js
|
|
7
7
|
// IE11 does not support unicode flag, otherwise this is just /\p{S}/u.
|
|
8
8
|
// /^\p{S}/u
|
|
@@ -119,7 +119,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
119
119
|
// We only need to handle scientific and engineering notation here.
|
|
120
120
|
numberParts.push.apply(numberParts, paritionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
121
121
|
// If compact number pattern exists, do not insert group separators.
|
|
122
|
-
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern));
|
|
122
|
+
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern, style));
|
|
123
123
|
break;
|
|
124
124
|
}
|
|
125
125
|
case '-':
|
|
@@ -262,7 +262,7 @@ function paritionNumberIntoParts(symbols, numberResult, notation, exponent, numb
|
|
|
262
262
|
* A typical value looks like "#,##0.00" (primary group size is 3).
|
|
263
263
|
* Some locales like Hindi has secondary group size of 2 (e.g. "#,##,##0.00").
|
|
264
264
|
*/
|
|
265
|
-
decimalNumberPattern) {
|
|
265
|
+
decimalNumberPattern, style) {
|
|
266
266
|
var result = [];
|
|
267
267
|
// eslint-disable-next-line prefer-const
|
|
268
268
|
var n = numberResult.formattedString, x = numberResult.roundedNumber;
|
|
@@ -295,7 +295,11 @@ decimalNumberPattern) {
|
|
|
295
295
|
// NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
|
|
296
296
|
// NumberFormat('de').format(1234) //=> "1.234"
|
|
297
297
|
if (useGrouping && (notation !== 'compact' || x >= 10000)) {
|
|
298
|
-
|
|
298
|
+
// a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
|
|
299
|
+
// For currency we should use `currencyGroup` instead of generic `group`
|
|
300
|
+
var groupSepSymbol = style === 'currency' && symbols.currencyGroup != null
|
|
301
|
+
? symbols.currencyGroup
|
|
302
|
+
: symbols.group;
|
|
299
303
|
var groups = [];
|
|
300
304
|
// > There may be two different grouping sizes: The primary grouping size used for the least
|
|
301
305
|
// > significant integer group, and the secondary grouping size used for more significant groups.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NumberFormatLocaleInternalData, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsNotation, NumberFormatOptionsStyle, NumberFormatOptionsUnitDisplay, NumberFormatPart, UseGroupingType } from '../types/number';
|
|
2
2
|
interface NumberResult {
|
|
3
3
|
formattedString: string;
|
|
4
4
|
roundedNumber: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { S_UNICODE_REGEX } from '../regex.generated';
|
|
1
2
|
import { ToRawFixed } from './ToRawFixed';
|
|
2
3
|
import { digitMapping } from './digit-mapping.generated';
|
|
3
|
-
import { S_UNICODE_REGEX } from '../regex.generated';
|
|
4
4
|
// This is from: unicode-12.1.0/General_Category/Symbol/regex.js
|
|
5
5
|
// IE11 does not support unicode flag, otherwise this is just /\p{S}/u.
|
|
6
6
|
// /^\p{S}/u
|
|
@@ -117,7 +117,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
117
117
|
// We only need to handle scientific and engineering notation here.
|
|
118
118
|
numberParts.push.apply(numberParts, paritionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
119
119
|
// If compact number pattern exists, do not insert group separators.
|
|
120
|
-
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern));
|
|
120
|
+
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern, style));
|
|
121
121
|
break;
|
|
122
122
|
}
|
|
123
123
|
case '-':
|
|
@@ -259,7 +259,7 @@ function paritionNumberIntoParts(symbols, numberResult, notation, exponent, numb
|
|
|
259
259
|
* A typical value looks like "#,##0.00" (primary group size is 3).
|
|
260
260
|
* Some locales like Hindi has secondary group size of 2 (e.g. "#,##,##0.00").
|
|
261
261
|
*/
|
|
262
|
-
decimalNumberPattern) {
|
|
262
|
+
decimalNumberPattern, style) {
|
|
263
263
|
var result = [];
|
|
264
264
|
// eslint-disable-next-line prefer-const
|
|
265
265
|
var n = numberResult.formattedString, x = numberResult.roundedNumber;
|
|
@@ -292,7 +292,11 @@ decimalNumberPattern) {
|
|
|
292
292
|
// NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
|
|
293
293
|
// NumberFormat('de').format(1234) //=> "1.234"
|
|
294
294
|
if (useGrouping && (notation !== 'compact' || x >= 10000)) {
|
|
295
|
-
|
|
295
|
+
// a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
|
|
296
|
+
// For currency we should use `currencyGroup` instead of generic `group`
|
|
297
|
+
var groupSepSymbol = style === 'currency' && symbols.currencyGroup != null
|
|
298
|
+
? symbols.currencyGroup
|
|
299
|
+
: symbols.group;
|
|
296
300
|
var groups = [];
|
|
297
301
|
// > There may be two different grouping sizes: The primary grouping size used for the least
|
|
298
302
|
// > significant integer group, and the secondary grouping size used for more significant groups.
|
package/lib/types/number.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LDMLPluralRule } from './plural-rules';
|
|
2
1
|
import { LocaleData } from './core';
|
|
2
|
+
import { LDMLPluralRule } from './plural-rules';
|
|
3
3
|
export type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
4
4
|
export type RoundingPriorityType = 'auto' | 'morePrecision' | 'lessPrecision';
|
|
5
5
|
export type NumberFormatRoundingType = 'morePrecision' | 'lessPrecision' | 'significantDigits' | 'fractionDigits';
|
|
@@ -87,6 +87,7 @@ export interface SymbolsData {
|
|
|
87
87
|
timeSeparator: string;
|
|
88
88
|
approximatelySign: string;
|
|
89
89
|
rangeSign: string;
|
|
90
|
+
currencyGroup?: string;
|
|
90
91
|
}
|
|
91
92
|
export interface RawNumberData {
|
|
92
93
|
nu: string[];
|
package/package.json
CHANGED
package/types/number.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LDMLPluralRule } from './plural-rules';
|
|
2
1
|
import { LocaleData } from './core';
|
|
2
|
+
import { LDMLPluralRule } from './plural-rules';
|
|
3
3
|
export type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
4
4
|
export type RoundingPriorityType = 'auto' | 'morePrecision' | 'lessPrecision';
|
|
5
5
|
export type NumberFormatRoundingType = 'morePrecision' | 'lessPrecision' | 'significantDigits' | 'fractionDigits';
|
|
@@ -87,6 +87,7 @@ export interface SymbolsData {
|
|
|
87
87
|
timeSeparator: string;
|
|
88
88
|
approximatelySign: string;
|
|
89
89
|
rangeSign: string;
|
|
90
|
+
currencyGroup?: string;
|
|
90
91
|
}
|
|
91
92
|
export interface RawNumberData {
|
|
92
93
|
nu: string[];
|