@formatjs/ecma402-abstract 2.3.6 → 3.0.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.
- package/262.d.ts +1 -1
- package/262.js +42 -68
- package/CanonicalizeLocaleList.js +1 -4
- package/CanonicalizeTimeZoneName.js +1 -4
- package/CoerceOptionsToObject.js +3 -6
- package/DefaultNumberOption.js +1 -4
- package/GetNumberOption.js +3 -6
- package/GetOption.js +3 -6
- package/GetOptionsObject.js +1 -4
- package/GetStringOrBooleanOption.js +3 -6
- package/IsSanctionedSimpleUnitIdentifier.js +5 -10
- package/IsValidTimeZoneName.js +1 -4
- package/IsWellFormedCurrencyCode.js +1 -4
- package/IsWellFormedUnitIdentifier.js +5 -8
- package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
- package/NumberFormat/ApplyUnsignedRoundingMode.js +5 -8
- package/NumberFormat/CollapseNumberRange.d.ts +1 -1
- package/NumberFormat/CollapseNumberRange.js +1 -4
- package/NumberFormat/ComputeExponent.d.ts +2 -2
- package/NumberFormat/ComputeExponent.js +8 -12
- package/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -2
- package/NumberFormat/ComputeExponentForMagnitude.js +6 -10
- package/NumberFormat/CurrencyDigits.js +3 -6
- package/NumberFormat/FormatApproximately.d.ts +1 -1
- package/NumberFormat/FormatApproximately.js +1 -4
- package/NumberFormat/FormatNumeric.d.ts +2 -2
- package/NumberFormat/FormatNumeric.js +3 -6
- package/NumberFormat/FormatNumericRange.d.ts +2 -2
- package/NumberFormat/FormatNumericRange.js +3 -6
- package/NumberFormat/FormatNumericRangeToParts.d.ts +2 -2
- package/NumberFormat/FormatNumericRangeToParts.js +3 -6
- package/NumberFormat/FormatNumericToParts.d.ts +2 -2
- package/NumberFormat/FormatNumericToParts.js +5 -8
- package/NumberFormat/FormatNumericToString.d.ts +2 -2
- package/NumberFormat/FormatNumericToString.js +16 -19
- package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
- package/NumberFormat/GetUnsignedRoundingMode.js +1 -4
- package/NumberFormat/InitializeNumberFormat.d.ts +1 -1
- package/NumberFormat/InitializeNumberFormat.js +23 -26
- package/NumberFormat/PartitionNumberPattern.d.ts +2 -2
- package/NumberFormat/PartitionNumberPattern.js +12 -16
- package/NumberFormat/PartitionNumberRangePattern.d.ts +2 -2
- package/NumberFormat/PartitionNumberRangePattern.js +12 -15
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
- package/NumberFormat/SetNumberFormatDigitOptions.js +18 -21
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts +1 -1
- package/NumberFormat/SetNumberFormatUnitOptions.js +15 -18
- package/NumberFormat/ToRawFixed.d.ts +2 -2
- package/NumberFormat/ToRawFixed.js +10 -14
- package/NumberFormat/ToRawPrecision.d.ts +2 -2
- package/NumberFormat/ToRawPrecision.js +19 -23
- package/NumberFormat/digit-mapping.generated.js +1 -4
- package/NumberFormat/format_to_parts.d.ts +2 -2
- package/NumberFormat/format_to_parts.js +18 -22
- package/PartitionPattern.js +3 -6
- package/SupportedLocales.js +8 -11
- package/ToIntlMathematicalValue.d.ts +1 -1
- package/ToIntlMathematicalValue.js +12 -16
- package/constants.d.ts +1 -1
- package/constants.js +4 -8
- package/data.js +3 -6
- package/index.d.ts +47 -47
- package/index.js +45 -66
- package/package.json +7 -5
- package/regex.generated.js +1 -4
- package/types/core.js +1 -2
- package/types/date-time.js +2 -5
- package/types/displaynames.d.ts +1 -1
- package/types/displaynames.js +1 -2
- package/types/list.d.ts +1 -1
- package/types/list.js +1 -2
- package/types/number.d.ts +3 -3
- package/types/number.js +1 -2
- package/types/plural-rules.d.ts +2 -2
- package/types/plural-rules.js +1 -2
- package/types/relative-time.d.ts +2 -2
- package/types/relative-time.js +1 -2
- package/utils.js +28 -40
- package/lib/262.d.ts +0 -93
- package/lib/262.js +0 -400
- package/lib/CanonicalizeLocaleList.d.ts +0 -5
- package/lib/CanonicalizeLocaleList.js +0 -8
- package/lib/CanonicalizeTimeZoneName.d.ts +0 -8
- package/lib/CanonicalizeTimeZoneName.js +0 -17
- package/lib/CoerceOptionsToObject.d.ts +0 -6
- package/lib/CoerceOptionsToObject.js +0 -12
- package/lib/DefaultNumberOption.d.ts +0 -8
- package/lib/DefaultNumberOption.js +0 -18
- package/lib/GetNumberOption.d.ts +0 -9
- package/lib/GetNumberOption.js +0 -13
- package/lib/GetOption.d.ts +0 -9
- package/lib/GetOption.js +0 -31
- package/lib/GetOptionsObject.d.ts +0 -6
- package/lib/GetOptionsObject.js +0 -14
- package/lib/GetStringOrBooleanOption.d.ts +0 -10
- package/lib/GetStringOrBooleanOption.js +0 -31
- package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +0 -13
- package/lib/IsSanctionedSimpleUnitIdentifier.js +0 -63
- package/lib/IsValidTimeZoneName.d.ts +0 -9
- package/lib/IsValidTimeZoneName.js +0 -17
- package/lib/IsWellFormedCurrencyCode.d.ts +0 -4
- package/lib/IsWellFormedCurrencyCode.js +0 -21
- package/lib/IsWellFormedUnitIdentifier.d.ts +0 -5
- package/lib/IsWellFormedUnitIdentifier.js +0 -28
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts +0 -3
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +0 -33
- package/lib/NumberFormat/CollapseNumberRange.d.ts +0 -8
- package/lib/NumberFormat/CollapseNumberRange.js +0 -50
- package/lib/NumberFormat/ComputeExponent.d.ts +0 -10
- package/lib/NumberFormat/ComputeExponent.js +0 -34
- package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -8
- package/lib/NumberFormat/ComputeExponentForMagnitude.js +0 -65
- package/lib/NumberFormat/CurrencyDigits.d.ts +0 -6
- package/lib/NumberFormat/CurrencyDigits.js +0 -10
- package/lib/NumberFormat/FormatApproximately.d.ts +0 -5
- package/lib/NumberFormat/FormatApproximately.js +0 -9
- package/lib/NumberFormat/FormatNumeric.d.ts +0 -3
- package/lib/NumberFormat/FormatNumeric.js +0 -5
- package/lib/NumberFormat/FormatNumericRange.d.ts +0 -8
- package/lib/NumberFormat/FormatNumericRange.js +0 -11
- package/lib/NumberFormat/FormatNumericRangeToParts.d.ts +0 -8
- package/lib/NumberFormat/FormatNumericRangeToParts.js +0 -16
- package/lib/NumberFormat/FormatNumericToParts.d.ts +0 -5
- package/lib/NumberFormat/FormatNumericToParts.js +0 -14
- package/lib/NumberFormat/FormatNumericToString.d.ts +0 -9
- package/lib/NumberFormat/FormatNumericToString.js +0 -84
- package/lib/NumberFormat/GetUnsignedRoundingMode.d.ts +0 -2
- package/lib/NumberFormat/GetUnsignedRoundingMode.js +0 -28
- package/lib/NumberFormat/InitializeNumberFormat.d.ts +0 -12
- package/lib/NumberFormat/InitializeNumberFormat.js +0 -66
- package/lib/NumberFormat/PartitionNumberPattern.d.ts +0 -6
- package/lib/NumberFormat/PartitionNumberPattern.js +0 -126
- package/lib/NumberFormat/PartitionNumberRangePattern.d.ts +0 -8
- package/lib/NumberFormat/PartitionNumberRangePattern.js +0 -40
- package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -5
- package/lib/NumberFormat/SetNumberFormatDigitOptions.js +0 -179
- package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -5
- package/lib/NumberFormat/SetNumberFormatUnitOptions.js +0 -50
- package/lib/NumberFormat/ToRawFixed.d.ts +0 -9
- package/lib/NumberFormat/ToRawFixed.js +0 -119
- package/lib/NumberFormat/ToRawPrecision.d.ts +0 -9
- package/lib/NumberFormat/ToRawPrecision.js +0 -148
- package/lib/NumberFormat/digit-mapping.generated.d.ts +0 -1
- package/lib/NumberFormat/digit-mapping.generated.js +0 -782
- package/lib/NumberFormat/format_to_parts.d.ts +0 -24
- package/lib/NumberFormat/format_to_parts.js +0 -447
- package/lib/PartitionPattern.d.ts +0 -9
- package/lib/PartitionPattern.js +0 -36
- package/lib/SupportedLocales.d.ts +0 -9
- package/lib/SupportedLocales.js +0 -20
- package/lib/ToIntlMathematicalValue.d.ts +0 -2
- package/lib/ToIntlMathematicalValue.js +0 -27
- package/lib/constants.d.ts +0 -4
- package/lib/constants.js +0 -4
- package/lib/data.d.ts +0 -5
- package/lib/data.js +0 -13
- package/lib/index.d.ts +0 -47
- package/lib/index.js +0 -45
- package/lib/regex.generated.d.ts +0 -1
- package/lib/regex.generated.js +0 -2
- package/lib/types/core.d.ts +0 -10
- package/lib/types/core.js +0 -1
- package/lib/types/date-time.d.ts +0 -135
- package/lib/types/date-time.js +0 -6
- package/lib/types/displaynames.d.ts +0 -65
- package/lib/types/displaynames.js +0 -1
- package/lib/types/list.d.ts +0 -18
- package/lib/types/list.js +0 -1
- package/lib/types/number.d.ts +0 -173
- package/lib/types/number.js +0 -1
- package/lib/types/plural-rules.d.ts +0 -16
- package/lib/types/plural-rules.js +0 -1
- package/lib/types/relative-time.d.ts +0 -40
- package/lib/types/relative-time.js +0 -1
- package/lib/utils.d.ts +0 -30
- package/lib/utils.js +0 -135
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var GetNumberOption_1 = require("../GetNumberOption");
|
|
6
|
-
var GetOption_1 = require("../GetOption");
|
|
7
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { DefaultNumberOption } from '../DefaultNumberOption.js';
|
|
2
|
+
import { GetNumberOption } from '../GetNumberOption.js';
|
|
3
|
+
import { GetOption } from '../GetOption.js';
|
|
4
|
+
import { invariant } from '../utils.js';
|
|
8
5
|
//IMPL: Valid rounding increments as per implementation
|
|
9
6
|
var VALID_ROUNDING_INCREMENTS = new Set([
|
|
10
7
|
1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000,
|
|
@@ -12,9 +9,9 @@ var VALID_ROUNDING_INCREMENTS = new Set([
|
|
|
12
9
|
/**
|
|
13
10
|
* https://tc39.es/ecma402/#sec-setnfdigitoptions
|
|
14
11
|
*/
|
|
15
|
-
function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
12
|
+
export function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
|
|
16
13
|
// 1. Let mnid be ? GetNumberOption(opts, "minimumIntegerDigits", 1, 21, 1).
|
|
17
|
-
var mnid =
|
|
14
|
+
var mnid = GetNumberOption(opts, 'minimumIntegerDigits', 1, 21, 1);
|
|
18
15
|
// 2. Let mnfd be opts.[[MinimumFractionDigits]].
|
|
19
16
|
var mnfd = opts.minimumFractionDigits;
|
|
20
17
|
// 3. Let mxfd be opts.[[MaximumFractionDigits]].
|
|
@@ -26,11 +23,11 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
26
23
|
// 6. Set internalSlots.[[MinimumIntegerDigits]] to mnid.
|
|
27
24
|
internalSlots.minimumIntegerDigits = mnid;
|
|
28
25
|
// 7. Let roundingIncrement be ? GetNumberOption(opts, "roundingIncrement", 1, 5000, 1).
|
|
29
|
-
var roundingIncrement =
|
|
26
|
+
var roundingIncrement = GetNumberOption(opts, 'roundingIncrement', 1, 5000, 1);
|
|
30
27
|
// 8. If roundingIncrement is not an element of the list {1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000}, throw a RangeError exception.
|
|
31
|
-
|
|
28
|
+
invariant(VALID_ROUNDING_INCREMENTS.has(roundingIncrement), "Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(Array.from(VALID_ROUNDING_INCREMENTS).join(', '), "."));
|
|
32
29
|
// 9. Let roundingMode be ? GetOption(opts, "roundingMode", "string", « "ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven" », "halfExpand").
|
|
33
|
-
var roundingMode =
|
|
30
|
+
var roundingMode = GetOption(opts, 'roundingMode', 'string', [
|
|
34
31
|
'ceil',
|
|
35
32
|
'floor',
|
|
36
33
|
'expand',
|
|
@@ -42,9 +39,9 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
42
39
|
'halfEven',
|
|
43
40
|
], 'halfExpand');
|
|
44
41
|
// 10. Let roundingPriority be ? GetOption(opts, "roundingPriority", "string", « "auto", "morePrecision", "lessPrecision" », "auto").
|
|
45
|
-
var roundingPriority =
|
|
42
|
+
var roundingPriority = GetOption(opts, 'roundingPriority', 'string', ['auto', 'morePrecision', 'lessPrecision'], 'auto');
|
|
46
43
|
// 11. Let trailingZeroDisplay be ? GetOption(opts, "trailingZeroDisplay", "string", « "auto", "stripIfInteger" », "auto").
|
|
47
|
-
var trailingZeroDisplay =
|
|
44
|
+
var trailingZeroDisplay = GetOption(opts, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
|
|
48
45
|
// 12. If roundingIncrement is not 1, then
|
|
49
46
|
if (roundingIncrement !== 1) {
|
|
50
47
|
// 12.a. Set mxfdDefault to mnfdDefault.
|
|
@@ -79,9 +76,9 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
79
76
|
// 21.a. If hasSd is true, then
|
|
80
77
|
if (hasSd) {
|
|
81
78
|
// 21.a.i. Set internalSlots.[[MinimumSignificantDigits]] to ? DefaultNumberOption(mnsd, 1, 21, 1).
|
|
82
|
-
internalSlots.minimumSignificantDigits =
|
|
79
|
+
internalSlots.minimumSignificantDigits = DefaultNumberOption(mnsd, 1, 21, 1);
|
|
83
80
|
// 21.a.ii. Set internalSlots.[[MaximumSignificantDigits]] to ? DefaultNumberOption(mxsd, internalSlots.[[MinimumSignificantDigits]], 21, 21).
|
|
84
|
-
internalSlots.maximumSignificantDigits =
|
|
81
|
+
internalSlots.maximumSignificantDigits = DefaultNumberOption(mxsd, internalSlots.minimumSignificantDigits, 21, 21);
|
|
85
82
|
}
|
|
86
83
|
else {
|
|
87
84
|
// 21.b. Else,
|
|
@@ -96,13 +93,13 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
96
93
|
// 22.a. If hasFd is true, then
|
|
97
94
|
if (hasFd) {
|
|
98
95
|
// 22.a.i. Set mnfd to ? DefaultNumberOption(mnfd, 0, 100, undefined).
|
|
99
|
-
mnfd =
|
|
96
|
+
mnfd = DefaultNumberOption(mnfd, 0, 100, undefined);
|
|
100
97
|
// 22.a.ii. Set mxfd to ? DefaultNumberOption(mxfd, 0, 100, undefined).
|
|
101
|
-
mxfd =
|
|
98
|
+
mxfd = DefaultNumberOption(mxfd, 0, 100, undefined);
|
|
102
99
|
// 22.a.iii. If mnfd is undefined, then
|
|
103
100
|
if (mnfd === undefined) {
|
|
104
101
|
// 22.a.iii.1. Assert: mxfd is not undefined.
|
|
105
|
-
|
|
102
|
+
invariant(mxfd !== undefined, 'maximumFractionDigits must be defined');
|
|
106
103
|
// 22.a.iii.2. Set mnfd to min(mnfdDefault, mxfd).
|
|
107
104
|
mnfd = Math.min(mnfdDefault, mxfd);
|
|
108
105
|
}
|
|
@@ -174,9 +171,9 @@ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefau
|
|
|
174
171
|
// 28. If roundingIncrement is not 1, then
|
|
175
172
|
if (roundingIncrement !== 1) {
|
|
176
173
|
// 28.a. Assert: internalSlots.[[RoundingType]] is "fractionDigits".
|
|
177
|
-
|
|
174
|
+
invariant(internalSlots.roundingType === 'fractionDigits', 'Invalid roundingType', TypeError);
|
|
178
175
|
// 28.b. Assert: internalSlots.[[MaximumFractionDigits]] is equal to internalSlots.[[MinimumFractionDigits]].
|
|
179
|
-
|
|
176
|
+
invariant(internalSlots.maximumFractionDigits ===
|
|
180
177
|
internalSlots.minimumFractionDigits, 'With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.', RangeError);
|
|
181
178
|
}
|
|
182
179
|
}
|
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var IsWellFormedCurrencyCode_1 = require("../IsWellFormedCurrencyCode");
|
|
6
|
-
var IsWellFormedUnitIdentifier_1 = require("../IsWellFormedUnitIdentifier");
|
|
7
|
-
var utils_1 = require("../utils");
|
|
1
|
+
import { GetOption } from '../GetOption.js';
|
|
2
|
+
import { IsWellFormedCurrencyCode } from '../IsWellFormedCurrencyCode.js';
|
|
3
|
+
import { IsWellFormedUnitIdentifier } from '../IsWellFormedUnitIdentifier.js';
|
|
4
|
+
import { invariant } from '../utils.js';
|
|
8
5
|
/**
|
|
9
6
|
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
|
|
10
7
|
*/
|
|
11
|
-
function SetNumberFormatUnitOptions(internalSlots, options) {
|
|
8
|
+
export function SetNumberFormatUnitOptions(internalSlots, options) {
|
|
12
9
|
if (options === void 0) { options = Object.create(null); }
|
|
13
10
|
// 1. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal").
|
|
14
|
-
var style =
|
|
11
|
+
var style = GetOption(options, 'style', 'string', ['decimal', 'percent', 'currency', 'unit'], 'decimal');
|
|
15
12
|
// 2. Set internalSlots.[[Style]] to style.
|
|
16
13
|
internalSlots.style = style;
|
|
17
14
|
// 3. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
|
|
18
|
-
var currency =
|
|
15
|
+
var currency = GetOption(options, 'currency', 'string', undefined, undefined);
|
|
19
16
|
// 4. If currency is not undefined, then
|
|
20
17
|
// a. If the result of IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception.
|
|
21
|
-
|
|
18
|
+
invariant(currency === undefined || IsWellFormedCurrencyCode(currency), 'Malformed currency code', RangeError);
|
|
22
19
|
// 5. If style is "currency" and currency is undefined, throw a TypeError exception.
|
|
23
|
-
|
|
20
|
+
invariant(style !== 'currency' || currency !== undefined, 'currency cannot be undefined', TypeError);
|
|
24
21
|
// 6. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
|
|
25
|
-
var currencyDisplay =
|
|
22
|
+
var currencyDisplay = GetOption(options, 'currencyDisplay', 'string', ['code', 'symbol', 'narrowSymbol', 'name'], 'symbol');
|
|
26
23
|
// 7. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard").
|
|
27
|
-
var currencySign =
|
|
24
|
+
var currencySign = GetOption(options, 'currencySign', 'string', ['standard', 'accounting'], 'standard');
|
|
28
25
|
// 8. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
|
|
29
|
-
var unit =
|
|
26
|
+
var unit = GetOption(options, 'unit', 'string', undefined, undefined);
|
|
30
27
|
// 9. If unit is not undefined, then
|
|
31
28
|
// a. If the result of IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception.
|
|
32
|
-
|
|
29
|
+
invariant(unit === undefined || IsWellFormedUnitIdentifier(unit), 'Invalid unit argument for Intl.NumberFormat()', RangeError);
|
|
33
30
|
// 10. If style is "unit" and unit is undefined, throw a TypeError exception.
|
|
34
|
-
|
|
31
|
+
invariant(style !== 'unit' || unit !== undefined, 'unit cannot be undefined', TypeError);
|
|
35
32
|
// 11. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
|
|
36
|
-
var unitDisplay =
|
|
33
|
+
var unitDisplay = GetOption(options, 'unitDisplay', 'string', ['short', 'narrow', 'long'], 'short');
|
|
37
34
|
// 12. If style is "currency", then
|
|
38
35
|
if (style === 'currency') {
|
|
39
36
|
// a. Set internalSlots.[[Currency]] to the result of converting currency to upper case as specified in 6.1.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { RawNumberFormatResult, UnsignedRoundingModeType } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { RawNumberFormatResult, UnsignedRoundingModeType } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://tc39.es/ecma402/#sec-torawfixed
|
|
5
5
|
* @param x a finite non-negative Number or BigInt
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
6
|
-
var utils_1 = require("../utils");
|
|
7
|
-
var ApplyUnsignedRoundingMode_1 = require("./ApplyUnsignedRoundingMode");
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { repeat } from '../utils.js';
|
|
3
|
+
import { ApplyUnsignedRoundingMode } from './ApplyUnsignedRoundingMode.js';
|
|
8
4
|
//IMPL: Setting Decimal configuration
|
|
9
|
-
|
|
5
|
+
Decimal.set({
|
|
10
6
|
toExpPos: 100,
|
|
11
7
|
});
|
|
12
8
|
//IMPL: Helper function to calculate raw fixed value
|
|
13
9
|
function ToRawFixedFn(n, f) {
|
|
14
|
-
return n.times(
|
|
10
|
+
return n.times(Decimal.pow(10, -f));
|
|
15
11
|
}
|
|
16
12
|
//IMPL: Helper function to find n1 and r1
|
|
17
13
|
function findN1R1(x, f, roundingIncrement) {
|
|
18
|
-
var nx = x.times(
|
|
14
|
+
var nx = x.times(Decimal.pow(10, f)).floor();
|
|
19
15
|
var n1 = nx.div(roundingIncrement).floor().times(roundingIncrement);
|
|
20
16
|
var r1 = ToRawFixedFn(n1, f);
|
|
21
17
|
return {
|
|
@@ -25,7 +21,7 @@ function findN1R1(x, f, roundingIncrement) {
|
|
|
25
21
|
}
|
|
26
22
|
//IMPL: Helper function to find n2 and r2
|
|
27
23
|
function findN2R2(x, f, roundingIncrement) {
|
|
28
|
-
var nx = x.times(
|
|
24
|
+
var nx = x.times(Decimal.pow(10, f)).ceil();
|
|
29
25
|
var n2 = nx.div(roundingIncrement).ceil().times(roundingIncrement);
|
|
30
26
|
var r2 = ToRawFixedFn(n2, f);
|
|
31
27
|
return {
|
|
@@ -39,7 +35,7 @@ function findN2R2(x, f, roundingIncrement) {
|
|
|
39
35
|
* @param minFraction an integer between 0 and 20
|
|
40
36
|
* @param maxFraction an integer between 0 and 20
|
|
41
37
|
*/
|
|
42
|
-
function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
|
|
38
|
+
export function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
|
|
43
39
|
// 1. Let f be maxFraction.
|
|
44
40
|
var f = maxFraction;
|
|
45
41
|
// 2. Let n1 and r1 be the results of performing the maximized rounding of x to f fraction digits.
|
|
@@ -47,7 +43,7 @@ function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoun
|
|
|
47
43
|
// 3. Let n2 and r2 be the results of performing the minimized rounding of x to f fraction digits.
|
|
48
44
|
var _b = findN2R2(x, f, roundingIncrement), n2 = _b.n2, r2 = _b.r2;
|
|
49
45
|
// 4. Let r be ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode).
|
|
50
|
-
var r =
|
|
46
|
+
var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
|
|
51
47
|
var n, xFinal;
|
|
52
48
|
var m;
|
|
53
49
|
// 5. If r is equal to r1, then
|
|
@@ -80,7 +76,7 @@ function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoun
|
|
|
80
76
|
// b. If k < f, then
|
|
81
77
|
if (k <= f) {
|
|
82
78
|
// i. Let z be the String value consisting of f + 1 - k occurrences of the character "0".
|
|
83
|
-
var z =
|
|
79
|
+
var z = repeat('0', f - k + 1);
|
|
84
80
|
// ii. Set m to the string-concatenation of z and m.
|
|
85
81
|
m = z + m;
|
|
86
82
|
// iii. Set k to f + 1.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { RawNumberFormatResult, UnsignedRoundingModeType } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { RawNumberFormatResult, UnsignedRoundingModeType } from '../types/number.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://tc39.es/ecma402/#sec-torawprecision
|
|
5
5
|
* @param x a finite non-negative Number or BigInt
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
6
|
-
var constants_1 = require("../constants");
|
|
7
|
-
var utils_1 = require("../utils");
|
|
8
|
-
var ApplyUnsignedRoundingMode_1 = require("./ApplyUnsignedRoundingMode");
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { ZERO } from '../constants.js';
|
|
3
|
+
import { invariant, repeat } from '../utils.js';
|
|
4
|
+
import { ApplyUnsignedRoundingMode } from './ApplyUnsignedRoundingMode.js';
|
|
9
5
|
//IMPL: Helper function to find n1, e1, and r1
|
|
10
6
|
function findN1E1R1(x, p) {
|
|
11
|
-
var maxN1 =
|
|
12
|
-
var minN1 =
|
|
7
|
+
var maxN1 = Decimal.pow(10, p);
|
|
8
|
+
var minN1 = Decimal.pow(10, p - 1);
|
|
13
9
|
var maxE1 = x.div(minN1).log(10).plus(p).minus(1).ceil();
|
|
14
10
|
var currentE1 = maxE1;
|
|
15
11
|
while (true) {
|
|
16
|
-
var currentN1 = x.div(
|
|
12
|
+
var currentN1 = x.div(Decimal.pow(10, currentE1.minus(p).plus(1))).floor();
|
|
17
13
|
if (currentN1.lessThan(maxN1) && currentN1.greaterThanOrEqualTo(minN1)) {
|
|
18
|
-
var currentR1 = currentN1.times(
|
|
14
|
+
var currentR1 = currentN1.times(Decimal.pow(10, currentE1.minus(p).plus(1)));
|
|
19
15
|
if (currentR1.lessThanOrEqualTo(x)) {
|
|
20
16
|
return {
|
|
21
17
|
n1: currentN1,
|
|
@@ -29,14 +25,14 @@ function findN1E1R1(x, p) {
|
|
|
29
25
|
}
|
|
30
26
|
//IMPL: Helper function to find n2, e2, and r2
|
|
31
27
|
function findN2E2R2(x, p) {
|
|
32
|
-
var maxN2 =
|
|
33
|
-
var minN2 =
|
|
28
|
+
var maxN2 = Decimal.pow(10, p);
|
|
29
|
+
var minN2 = Decimal.pow(10, p - 1);
|
|
34
30
|
var minE2 = x.div(maxN2).log(10).plus(p).minus(1).floor();
|
|
35
31
|
var currentE2 = minE2;
|
|
36
32
|
while (true) {
|
|
37
|
-
var currentN2 = x.div(
|
|
33
|
+
var currentN2 = x.div(Decimal.pow(10, currentE2.minus(p).plus(1))).ceil();
|
|
38
34
|
if (currentN2.lessThan(maxN2) && currentN2.greaterThanOrEqualTo(minN2)) {
|
|
39
|
-
var currentR2 = currentN2.times(
|
|
35
|
+
var currentR2 = currentN2.times(Decimal.pow(10, currentE2.minus(p).plus(1)));
|
|
40
36
|
if (currentR2.greaterThanOrEqualTo(x)) {
|
|
41
37
|
return {
|
|
42
38
|
n2: currentN2,
|
|
@@ -54,7 +50,7 @@ function findN2E2R2(x, p) {
|
|
|
54
50
|
* @param minPrecision an integer between 1 and 21
|
|
55
51
|
* @param maxPrecision an integer between 1 and 21
|
|
56
52
|
*/
|
|
57
|
-
function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
53
|
+
export function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
58
54
|
// 1. Let p be maxPrecision.
|
|
59
55
|
var p = maxPrecision;
|
|
60
56
|
var m;
|
|
@@ -63,11 +59,11 @@ function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
|
63
59
|
// 2. If x = 0, then
|
|
64
60
|
if (x.isZero()) {
|
|
65
61
|
// a. Let m be the String value consisting of p occurrences of the character "0".
|
|
66
|
-
m =
|
|
62
|
+
m = repeat('0', p);
|
|
67
63
|
// b. Let e be 0.
|
|
68
64
|
e = 0;
|
|
69
65
|
// c. Let xFinal be 0.
|
|
70
|
-
xFinal =
|
|
66
|
+
xFinal = ZERO;
|
|
71
67
|
}
|
|
72
68
|
else {
|
|
73
69
|
// 3. Else,
|
|
@@ -76,7 +72,7 @@ function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
|
76
72
|
// b. Let {n2, e2, r2} be the result of findN2E2R2(x, p).
|
|
77
73
|
var _b = findN2E2R2(x, p), n2 = _b.n2, e2 = _b.e2, r2 = _b.r2;
|
|
78
74
|
// c. Let r be ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode).
|
|
79
|
-
var r =
|
|
75
|
+
var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
|
|
80
76
|
var n
|
|
81
77
|
// d. If r = r1, then
|
|
82
78
|
= void 0;
|
|
@@ -105,7 +101,7 @@ function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
|
105
101
|
// 4. If e ≥ p - 1, then
|
|
106
102
|
if (e >= p - 1) {
|
|
107
103
|
// a. Let m be the string-concatenation of m and p - 1 - e occurrences of the character "0".
|
|
108
|
-
m = m +
|
|
104
|
+
m = m + repeat('0', e - p + 1);
|
|
109
105
|
// b. Let int be e + 1.
|
|
110
106
|
int = e + 1;
|
|
111
107
|
}
|
|
@@ -119,9 +115,9 @@ function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
|
119
115
|
else {
|
|
120
116
|
// 6. Else,
|
|
121
117
|
// a. Assert: e < 0.
|
|
122
|
-
|
|
118
|
+
invariant(e < 0, 'e should be less than 0');
|
|
123
119
|
// b. Let m be the string-concatenation of "0.", -e - 1 occurrences of the character "0", and m.
|
|
124
|
-
m = '0.' +
|
|
120
|
+
m = '0.' + repeat('0', -e - 1) + m;
|
|
125
121
|
// c. Let int be 1.
|
|
126
122
|
int = 1;
|
|
127
123
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { NumberFormatLocaleInternalData, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsNotation, NumberFormatOptionsStyle, NumberFormatOptionsUnitDisplay, NumberFormatPart, RoundingModeType, UseGroupingType } from '../types/number';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { NumberFormatLocaleInternalData, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsNotation, NumberFormatOptionsStyle, NumberFormatOptionsUnitDisplay, NumberFormatPart, RoundingModeType, UseGroupingType } from '../types/number.js';
|
|
3
3
|
interface NumberResult {
|
|
4
4
|
formattedString: string;
|
|
5
5
|
roundedNumber: Decimal;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var regex_generated_1 = require("../regex.generated");
|
|
7
|
-
var digit_mapping_generated_1 = require("./digit-mapping.generated");
|
|
8
|
-
var GetUnsignedRoundingMode_1 = require("./GetUnsignedRoundingMode");
|
|
9
|
-
var ToRawFixed_1 = require("./ToRawFixed");
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { S_UNICODE_REGEX } from '../regex.generated.js';
|
|
3
|
+
import { digitMapping } from './digit-mapping.generated.js';
|
|
4
|
+
import { GetUnsignedRoundingMode } from './GetUnsignedRoundingMode.js';
|
|
5
|
+
import { ToRawFixed } from './ToRawFixed.js';
|
|
10
6
|
// This is from: unicode-12.1.0/General_Category/Symbol/regex.js
|
|
11
7
|
// IE11 does not support unicode flag, otherwise this is just /\p{S}/u.
|
|
12
8
|
// /^\p{S}/u
|
|
13
|
-
var CARET_S_UNICODE_REGEX = new RegExp("^".concat(
|
|
9
|
+
var CARET_S_UNICODE_REGEX = new RegExp("^".concat(S_UNICODE_REGEX.source));
|
|
14
10
|
// /\p{S}$/u
|
|
15
|
-
var S_DOLLAR_UNICODE_REGEX = new RegExp("".concat(
|
|
16
|
-
var CLDR_NUMBER_PATTERN = /[#0](?:[
|
|
17
|
-
function formatToParts(numberResult, data, pl, options) {
|
|
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) {
|
|
18
14
|
var _a;
|
|
19
15
|
var sign = numberResult.sign, exponent = numberResult.exponent, magnitude = numberResult.magnitude;
|
|
20
16
|
var notation = options.notation, style = options.style, numberingSystem = options.numberingSystem;
|
|
@@ -110,7 +106,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
110
106
|
}
|
|
111
107
|
}
|
|
112
108
|
// The following tokens are special: `{0}`, `¤`, `%`, `-`, `+`, `{c:...}.
|
|
113
|
-
var numberPatternParts = numberPattern.split(/({c:[^}]+}|\{0\}|[
|
|
109
|
+
var numberPatternParts = numberPattern.split(/({c:[^}]+}|\{0\}|[¤%\-+])/g);
|
|
114
110
|
var numberParts = [];
|
|
115
111
|
var symbols = data.numbers.symbols[numberingSystem] ||
|
|
116
112
|
data.numbers.symbols[defaultNumberingSystem];
|
|
@@ -124,7 +120,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
124
120
|
// We only need to handle scientific and engineering notation here.
|
|
125
121
|
numberParts.push.apply(numberParts, partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
126
122
|
// If compact number pattern exists, do not insert group separators.
|
|
127
|
-
!compactNumberPattern && ((_a = options.useGrouping) !== null && _a !== void 0 ? _a : true), decimalNumberPattern, style, options.roundingIncrement,
|
|
123
|
+
!compactNumberPattern && ((_a = options.useGrouping) !== null && _a !== void 0 ? _a : true), decimalNumberPattern, style, options.roundingIncrement, GetUnsignedRoundingMode(options.roundingMode, sign === -1)));
|
|
128
124
|
break;
|
|
129
125
|
}
|
|
130
126
|
case '-':
|
|
@@ -141,7 +137,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
141
137
|
numberParts.push({ type: 'currency', value: nonNameCurrencyPart });
|
|
142
138
|
break;
|
|
143
139
|
default:
|
|
144
|
-
if (
|
|
140
|
+
if (part.startsWith('{c:')) {
|
|
145
141
|
numberParts.push({
|
|
146
142
|
type: 'compact',
|
|
147
143
|
value: part.substring(3, part.length - 1),
|
|
@@ -168,7 +164,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
168
164
|
var currencyNameData = data.currencies[options.currency];
|
|
169
165
|
if (currencyNameData) {
|
|
170
166
|
unitName = selectPlural(pl, numberResult.roundedNumber
|
|
171
|
-
.times(
|
|
167
|
+
.times(Decimal.pow(10, exponent))
|
|
172
168
|
.toNumber(), currencyNameData.displayName);
|
|
173
169
|
}
|
|
174
170
|
else {
|
|
@@ -207,7 +203,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
207
203
|
if (unitData) {
|
|
208
204
|
// Simple unit pattern
|
|
209
205
|
unitPattern = selectPlural(pl, numberResult.roundedNumber
|
|
210
|
-
.times(
|
|
206
|
+
.times(Decimal.pow(10, exponent))
|
|
211
207
|
.toNumber(), data.units.simple[unit][unitDisplay]);
|
|
212
208
|
}
|
|
213
209
|
else {
|
|
@@ -217,7 +213,7 @@ function formatToParts(numberResult, data, pl, options) {
|
|
|
217
213
|
var _c = unit.split('-per-'), numeratorUnit = _c[0], denominatorUnit = _c[1];
|
|
218
214
|
unitData = data.units.simple[numeratorUnit];
|
|
219
215
|
var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber
|
|
220
|
-
.times(
|
|
216
|
+
.times(Decimal.pow(10, exponent))
|
|
221
217
|
.toNumber(), data.units.simple[numeratorUnit][unitDisplay]);
|
|
222
218
|
var perUnitPattern = data.units.simple[denominatorUnit].perUnit[unitDisplay];
|
|
223
219
|
if (perUnitPattern) {
|
|
@@ -282,7 +278,7 @@ decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
|
|
|
282
278
|
else if (!x.isFinite()) {
|
|
283
279
|
return [{ type: 'infinity', value: n }];
|
|
284
280
|
}
|
|
285
|
-
var digitReplacementTable =
|
|
281
|
+
var digitReplacementTable = digitMapping[numberingSystem];
|
|
286
282
|
if (digitReplacementTable) {
|
|
287
283
|
n = n.replace(/\d/g, function (digit) { return digitReplacementTable[+digit] || digit; });
|
|
288
284
|
}
|
|
@@ -375,7 +371,7 @@ decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
|
|
|
375
371
|
result.push({ type: 'exponentMinusSign', value: symbols.minusSign });
|
|
376
372
|
exponent = -exponent;
|
|
377
373
|
}
|
|
378
|
-
var exponentResult =
|
|
374
|
+
var exponentResult = ToRawFixed(new Decimal(exponent), 0, 0, roundingIncrement, unsignedRoundingMode);
|
|
379
375
|
result.push({
|
|
380
376
|
type: 'exponentInteger',
|
|
381
377
|
value: exponentResult.formattedString,
|
|
@@ -441,7 +437,7 @@ function getCompactDisplayPattern(numberResult, pl, data, style, compactDisplay,
|
|
|
441
437
|
}
|
|
442
438
|
pattern = getPatternForSign(pattern, sign)
|
|
443
439
|
// Extract compact literal from the pattern
|
|
444
|
-
.replace(/([^\s
|
|
440
|
+
.replace(/([^\s;\-+\d¤]+)/g, '{c:$1}')
|
|
445
441
|
// We replace one or more zeros with a single zero so it matches `CLDR_NUMBER_PATTERN`.
|
|
446
442
|
.replace(/0+/, '0');
|
|
447
443
|
return pattern;
|
package/PartitionPattern.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PartitionPattern = PartitionPattern;
|
|
4
|
-
var utils_1 = require("./utils");
|
|
1
|
+
import { invariant } from './utils.js';
|
|
5
2
|
/**
|
|
6
3
|
* Partition a pattern into a list of literals and placeholders
|
|
7
4
|
* https://tc39.es/ecma402/#sec-partitionpattern
|
|
8
5
|
* @param pattern
|
|
9
6
|
*/
|
|
10
|
-
function PartitionPattern(pattern) {
|
|
7
|
+
export function PartitionPattern(pattern) {
|
|
11
8
|
var result = [];
|
|
12
9
|
var beginIndex = pattern.indexOf('{');
|
|
13
10
|
var endIndex = 0;
|
|
@@ -15,7 +12,7 @@ function PartitionPattern(pattern) {
|
|
|
15
12
|
var length = pattern.length;
|
|
16
13
|
while (beginIndex < pattern.length && beginIndex > -1) {
|
|
17
14
|
endIndex = pattern.indexOf('}', beginIndex);
|
|
18
|
-
|
|
15
|
+
invariant(endIndex > beginIndex, "Invalid pattern ".concat(pattern));
|
|
19
16
|
if (beginIndex > nextIndex) {
|
|
20
17
|
result.push({
|
|
21
18
|
type: 'literal',
|
package/SupportedLocales.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var intl_localematcher_1 = require("@formatjs/intl-localematcher");
|
|
5
|
-
var _262_1 = require("./262");
|
|
6
|
-
var GetOption_1 = require("./GetOption");
|
|
1
|
+
import { LookupSupportedLocales } from '@formatjs/intl-localematcher';
|
|
2
|
+
import { ToObject } from './262.js';
|
|
3
|
+
import { GetOption } from './GetOption.js';
|
|
7
4
|
/**
|
|
8
5
|
* https://tc39.es/ecma402/#sec-supportedlocales
|
|
9
6
|
* @param availableLocales
|
|
10
7
|
* @param requestedLocales
|
|
11
8
|
* @param options
|
|
12
9
|
*/
|
|
13
|
-
function SupportedLocales(availableLocales, requestedLocales, options) {
|
|
10
|
+
export function SupportedLocales(availableLocales, requestedLocales, options) {
|
|
14
11
|
var matcher = 'best fit';
|
|
15
12
|
if (options !== undefined) {
|
|
16
|
-
options =
|
|
17
|
-
matcher =
|
|
13
|
+
options = ToObject(options);
|
|
14
|
+
matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
|
|
18
15
|
}
|
|
19
16
|
if (matcher === 'best fit') {
|
|
20
|
-
return
|
|
17
|
+
return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
|
|
21
18
|
}
|
|
22
|
-
return
|
|
19
|
+
return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
|
|
23
20
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
2
|
export declare function ToIntlMathematicalValue(input: unknown): Decimal;
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
6
|
-
var _262_1 = require("./262");
|
|
7
|
-
function ToIntlMathematicalValue(input) {
|
|
8
|
-
var primValue = (0, _262_1.ToPrimitive)(input, 'number');
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { ToPrimitive } from './262.js';
|
|
3
|
+
export function ToIntlMathematicalValue(input) {
|
|
4
|
+
var primValue = ToPrimitive(input, 'number');
|
|
9
5
|
if (typeof primValue === 'bigint') {
|
|
10
|
-
return new
|
|
6
|
+
return new Decimal(primValue);
|
|
11
7
|
}
|
|
12
8
|
// IMPL
|
|
13
9
|
if (primValue === undefined) {
|
|
14
|
-
return new
|
|
10
|
+
return new Decimal(NaN);
|
|
15
11
|
}
|
|
16
12
|
if (primValue === true) {
|
|
17
|
-
return new
|
|
13
|
+
return new Decimal(1);
|
|
18
14
|
}
|
|
19
15
|
if (primValue === false) {
|
|
20
|
-
return new
|
|
16
|
+
return new Decimal(0);
|
|
21
17
|
}
|
|
22
18
|
if (primValue === null) {
|
|
23
|
-
return new
|
|
19
|
+
return new Decimal(0);
|
|
24
20
|
}
|
|
25
21
|
try {
|
|
26
|
-
return new
|
|
22
|
+
return new Decimal(primValue);
|
|
27
23
|
}
|
|
28
|
-
catch (
|
|
29
|
-
return new
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return new Decimal(NaN);
|
|
30
26
|
}
|
|
31
27
|
}
|
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
6
|
-
exports.TEN = new decimal_js_1.default(10);
|
|
7
|
-
exports.ZERO = new decimal_js_1.default(0);
|
|
8
|
-
exports.NEGATIVE_ZERO = new decimal_js_1.default(-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/data.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMissingLocaleDataError = isMissingLocaleDataError;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
1
|
+
import { __extends } from "tslib";
|
|
5
2
|
var MissingLocaleDataError = /** @class */ (function (_super) {
|
|
6
|
-
|
|
3
|
+
__extends(MissingLocaleDataError, _super);
|
|
7
4
|
function MissingLocaleDataError() {
|
|
8
5
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
9
6
|
_this.type = 'MISSING_LOCALE_DATA';
|
|
@@ -11,6 +8,6 @@ var MissingLocaleDataError = /** @class */ (function (_super) {
|
|
|
11
8
|
}
|
|
12
9
|
return MissingLocaleDataError;
|
|
13
10
|
}(Error));
|
|
14
|
-
function isMissingLocaleDataError(e) {
|
|
11
|
+
export function isMissingLocaleDataError(e) {
|
|
15
12
|
return e.type === 'MISSING_LOCALE_DATA';
|
|
16
13
|
}
|