@formatjs/ecma402-abstract 2.3.5 → 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.
- 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.d.ts +1 -0
- package/PartitionPattern.js +4 -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 -8
- package/lib/PartitionPattern.js +0 -35
- 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,148 +0,0 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { ZERO } from '../constants';
|
|
3
|
-
import { invariant, repeat } from '../utils';
|
|
4
|
-
import { ApplyUnsignedRoundingMode } from './ApplyUnsignedRoundingMode';
|
|
5
|
-
//IMPL: Helper function to find n1, e1, and r1
|
|
6
|
-
function findN1E1R1(x, p) {
|
|
7
|
-
var maxN1 = Decimal.pow(10, p);
|
|
8
|
-
var minN1 = Decimal.pow(10, p - 1);
|
|
9
|
-
var maxE1 = x.div(minN1).log(10).plus(p).minus(1).ceil();
|
|
10
|
-
var currentE1 = maxE1;
|
|
11
|
-
while (true) {
|
|
12
|
-
var currentN1 = x.div(Decimal.pow(10, currentE1.minus(p).plus(1))).floor();
|
|
13
|
-
if (currentN1.lessThan(maxN1) && currentN1.greaterThanOrEqualTo(minN1)) {
|
|
14
|
-
var currentR1 = currentN1.times(Decimal.pow(10, currentE1.minus(p).plus(1)));
|
|
15
|
-
if (currentR1.lessThanOrEqualTo(x)) {
|
|
16
|
-
return {
|
|
17
|
-
n1: currentN1,
|
|
18
|
-
e1: currentE1,
|
|
19
|
-
r1: currentR1,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
currentE1 = currentE1.minus(1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//IMPL: Helper function to find n2, e2, and r2
|
|
27
|
-
function findN2E2R2(x, p) {
|
|
28
|
-
var maxN2 = Decimal.pow(10, p);
|
|
29
|
-
var minN2 = Decimal.pow(10, p - 1);
|
|
30
|
-
var minE2 = x.div(maxN2).log(10).plus(p).minus(1).floor();
|
|
31
|
-
var currentE2 = minE2;
|
|
32
|
-
while (true) {
|
|
33
|
-
var currentN2 = x.div(Decimal.pow(10, currentE2.minus(p).plus(1))).ceil();
|
|
34
|
-
if (currentN2.lessThan(maxN2) && currentN2.greaterThanOrEqualTo(minN2)) {
|
|
35
|
-
var currentR2 = currentN2.times(Decimal.pow(10, currentE2.minus(p).plus(1)));
|
|
36
|
-
if (currentR2.greaterThanOrEqualTo(x)) {
|
|
37
|
-
return {
|
|
38
|
-
n2: currentN2,
|
|
39
|
-
e2: currentE2,
|
|
40
|
-
r2: currentR2,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
currentE2 = currentE2.plus(1);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* https://tc39.es/ecma402/#sec-torawprecision
|
|
49
|
-
* @param x a finite non-negative Number or BigInt
|
|
50
|
-
* @param minPrecision an integer between 1 and 21
|
|
51
|
-
* @param maxPrecision an integer between 1 and 21
|
|
52
|
-
*/
|
|
53
|
-
export function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
|
|
54
|
-
// 1. Let p be maxPrecision.
|
|
55
|
-
var p = maxPrecision;
|
|
56
|
-
var m;
|
|
57
|
-
var e;
|
|
58
|
-
var xFinal;
|
|
59
|
-
// 2. If x = 0, then
|
|
60
|
-
if (x.isZero()) {
|
|
61
|
-
// a. Let m be the String value consisting of p occurrences of the character "0".
|
|
62
|
-
m = repeat('0', p);
|
|
63
|
-
// b. Let e be 0.
|
|
64
|
-
e = 0;
|
|
65
|
-
// c. Let xFinal be 0.
|
|
66
|
-
xFinal = ZERO;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// 3. Else,
|
|
70
|
-
// a. Let {n1, e1, r1} be the result of findN1E1R1(x, p).
|
|
71
|
-
var _a = findN1E1R1(x, p), n1 = _a.n1, e1 = _a.e1, r1 = _a.r1;
|
|
72
|
-
// b. Let {n2, e2, r2} be the result of findN2E2R2(x, p).
|
|
73
|
-
var _b = findN2E2R2(x, p), n2 = _b.n2, e2 = _b.e2, r2 = _b.r2;
|
|
74
|
-
// c. Let r be ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode).
|
|
75
|
-
var r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
|
|
76
|
-
var n
|
|
77
|
-
// d. If r = r1, then
|
|
78
|
-
= void 0;
|
|
79
|
-
// d. If r = r1, then
|
|
80
|
-
if (r.eq(r1)) {
|
|
81
|
-
// i. Let n be n1.
|
|
82
|
-
n = n1;
|
|
83
|
-
// ii. Let e be e1.
|
|
84
|
-
e = e1.toNumber();
|
|
85
|
-
// iii. Let xFinal be r1.
|
|
86
|
-
xFinal = r1;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// e. Else,
|
|
90
|
-
// i. Let n be n2.
|
|
91
|
-
n = n2;
|
|
92
|
-
// ii. Let e be e2.
|
|
93
|
-
e = e2.toNumber();
|
|
94
|
-
// iii. Let xFinal be r2.
|
|
95
|
-
xFinal = r2;
|
|
96
|
-
}
|
|
97
|
-
// f. Let m be the String representation of n.
|
|
98
|
-
m = n.toString();
|
|
99
|
-
}
|
|
100
|
-
var int;
|
|
101
|
-
// 4. If e ≥ p - 1, then
|
|
102
|
-
if (e >= p - 1) {
|
|
103
|
-
// a. Let m be the string-concatenation of m and p - 1 - e occurrences of the character "0".
|
|
104
|
-
m = m + repeat('0', e - p + 1);
|
|
105
|
-
// b. Let int be e + 1.
|
|
106
|
-
int = e + 1;
|
|
107
|
-
}
|
|
108
|
-
else if (e >= 0) {
|
|
109
|
-
// 5. Else if e ≥ 0, then
|
|
110
|
-
// a. Let m be the string-concatenation of the first e + 1 characters of m, ".", and the remaining p - (e + 1) characters of m.
|
|
111
|
-
m = m.slice(0, e + 1) + '.' + m.slice(m.length - (p - (e + 1)));
|
|
112
|
-
// b. Let int be e + 1.
|
|
113
|
-
int = e + 1;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// 6. Else,
|
|
117
|
-
// a. Assert: e < 0.
|
|
118
|
-
invariant(e < 0, 'e should be less than 0');
|
|
119
|
-
// b. Let m be the string-concatenation of "0.", -e - 1 occurrences of the character "0", and m.
|
|
120
|
-
m = '0.' + repeat('0', -e - 1) + m;
|
|
121
|
-
// c. Let int be 1.
|
|
122
|
-
int = 1;
|
|
123
|
-
}
|
|
124
|
-
// 7. If m contains ".", and maxPrecision > minPrecision, then
|
|
125
|
-
if (m.includes('.') && maxPrecision > minPrecision) {
|
|
126
|
-
// a. Let cut be maxPrecision - minPrecision.
|
|
127
|
-
var cut = maxPrecision - minPrecision;
|
|
128
|
-
// b. Repeat, while cut > 0 and the last character of m is "0",
|
|
129
|
-
while (cut > 0 && m[m.length - 1] === '0') {
|
|
130
|
-
// i. Remove the last character from m.
|
|
131
|
-
m = m.slice(0, m.length - 1);
|
|
132
|
-
// ii. Decrease cut by 1.
|
|
133
|
-
cut--;
|
|
134
|
-
}
|
|
135
|
-
// c. If the last character of m is ".", then
|
|
136
|
-
if (m[m.length - 1] === '.') {
|
|
137
|
-
// i. Remove the last character from m.
|
|
138
|
-
m = m.slice(0, m.length - 1);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// 8. Return the Record { [[FormattedString]]: m, [[RoundedNumber]]: xFinal, [[IntegerDigitsCount]]: int, [[RoundingMagnitude]]: e }.
|
|
142
|
-
return {
|
|
143
|
-
formattedString: m,
|
|
144
|
-
roundedNumber: xFinal,
|
|
145
|
-
integerDigitsCount: int,
|
|
146
|
-
roundingMagnitude: e,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const digitMapping: Record<string, ReadonlyArray<string>>;
|