@formatjs/ecma402-abstract 1.17.3 → 1.18.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.
- package/DefaultNumberOption.d.ts +1 -1
- package/DefaultNumberOption.js +16 -8
- package/GetNumberOption.d.ts +1 -1
- package/GetNumberOption.js +0 -1
- package/GetOption.d.ts +1 -1
- package/LICENSE.md +1 -1
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
- package/NumberFormat/SetNumberFormatDigitOptions.js +2 -3
- package/lib/262.js +23 -49
- package/lib/CanonicalizeLocaleList.js +1 -5
- package/lib/CanonicalizeTimeZoneName.js +1 -5
- package/lib/CoerceOptionsToObject.js +3 -7
- package/lib/DefaultNumberOption.d.ts +1 -1
- package/lib/DefaultNumberOption.js +16 -12
- package/lib/GetNumberOption.d.ts +1 -1
- package/lib/GetNumberOption.js +3 -8
- package/lib/GetOption.d.ts +1 -1
- package/lib/GetOption.js +3 -7
- package/lib/GetOptionsObject.js +1 -5
- package/lib/GetStringOrBooleanOption.js +3 -7
- package/lib/IsSanctionedSimpleUnitIdentifier.js +5 -10
- package/lib/IsValidTimeZoneName.js +1 -5
- package/lib/IsWellFormedCurrencyCode.js +1 -5
- package/lib/IsWellFormedUnitIdentifier.js +5 -9
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +1 -5
- package/lib/NumberFormat/CollapseNumberRange.js +1 -5
- package/lib/NumberFormat/ComputeExponent.js +9 -13
- package/lib/NumberFormat/ComputeExponentForMagnitude.js +1 -5
- package/lib/NumberFormat/CurrencyDigits.js +3 -7
- package/lib/NumberFormat/FormatApproximately.js +1 -5
- package/lib/NumberFormat/FormatNumericRange.js +3 -7
- package/lib/NumberFormat/FormatNumericRangeToParts.js +3 -7
- package/lib/NumberFormat/FormatNumericToParts.js +5 -9
- package/lib/NumberFormat/FormatNumericToString.js +11 -15
- package/lib/NumberFormat/GetUnsignedRoundingMode.js +1 -5
- package/lib/NumberFormat/InitializeNumberFormat.js +27 -31
- package/lib/NumberFormat/PartitionNumberPattern.js +11 -16
- package/lib/NumberFormat/PartitionNumberRangePattern.js +8 -12
- package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
- package/lib/NumberFormat/SetNumberFormatDigitOptions.js +11 -16
- package/lib/NumberFormat/SetNumberFormatUnitOptions.js +12 -16
- package/lib/NumberFormat/ToRawFixed.js +4 -8
- package/lib/NumberFormat/ToRawPrecision.js +7 -11
- package/lib/NumberFormat/digit-mapping.generated.js +1 -4
- package/lib/NumberFormat/format_to_parts.js +8 -11
- package/lib/PartitionPattern.js +3 -7
- package/lib/SupportedLocales.js +8 -12
- package/lib/data.js +3 -7
- package/lib/index.js +42 -56
- package/lib/regex.generated.js +1 -4
- package/lib/types/core.js +1 -2
- package/lib/types/date-time.js +2 -5
- package/lib/types/displaynames.js +1 -2
- package/lib/types/list.js +1 -2
- package/lib/types/number.js +1 -2
- package/lib/types/plural-rules.js +1 -2
- package/lib/types/relative-time.js +1 -2
- package/lib/utils.js +10 -22
- package/package.json +2 -2
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplyUnsignedRoundingMode = void 0;
|
|
4
|
-
function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
|
|
1
|
+
export function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
|
|
5
2
|
if (x === r1)
|
|
6
3
|
return r1;
|
|
7
4
|
if (unsignedRoundingMode === undefined) {
|
|
@@ -39,4 +36,3 @@ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
|
|
|
39
36
|
}
|
|
40
37
|
return r2;
|
|
41
38
|
}
|
|
42
|
-
exports.ApplyUnsignedRoundingMode = ApplyUnsignedRoundingMode;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CollapseNumberRange = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* https://tc39.es/ecma402/#sec-collapsenumberrange
|
|
6
3
|
*/
|
|
7
|
-
function CollapseNumberRange(result) {
|
|
4
|
+
export function CollapseNumberRange(result) {
|
|
8
5
|
return result;
|
|
9
6
|
}
|
|
10
|
-
exports.CollapseNumberRange = CollapseNumberRange;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var utils_1 = require("../utils");
|
|
5
|
-
var ComputeExponentForMagnitude_1 = require("./ComputeExponentForMagnitude");
|
|
6
|
-
var FormatNumericToString_1 = require("./FormatNumericToString");
|
|
1
|
+
import { getMagnitude } from '../utils';
|
|
2
|
+
import { ComputeExponentForMagnitude } from './ComputeExponentForMagnitude';
|
|
3
|
+
import { FormatNumericToString } from './FormatNumericToString';
|
|
7
4
|
/**
|
|
8
5
|
* The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x
|
|
9
6
|
* according to the number formatting settings. It handles cases such as 999 rounding up to 1000,
|
|
@@ -11,7 +8,7 @@ var FormatNumericToString_1 = require("./FormatNumericToString");
|
|
|
11
8
|
*
|
|
12
9
|
* NOT IN SPEC: it returns [exponent, magnitude].
|
|
13
10
|
*/
|
|
14
|
-
function ComputeExponent(numberFormat, x, _a) {
|
|
11
|
+
export function ComputeExponent(numberFormat, x, _a) {
|
|
15
12
|
var getInternalSlots = _a.getInternalSlots;
|
|
16
13
|
if (x === 0) {
|
|
17
14
|
return [0, 0];
|
|
@@ -19,25 +16,24 @@ function ComputeExponent(numberFormat, x, _a) {
|
|
|
19
16
|
if (x < 0) {
|
|
20
17
|
x = -x;
|
|
21
18
|
}
|
|
22
|
-
var magnitude =
|
|
23
|
-
var exponent =
|
|
19
|
+
var magnitude = getMagnitude(x);
|
|
20
|
+
var exponent = ComputeExponentForMagnitude(numberFormat, magnitude, {
|
|
24
21
|
getInternalSlots: getInternalSlots,
|
|
25
22
|
});
|
|
26
23
|
// Preserve more precision by doing multiplication when exponent is negative.
|
|
27
24
|
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
|
|
28
|
-
var formatNumberResult =
|
|
25
|
+
var formatNumberResult = FormatNumericToString(getInternalSlots(numberFormat), x);
|
|
29
26
|
if (formatNumberResult.roundedNumber === 0) {
|
|
30
27
|
return [exponent, magnitude];
|
|
31
28
|
}
|
|
32
|
-
var newMagnitude =
|
|
29
|
+
var newMagnitude = getMagnitude(formatNumberResult.roundedNumber);
|
|
33
30
|
if (newMagnitude === magnitude - exponent) {
|
|
34
31
|
return [exponent, magnitude];
|
|
35
32
|
}
|
|
36
33
|
return [
|
|
37
|
-
|
|
34
|
+
ComputeExponentForMagnitude(numberFormat, magnitude + 1, {
|
|
38
35
|
getInternalSlots: getInternalSlots,
|
|
39
36
|
}),
|
|
40
37
|
magnitude + 1,
|
|
41
38
|
];
|
|
42
39
|
}
|
|
43
|
-
exports.ComputeExponent = ComputeExponent;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComputeExponentForMagnitude = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
|
|
6
3
|
* number of the given magnitude (power of ten of the most significant digit) according to the
|
|
7
4
|
* locale and the desired notation (scientific, engineering, or compact).
|
|
8
5
|
*/
|
|
9
|
-
function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
|
|
6
|
+
export function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
|
|
10
7
|
var getInternalSlots = _a.getInternalSlots;
|
|
11
8
|
var internalSlots = getInternalSlots(numberFormat);
|
|
12
9
|
var notation = internalSlots.notation, dataLocaleData = internalSlots.dataLocaleData, numberingSystem = internalSlots.numberingSystem;
|
|
@@ -61,4 +58,3 @@ function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
|
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
}
|
|
64
|
-
exports.ComputeExponentForMagnitude = ComputeExponentForMagnitude;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CurrencyDigits = void 0;
|
|
4
|
-
var _262_1 = require("../262");
|
|
1
|
+
import { HasOwnProperty } from '../262';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-currencydigits
|
|
7
4
|
*/
|
|
8
|
-
function CurrencyDigits(c, _a) {
|
|
5
|
+
export function CurrencyDigits(c, _a) {
|
|
9
6
|
var currencyDigitsData = _a.currencyDigitsData;
|
|
10
|
-
return
|
|
7
|
+
return HasOwnProperty(currencyDigitsData, c)
|
|
11
8
|
? currencyDigitsData[c]
|
|
12
9
|
: 2;
|
|
13
10
|
}
|
|
14
|
-
exports.CurrencyDigits = CurrencyDigits;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatApproximately = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* https://tc39.es/ecma402/#sec-formatapproximately
|
|
6
3
|
*/
|
|
7
|
-
function FormatApproximately(numberFormat, result, _a) {
|
|
4
|
+
export function FormatApproximately(numberFormat, result, _a) {
|
|
8
5
|
var getInternalSlots = _a.getInternalSlots;
|
|
9
6
|
var internalSlots = getInternalSlots(numberFormat);
|
|
10
7
|
var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
|
|
@@ -12,4 +9,3 @@ function FormatApproximately(numberFormat, result, _a) {
|
|
|
12
9
|
result.push({ type: 'approximatelySign', value: approximatelySign });
|
|
13
10
|
return result;
|
|
14
11
|
}
|
|
15
|
-
exports.FormatApproximately = FormatApproximately;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatNumericRange = void 0;
|
|
4
|
-
var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
|
|
1
|
+
import { PartitionNumberRangePattern } from './PartitionNumberRangePattern';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-formatnumericrange
|
|
7
4
|
*/
|
|
8
|
-
function FormatNumericRange(numberFormat, x, y, _a) {
|
|
5
|
+
export function FormatNumericRange(numberFormat, x, y, _a) {
|
|
9
6
|
var getInternalSlots = _a.getInternalSlots;
|
|
10
|
-
var parts =
|
|
7
|
+
var parts = PartitionNumberRangePattern(numberFormat, x, y, {
|
|
11
8
|
getInternalSlots: getInternalSlots,
|
|
12
9
|
});
|
|
13
10
|
return parts.map(function (part) { return part.value; }).join('');
|
|
14
11
|
}
|
|
15
|
-
exports.FormatNumericRange = FormatNumericRange;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatNumericRangeToParts = void 0;
|
|
4
|
-
var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
|
|
1
|
+
import { PartitionNumberRangePattern } from './PartitionNumberRangePattern';
|
|
5
2
|
/**
|
|
6
3
|
* https://tc39.es/ecma402/#sec-formatnumericrangetoparts
|
|
7
4
|
*/
|
|
8
|
-
function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
5
|
+
export function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
9
6
|
var getInternalSlots = _a.getInternalSlots;
|
|
10
|
-
var parts =
|
|
7
|
+
var parts = PartitionNumberRangePattern(numberFormat, x, y, {
|
|
11
8
|
getInternalSlots: getInternalSlots,
|
|
12
9
|
});
|
|
13
10
|
return parts.map(function (part, index) { return ({
|
|
@@ -17,4 +14,3 @@ function FormatNumericRangeToParts(numberFormat, x, y, _a) {
|
|
|
17
14
|
result: index.toString(),
|
|
18
15
|
}); });
|
|
19
16
|
}
|
|
20
|
-
exports.FormatNumericRangeToParts = FormatNumericRangeToParts;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
function FormatNumericToParts(nf, x, implDetails) {
|
|
7
|
-
var parts = (0, PartitionNumberPattern_1.PartitionNumberPattern)(nf, x, implDetails);
|
|
8
|
-
var result = (0, _262_1.ArrayCreate)(0);
|
|
1
|
+
import { PartitionNumberPattern } from './PartitionNumberPattern';
|
|
2
|
+
import { ArrayCreate } from '../262';
|
|
3
|
+
export function FormatNumericToParts(nf, x, implDetails) {
|
|
4
|
+
var parts = PartitionNumberPattern(nf, x, implDetails);
|
|
5
|
+
var result = ArrayCreate(0);
|
|
9
6
|
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
10
7
|
var part = parts_1[_i];
|
|
11
8
|
result.push({
|
|
@@ -15,4 +12,3 @@ function FormatNumericToParts(nf, x, implDetails) {
|
|
|
15
12
|
}
|
|
16
13
|
return result;
|
|
17
14
|
}
|
|
18
|
-
exports.FormatNumericToParts = FormatNumericToParts;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var ToRawPrecision_1 = require("./ToRawPrecision");
|
|
6
|
-
var utils_1 = require("../utils");
|
|
7
|
-
var ToRawFixed_1 = require("./ToRawFixed");
|
|
1
|
+
import { SameValue } from '../262';
|
|
2
|
+
import { ToRawPrecision } from './ToRawPrecision';
|
|
3
|
+
import { repeat } from '../utils';
|
|
4
|
+
import { ToRawFixed } from './ToRawFixed';
|
|
8
5
|
/**
|
|
9
6
|
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
10
7
|
*/
|
|
11
|
-
function FormatNumericToString(intlObject, x) {
|
|
12
|
-
var isNegative = x < 0 ||
|
|
8
|
+
export function FormatNumericToString(intlObject, x) {
|
|
9
|
+
var isNegative = x < 0 || SameValue(x, -0);
|
|
13
10
|
if (isNegative) {
|
|
14
11
|
x = -x;
|
|
15
12
|
}
|
|
@@ -17,15 +14,15 @@ function FormatNumericToString(intlObject, x) {
|
|
|
17
14
|
var rourndingType = intlObject.roundingType;
|
|
18
15
|
switch (rourndingType) {
|
|
19
16
|
case 'significantDigits':
|
|
20
|
-
result =
|
|
17
|
+
result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
|
|
21
18
|
break;
|
|
22
19
|
case 'fractionDigits':
|
|
23
|
-
result =
|
|
20
|
+
result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
|
|
24
21
|
break;
|
|
25
22
|
default:
|
|
26
|
-
result =
|
|
23
|
+
result = ToRawPrecision(x, 1, 2);
|
|
27
24
|
if (result.integerDigitsCount > 1) {
|
|
28
|
-
result =
|
|
25
|
+
result = ToRawFixed(x, 0, 0);
|
|
29
26
|
}
|
|
30
27
|
break;
|
|
31
28
|
}
|
|
@@ -34,7 +31,7 @@ function FormatNumericToString(intlObject, x) {
|
|
|
34
31
|
var int = result.integerDigitsCount;
|
|
35
32
|
var minInteger = intlObject.minimumIntegerDigits;
|
|
36
33
|
if (int < minInteger) {
|
|
37
|
-
var forwardZeros =
|
|
34
|
+
var forwardZeros = repeat('0', minInteger - int);
|
|
38
35
|
string = forwardZeros + string;
|
|
39
36
|
}
|
|
40
37
|
if (isNegative) {
|
|
@@ -42,4 +39,3 @@ function FormatNumericToString(intlObject, x) {
|
|
|
42
39
|
}
|
|
43
40
|
return { roundedNumber: x, formattedString: string };
|
|
44
41
|
}
|
|
45
|
-
exports.FormatNumericToString = FormatNumericToString;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetUnsignedRoundingMode = void 0;
|
|
4
1
|
var negativeMapping = {
|
|
5
2
|
ceil: 'zero',
|
|
6
3
|
floor: 'infinity',
|
|
@@ -23,10 +20,9 @@ var positiveMapping = {
|
|
|
23
20
|
halfTrunc: 'half-zero',
|
|
24
21
|
halfEven: 'half-even',
|
|
25
22
|
};
|
|
26
|
-
function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
23
|
+
export function GetUnsignedRoundingMode(roundingMode, isNegative) {
|
|
27
24
|
if (isNegative) {
|
|
28
25
|
return negativeMapping[roundingMode];
|
|
29
26
|
}
|
|
30
27
|
return positiveMapping[roundingMode];
|
|
31
28
|
}
|
|
32
|
-
exports.GetUnsignedRoundingMode = GetUnsignedRoundingMode;
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var CurrencyDigits_1 = require("./CurrencyDigits");
|
|
12
|
-
var SetNumberFormatDigitOptions_1 = require("./SetNumberFormatDigitOptions");
|
|
13
|
-
var SetNumberFormatUnitOptions_1 = require("./SetNumberFormatUnitOptions");
|
|
1
|
+
import { ResolveLocale } from '@formatjs/intl-localematcher';
|
|
2
|
+
import { CanonicalizeLocaleList } from '../CanonicalizeLocaleList';
|
|
3
|
+
import { CoerceOptionsToObject } from '../CoerceOptionsToObject';
|
|
4
|
+
import { GetNumberOption } from '../GetNumberOption';
|
|
5
|
+
import { GetOption } from '../GetOption';
|
|
6
|
+
import { GetStringOrBooleanOption } from '../GetStringOrBooleanOption';
|
|
7
|
+
import { invariant } from '../utils';
|
|
8
|
+
import { CurrencyDigits } from './CurrencyDigits';
|
|
9
|
+
import { SetNumberFormatDigitOptions } from './SetNumberFormatDigitOptions';
|
|
10
|
+
import { SetNumberFormatUnitOptions } from './SetNumberFormatUnitOptions';
|
|
14
11
|
var VALID_ROUND_INCREMENT_VALUES = [
|
|
15
12
|
1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000,
|
|
16
13
|
];
|
|
17
14
|
/**
|
|
18
15
|
* https://tc39.es/ecma402/#sec-initializenumberformat
|
|
19
16
|
*/
|
|
20
|
-
function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
17
|
+
export function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
21
18
|
var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, availableLocales = _a.availableLocales, numberingSystemNames = _a.numberingSystemNames, getDefaultLocale = _a.getDefaultLocale, currencyDigitsData = _a.currencyDigitsData;
|
|
22
19
|
// @ts-ignore
|
|
23
|
-
var requestedLocales =
|
|
24
|
-
var options =
|
|
20
|
+
var requestedLocales = CanonicalizeLocaleList(locales);
|
|
21
|
+
var options = CoerceOptionsToObject(opts);
|
|
25
22
|
var opt = Object.create(null);
|
|
26
|
-
var matcher =
|
|
23
|
+
var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
27
24
|
opt.localeMatcher = matcher;
|
|
28
|
-
var numberingSystem =
|
|
25
|
+
var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
|
|
29
26
|
if (numberingSystem !== undefined &&
|
|
30
27
|
numberingSystemNames.indexOf(numberingSystem) < 0) {
|
|
31
28
|
// 8.a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal,
|
|
@@ -33,23 +30,23 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
33
30
|
throw RangeError("Invalid numberingSystems: ".concat(numberingSystem));
|
|
34
31
|
}
|
|
35
32
|
opt.nu = numberingSystem;
|
|
36
|
-
var r =
|
|
33
|
+
var r = ResolveLocale(Array.from(availableLocales), requestedLocales, opt,
|
|
37
34
|
// [[RelevantExtensionKeys]] slot, which is a constant
|
|
38
35
|
['nu'], localeData, getDefaultLocale);
|
|
39
36
|
var dataLocaleData = localeData[r.dataLocale];
|
|
40
|
-
|
|
37
|
+
invariant(!!dataLocaleData, "Missing locale data for ".concat(r.dataLocale));
|
|
41
38
|
var internalSlots = getInternalSlots(nf);
|
|
42
39
|
internalSlots.locale = r.locale;
|
|
43
40
|
internalSlots.dataLocale = r.dataLocale;
|
|
44
41
|
internalSlots.numberingSystem = r.nu;
|
|
45
42
|
internalSlots.dataLocaleData = dataLocaleData;
|
|
46
|
-
|
|
43
|
+
SetNumberFormatUnitOptions(nf, options, { getInternalSlots: getInternalSlots });
|
|
47
44
|
var style = internalSlots.style;
|
|
48
45
|
var mnfdDefault;
|
|
49
46
|
var mxfdDefault;
|
|
50
47
|
if (style === 'currency') {
|
|
51
48
|
var currency = internalSlots.currency;
|
|
52
|
-
var cDigits =
|
|
49
|
+
var cDigits = CurrencyDigits(currency, { currencyDigitsData: currencyDigitsData });
|
|
53
50
|
mnfdDefault = cDigits;
|
|
54
51
|
mxfdDefault = cDigits;
|
|
55
52
|
}
|
|
@@ -57,10 +54,10 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
57
54
|
mnfdDefault = 0;
|
|
58
55
|
mxfdDefault = style === 'percent' ? 0 : 3;
|
|
59
56
|
}
|
|
60
|
-
var notation =
|
|
57
|
+
var notation = GetOption(options, 'notation', 'string', ['standard', 'scientific', 'engineering', 'compact'], 'standard');
|
|
61
58
|
internalSlots.notation = notation;
|
|
62
|
-
|
|
63
|
-
var roundingIncrement =
|
|
59
|
+
SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
|
|
60
|
+
var roundingIncrement = GetNumberOption(options, 'roundingIncrement', 1, 5000, 1);
|
|
64
61
|
if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
|
|
65
62
|
throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
|
|
66
63
|
}
|
|
@@ -73,17 +70,17 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
73
70
|
throw new RangeError('With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.');
|
|
74
71
|
}
|
|
75
72
|
internalSlots.roundingIncrement = roundingIncrement;
|
|
76
|
-
var trailingZeroDisplay =
|
|
73
|
+
var trailingZeroDisplay = GetOption(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
|
|
77
74
|
internalSlots.trailingZeroDisplay = trailingZeroDisplay;
|
|
78
|
-
var compactDisplay =
|
|
75
|
+
var compactDisplay = GetOption(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
|
|
79
76
|
var defaultUseGrouping = 'auto';
|
|
80
77
|
if (notation === 'compact') {
|
|
81
78
|
internalSlots.compactDisplay = compactDisplay;
|
|
82
79
|
defaultUseGrouping = 'min2';
|
|
83
80
|
}
|
|
84
|
-
internalSlots.useGrouping =
|
|
85
|
-
internalSlots.signDisplay =
|
|
86
|
-
internalSlots.roundingMode =
|
|
81
|
+
internalSlots.useGrouping = GetStringOrBooleanOption(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
|
|
82
|
+
internalSlots.signDisplay = GetOption(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
|
|
83
|
+
internalSlots.roundingMode = GetOption(options, 'roundingMode', 'string', [
|
|
87
84
|
'ceil',
|
|
88
85
|
'floor',
|
|
89
86
|
'expand',
|
|
@@ -96,4 +93,3 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
|
|
|
96
93
|
], 'halfExpand');
|
|
97
94
|
return nf;
|
|
98
95
|
}
|
|
99
|
-
exports.InitializeNumberFormat = InitializeNumberFormat;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var FormatNumericToString_1 = require("./FormatNumericToString");
|
|
6
|
-
var _262_1 = require("../262");
|
|
7
|
-
var ComputeExponent_1 = require("./ComputeExponent");
|
|
8
|
-
var format_to_parts_1 = tslib_1.__importDefault(require("./format_to_parts"));
|
|
1
|
+
import { FormatNumericToString } from './FormatNumericToString';
|
|
2
|
+
import { SameValue } from '../262';
|
|
3
|
+
import { ComputeExponent } from './ComputeExponent';
|
|
4
|
+
import formatToParts from './format_to_parts';
|
|
9
5
|
/**
|
|
10
6
|
* https://tc39.es/ecma402/#sec-formatnumberstring
|
|
11
7
|
*/
|
|
12
|
-
function PartitionNumberPattern(numberFormat, x, _a) {
|
|
8
|
+
export function PartitionNumberPattern(numberFormat, x, _a) {
|
|
13
9
|
var _b;
|
|
14
10
|
var getInternalSlots = _a.getInternalSlots;
|
|
15
11
|
var internalSlots = getInternalSlots(numberFormat);
|
|
@@ -26,7 +22,7 @@ function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
26
22
|
n = symbols.infinity;
|
|
27
23
|
}
|
|
28
24
|
else {
|
|
29
|
-
if (!
|
|
25
|
+
if (!SameValue(x, -0)) {
|
|
30
26
|
if (!isFinite(x)) {
|
|
31
27
|
throw new Error('Input must be a mathematical value');
|
|
32
28
|
}
|
|
@@ -34,13 +30,13 @@ function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
34
30
|
x *= 100;
|
|
35
31
|
}
|
|
36
32
|
;
|
|
37
|
-
_b =
|
|
33
|
+
_b = ComputeExponent(numberFormat, x, {
|
|
38
34
|
getInternalSlots: getInternalSlots,
|
|
39
35
|
}), exponent = _b[0], magnitude = _b[1];
|
|
40
36
|
// Preserve more precision by doing multiplication when exponent is negative.
|
|
41
37
|
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
|
|
42
38
|
}
|
|
43
|
-
var formatNumberResult =
|
|
39
|
+
var formatNumberResult = FormatNumericToString(internalSlots, x);
|
|
44
40
|
n = formatNumberResult.formattedString;
|
|
45
41
|
x = formatNumberResult.roundedNumber;
|
|
46
42
|
}
|
|
@@ -53,7 +49,7 @@ function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
53
49
|
sign = 0;
|
|
54
50
|
break;
|
|
55
51
|
case 'auto':
|
|
56
|
-
if (
|
|
52
|
+
if (SameValue(x, 0) || x > 0 || isNaN(x)) {
|
|
57
53
|
sign = 0;
|
|
58
54
|
}
|
|
59
55
|
else {
|
|
@@ -61,7 +57,7 @@ function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
61
57
|
}
|
|
62
58
|
break;
|
|
63
59
|
case 'always':
|
|
64
|
-
if (
|
|
60
|
+
if (SameValue(x, 0) || x > 0 || isNaN(x)) {
|
|
65
61
|
sign = 1;
|
|
66
62
|
}
|
|
67
63
|
else {
|
|
@@ -80,6 +76,5 @@ function PartitionNumberPattern(numberFormat, x, _a) {
|
|
|
80
76
|
sign = -1;
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
|
-
return (
|
|
79
|
+
return formatToParts({ roundedNumber: x, formattedString: n, exponent: exponent, magnitude: magnitude, sign: sign }, internalSlots.dataLocaleData, pl, internalSlots);
|
|
84
80
|
}
|
|
85
|
-
exports.PartitionNumberPattern = PartitionNumberPattern;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
|
|
5
|
-
var CollapseNumberRange_1 = require("./CollapseNumberRange");
|
|
6
|
-
var FormatApproximately_1 = require("./FormatApproximately");
|
|
1
|
+
import { PartitionNumberPattern } from './PartitionNumberPattern';
|
|
2
|
+
import { CollapseNumberRange } from './CollapseNumberRange';
|
|
3
|
+
import { FormatApproximately } from './FormatApproximately';
|
|
7
4
|
/**
|
|
8
5
|
* https://tc39.es/ecma402/#sec-partitionnumberrangepattern
|
|
9
6
|
*/
|
|
10
|
-
function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
7
|
+
export function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
11
8
|
var getInternalSlots = _a.getInternalSlots;
|
|
12
9
|
if (isNaN(x) || isNaN(y)) {
|
|
13
10
|
throw new RangeError('Input must be a number');
|
|
14
11
|
}
|
|
15
12
|
var result = [];
|
|
16
|
-
var xResult =
|
|
17
|
-
var yResult =
|
|
13
|
+
var xResult = PartitionNumberPattern(numberFormat, x, { getInternalSlots: getInternalSlots });
|
|
14
|
+
var yResult = PartitionNumberPattern(numberFormat, y, { getInternalSlots: getInternalSlots });
|
|
18
15
|
if (xResult === yResult) {
|
|
19
|
-
return
|
|
16
|
+
return FormatApproximately(numberFormat, xResult, { getInternalSlots: getInternalSlots });
|
|
20
17
|
}
|
|
21
18
|
for (var _i = 0, xResult_1 = xResult; _i < xResult_1.length; _i++) {
|
|
22
19
|
var r = xResult_1[_i];
|
|
@@ -31,6 +28,5 @@ function PartitionNumberRangePattern(numberFormat, x, y, _a) {
|
|
|
31
28
|
r.source = 'endRange';
|
|
32
29
|
}
|
|
33
30
|
result = result.concat(yResult);
|
|
34
|
-
return
|
|
31
|
+
return CollapseNumberRange(result);
|
|
35
32
|
}
|
|
36
|
-
exports.PartitionNumberRangePattern = PartitionNumberRangePattern;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NumberFormatDigitOptions, NumberFormatNotation
|
|
1
|
+
import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions, NumberFormatNotation } from '../types/number';
|
|
2
2
|
/**
|
|
3
3
|
* https://tc39.es/ecma402/#sec-setnfdigitoptions
|
|
4
4
|
*/
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var GetNumberOption_1 = require("../GetNumberOption");
|
|
5
|
-
var DefaultNumberOption_1 = require("../DefaultNumberOption");
|
|
6
|
-
var GetOption_1 = require("../GetOption");
|
|
1
|
+
import { DefaultNumberOption } from '../DefaultNumberOption';
|
|
2
|
+
import { GetNumberOption } from '../GetNumberOption';
|
|
3
|
+
import { GetOption } from '../GetOption';
|
|
7
4
|
/**
|
|
8
5
|
* https://tc39.es/ecma402/#sec-setnfdigitoptions
|
|
9
6
|
*/
|
|
10
|
-
function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
11
|
-
var mnid =
|
|
7
|
+
export function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
8
|
+
var mnid = GetNumberOption(opts, 'minimumIntegerDigits', 1, 21, 1);
|
|
12
9
|
var mnfd = opts.minimumFractionDigits;
|
|
13
10
|
var mxfd = opts.maximumFractionDigits;
|
|
14
11
|
var mnsd = opts.minimumSignificantDigits;
|
|
15
12
|
var mxsd = opts.maximumSignificantDigits;
|
|
16
13
|
internalSlots.minimumIntegerDigits = mnid;
|
|
17
|
-
var roundingPriority =
|
|
14
|
+
var roundingPriority = GetOption(opts, 'roundingPriority', 'string', ['auto', 'morePrecision', 'lessPrecision'], 'auto');
|
|
18
15
|
var hasSd = mnsd !== undefined || mxsd !== undefined;
|
|
19
16
|
var hasFd = mnfd !== undefined || mxfd !== undefined;
|
|
20
17
|
var needSd = true;
|
|
@@ -27,8 +24,8 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
27
24
|
}
|
|
28
25
|
if (needSd) {
|
|
29
26
|
if (hasSd) {
|
|
30
|
-
mnsd =
|
|
31
|
-
mxsd =
|
|
27
|
+
mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
|
|
28
|
+
mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
|
|
32
29
|
internalSlots.minimumSignificantDigits = mnsd;
|
|
33
30
|
internalSlots.maximumSignificantDigits = mxsd;
|
|
34
31
|
}
|
|
@@ -39,11 +36,10 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
39
36
|
}
|
|
40
37
|
if (needFd) {
|
|
41
38
|
if (hasFd) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
mxfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxfd, 0, 20, undefined);
|
|
39
|
+
mnfd = DefaultNumberOption(mnfd, 0, 20, undefined);
|
|
40
|
+
mxfd = DefaultNumberOption(mxfd, 0, 20, undefined);
|
|
46
41
|
if (mnfd === undefined) {
|
|
42
|
+
// @ts-expect-error
|
|
47
43
|
mnfd = Math.min(mnfdDefault, mxfd);
|
|
48
44
|
}
|
|
49
45
|
else if (mxfd === undefined) {
|
|
@@ -82,4 +78,3 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
82
78
|
internalSlots.maximumSignificantDigits = 2;
|
|
83
79
|
}
|
|
84
80
|
}
|
|
85
|
-
exports.SetNumberFormatDigitOptions = SetNumberFormatDigitOptions;
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var GetOption_1 = require("../GetOption");
|
|
5
|
-
var IsWellFormedCurrencyCode_1 = require("../IsWellFormedCurrencyCode");
|
|
6
|
-
var IsWellFormedUnitIdentifier_1 = require("../IsWellFormedUnitIdentifier");
|
|
1
|
+
import { GetOption } from '../GetOption';
|
|
2
|
+
import { IsWellFormedCurrencyCode } from '../IsWellFormedCurrencyCode';
|
|
3
|
+
import { IsWellFormedUnitIdentifier } from '../IsWellFormedUnitIdentifier';
|
|
7
4
|
/**
|
|
8
5
|
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
|
|
9
6
|
*/
|
|
10
|
-
function SetNumberFormatUnitOptions(nf, options, _a) {
|
|
7
|
+
export function SetNumberFormatUnitOptions(nf, options, _a) {
|
|
11
8
|
if (options === void 0) { options = Object.create(null); }
|
|
12
9
|
var getInternalSlots = _a.getInternalSlots;
|
|
13
10
|
var internalSlots = getInternalSlots(nf);
|
|
14
|
-
var style =
|
|
11
|
+
var style = GetOption(options, 'style', 'string', ['decimal', 'percent', 'currency', 'unit'], 'decimal');
|
|
15
12
|
internalSlots.style = style;
|
|
16
|
-
var currency =
|
|
17
|
-
if (currency !== undefined && !
|
|
13
|
+
var currency = GetOption(options, 'currency', 'string', undefined, undefined);
|
|
14
|
+
if (currency !== undefined && !IsWellFormedCurrencyCode(currency)) {
|
|
18
15
|
throw RangeError('Malformed currency code');
|
|
19
16
|
}
|
|
20
17
|
if (style === 'currency' && currency === undefined) {
|
|
21
18
|
throw TypeError('currency cannot be undefined');
|
|
22
19
|
}
|
|
23
|
-
var currencyDisplay =
|
|
24
|
-
var currencySign =
|
|
25
|
-
var unit =
|
|
26
|
-
if (unit !== undefined && !
|
|
20
|
+
var currencyDisplay = GetOption(options, 'currencyDisplay', 'string', ['code', 'symbol', 'narrowSymbol', 'name'], 'symbol');
|
|
21
|
+
var currencySign = GetOption(options, 'currencySign', 'string', ['standard', 'accounting'], 'standard');
|
|
22
|
+
var unit = GetOption(options, 'unit', 'string', undefined, undefined);
|
|
23
|
+
if (unit !== undefined && !IsWellFormedUnitIdentifier(unit)) {
|
|
27
24
|
throw RangeError('Invalid unit argument for Intl.NumberFormat()');
|
|
28
25
|
}
|
|
29
26
|
if (style === 'unit' && unit === undefined) {
|
|
30
27
|
throw TypeError('unit cannot be undefined');
|
|
31
28
|
}
|
|
32
|
-
var unitDisplay =
|
|
29
|
+
var unitDisplay = GetOption(options, 'unitDisplay', 'string', ['short', 'narrow', 'long'], 'short');
|
|
33
30
|
if (style === 'currency') {
|
|
34
31
|
internalSlots.currency = currency.toUpperCase();
|
|
35
32
|
internalSlots.currencyDisplay = currencyDisplay;
|
|
@@ -40,4 +37,3 @@ function SetNumberFormatUnitOptions(nf, options, _a) {
|
|
|
40
37
|
internalSlots.unitDisplay = unitDisplay;
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
exports.SetNumberFormatUnitOptions = SetNumberFormatUnitOptions;
|