@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.
Files changed (177) hide show
  1. package/262.d.ts +1 -1
  2. package/262.js +42 -68
  3. package/CanonicalizeLocaleList.js +1 -4
  4. package/CanonicalizeTimeZoneName.js +1 -4
  5. package/CoerceOptionsToObject.js +3 -6
  6. package/DefaultNumberOption.js +1 -4
  7. package/GetNumberOption.js +3 -6
  8. package/GetOption.js +3 -6
  9. package/GetOptionsObject.js +1 -4
  10. package/GetStringOrBooleanOption.js +3 -6
  11. package/IsSanctionedSimpleUnitIdentifier.js +5 -10
  12. package/IsValidTimeZoneName.js +1 -4
  13. package/IsWellFormedCurrencyCode.js +1 -4
  14. package/IsWellFormedUnitIdentifier.js +5 -8
  15. package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
  16. package/NumberFormat/ApplyUnsignedRoundingMode.js +5 -8
  17. package/NumberFormat/CollapseNumberRange.d.ts +1 -1
  18. package/NumberFormat/CollapseNumberRange.js +1 -4
  19. package/NumberFormat/ComputeExponent.d.ts +2 -2
  20. package/NumberFormat/ComputeExponent.js +8 -12
  21. package/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -2
  22. package/NumberFormat/ComputeExponentForMagnitude.js +6 -10
  23. package/NumberFormat/CurrencyDigits.js +3 -6
  24. package/NumberFormat/FormatApproximately.d.ts +1 -1
  25. package/NumberFormat/FormatApproximately.js +1 -4
  26. package/NumberFormat/FormatNumeric.d.ts +2 -2
  27. package/NumberFormat/FormatNumeric.js +3 -6
  28. package/NumberFormat/FormatNumericRange.d.ts +2 -2
  29. package/NumberFormat/FormatNumericRange.js +3 -6
  30. package/NumberFormat/FormatNumericRangeToParts.d.ts +2 -2
  31. package/NumberFormat/FormatNumericRangeToParts.js +3 -6
  32. package/NumberFormat/FormatNumericToParts.d.ts +2 -2
  33. package/NumberFormat/FormatNumericToParts.js +5 -8
  34. package/NumberFormat/FormatNumericToString.d.ts +2 -2
  35. package/NumberFormat/FormatNumericToString.js +16 -19
  36. package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
  37. package/NumberFormat/GetUnsignedRoundingMode.js +1 -4
  38. package/NumberFormat/InitializeNumberFormat.d.ts +1 -1
  39. package/NumberFormat/InitializeNumberFormat.js +23 -26
  40. package/NumberFormat/PartitionNumberPattern.d.ts +2 -2
  41. package/NumberFormat/PartitionNumberPattern.js +12 -16
  42. package/NumberFormat/PartitionNumberRangePattern.d.ts +2 -2
  43. package/NumberFormat/PartitionNumberRangePattern.js +12 -15
  44. package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  45. package/NumberFormat/SetNumberFormatDigitOptions.js +18 -21
  46. package/NumberFormat/SetNumberFormatUnitOptions.d.ts +1 -1
  47. package/NumberFormat/SetNumberFormatUnitOptions.js +15 -18
  48. package/NumberFormat/ToRawFixed.d.ts +2 -2
  49. package/NumberFormat/ToRawFixed.js +10 -14
  50. package/NumberFormat/ToRawPrecision.d.ts +2 -2
  51. package/NumberFormat/ToRawPrecision.js +19 -23
  52. package/NumberFormat/digit-mapping.generated.js +1 -4
  53. package/NumberFormat/format_to_parts.d.ts +2 -2
  54. package/NumberFormat/format_to_parts.js +18 -22
  55. package/PartitionPattern.d.ts +1 -0
  56. package/PartitionPattern.js +4 -6
  57. package/SupportedLocales.js +8 -11
  58. package/ToIntlMathematicalValue.d.ts +1 -1
  59. package/ToIntlMathematicalValue.js +12 -16
  60. package/constants.d.ts +1 -1
  61. package/constants.js +4 -8
  62. package/data.js +3 -6
  63. package/index.d.ts +47 -47
  64. package/index.js +45 -66
  65. package/package.json +7 -5
  66. package/regex.generated.js +1 -4
  67. package/types/core.js +1 -2
  68. package/types/date-time.js +2 -5
  69. package/types/displaynames.d.ts +1 -1
  70. package/types/displaynames.js +1 -2
  71. package/types/list.d.ts +1 -1
  72. package/types/list.js +1 -2
  73. package/types/number.d.ts +3 -3
  74. package/types/number.js +1 -2
  75. package/types/plural-rules.d.ts +2 -2
  76. package/types/plural-rules.js +1 -2
  77. package/types/relative-time.d.ts +2 -2
  78. package/types/relative-time.js +1 -2
  79. package/utils.js +28 -40
  80. package/lib/262.d.ts +0 -93
  81. package/lib/262.js +0 -400
  82. package/lib/CanonicalizeLocaleList.d.ts +0 -5
  83. package/lib/CanonicalizeLocaleList.js +0 -8
  84. package/lib/CanonicalizeTimeZoneName.d.ts +0 -8
  85. package/lib/CanonicalizeTimeZoneName.js +0 -17
  86. package/lib/CoerceOptionsToObject.d.ts +0 -6
  87. package/lib/CoerceOptionsToObject.js +0 -12
  88. package/lib/DefaultNumberOption.d.ts +0 -8
  89. package/lib/DefaultNumberOption.js +0 -18
  90. package/lib/GetNumberOption.d.ts +0 -9
  91. package/lib/GetNumberOption.js +0 -13
  92. package/lib/GetOption.d.ts +0 -9
  93. package/lib/GetOption.js +0 -31
  94. package/lib/GetOptionsObject.d.ts +0 -6
  95. package/lib/GetOptionsObject.js +0 -14
  96. package/lib/GetStringOrBooleanOption.d.ts +0 -10
  97. package/lib/GetStringOrBooleanOption.js +0 -31
  98. package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +0 -13
  99. package/lib/IsSanctionedSimpleUnitIdentifier.js +0 -63
  100. package/lib/IsValidTimeZoneName.d.ts +0 -9
  101. package/lib/IsValidTimeZoneName.js +0 -17
  102. package/lib/IsWellFormedCurrencyCode.d.ts +0 -4
  103. package/lib/IsWellFormedCurrencyCode.js +0 -21
  104. package/lib/IsWellFormedUnitIdentifier.d.ts +0 -5
  105. package/lib/IsWellFormedUnitIdentifier.js +0 -28
  106. package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts +0 -3
  107. package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +0 -33
  108. package/lib/NumberFormat/CollapseNumberRange.d.ts +0 -8
  109. package/lib/NumberFormat/CollapseNumberRange.js +0 -50
  110. package/lib/NumberFormat/ComputeExponent.d.ts +0 -10
  111. package/lib/NumberFormat/ComputeExponent.js +0 -34
  112. package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -8
  113. package/lib/NumberFormat/ComputeExponentForMagnitude.js +0 -65
  114. package/lib/NumberFormat/CurrencyDigits.d.ts +0 -6
  115. package/lib/NumberFormat/CurrencyDigits.js +0 -10
  116. package/lib/NumberFormat/FormatApproximately.d.ts +0 -5
  117. package/lib/NumberFormat/FormatApproximately.js +0 -9
  118. package/lib/NumberFormat/FormatNumeric.d.ts +0 -3
  119. package/lib/NumberFormat/FormatNumeric.js +0 -5
  120. package/lib/NumberFormat/FormatNumericRange.d.ts +0 -8
  121. package/lib/NumberFormat/FormatNumericRange.js +0 -11
  122. package/lib/NumberFormat/FormatNumericRangeToParts.d.ts +0 -8
  123. package/lib/NumberFormat/FormatNumericRangeToParts.js +0 -16
  124. package/lib/NumberFormat/FormatNumericToParts.d.ts +0 -5
  125. package/lib/NumberFormat/FormatNumericToParts.js +0 -14
  126. package/lib/NumberFormat/FormatNumericToString.d.ts +0 -9
  127. package/lib/NumberFormat/FormatNumericToString.js +0 -84
  128. package/lib/NumberFormat/GetUnsignedRoundingMode.d.ts +0 -2
  129. package/lib/NumberFormat/GetUnsignedRoundingMode.js +0 -28
  130. package/lib/NumberFormat/InitializeNumberFormat.d.ts +0 -12
  131. package/lib/NumberFormat/InitializeNumberFormat.js +0 -66
  132. package/lib/NumberFormat/PartitionNumberPattern.d.ts +0 -6
  133. package/lib/NumberFormat/PartitionNumberPattern.js +0 -126
  134. package/lib/NumberFormat/PartitionNumberRangePattern.d.ts +0 -8
  135. package/lib/NumberFormat/PartitionNumberRangePattern.js +0 -40
  136. package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -5
  137. package/lib/NumberFormat/SetNumberFormatDigitOptions.js +0 -179
  138. package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -5
  139. package/lib/NumberFormat/SetNumberFormatUnitOptions.js +0 -50
  140. package/lib/NumberFormat/ToRawFixed.d.ts +0 -9
  141. package/lib/NumberFormat/ToRawFixed.js +0 -119
  142. package/lib/NumberFormat/ToRawPrecision.d.ts +0 -9
  143. package/lib/NumberFormat/ToRawPrecision.js +0 -148
  144. package/lib/NumberFormat/digit-mapping.generated.d.ts +0 -1
  145. package/lib/NumberFormat/digit-mapping.generated.js +0 -782
  146. package/lib/NumberFormat/format_to_parts.d.ts +0 -24
  147. package/lib/NumberFormat/format_to_parts.js +0 -447
  148. package/lib/PartitionPattern.d.ts +0 -8
  149. package/lib/PartitionPattern.js +0 -35
  150. package/lib/SupportedLocales.d.ts +0 -9
  151. package/lib/SupportedLocales.js +0 -20
  152. package/lib/ToIntlMathematicalValue.d.ts +0 -2
  153. package/lib/ToIntlMathematicalValue.js +0 -27
  154. package/lib/constants.d.ts +0 -4
  155. package/lib/constants.js +0 -4
  156. package/lib/data.d.ts +0 -5
  157. package/lib/data.js +0 -13
  158. package/lib/index.d.ts +0 -47
  159. package/lib/index.js +0 -45
  160. package/lib/regex.generated.d.ts +0 -1
  161. package/lib/regex.generated.js +0 -2
  162. package/lib/types/core.d.ts +0 -10
  163. package/lib/types/core.js +0 -1
  164. package/lib/types/date-time.d.ts +0 -135
  165. package/lib/types/date-time.js +0 -6
  166. package/lib/types/displaynames.d.ts +0 -65
  167. package/lib/types/displaynames.js +0 -1
  168. package/lib/types/list.d.ts +0 -18
  169. package/lib/types/list.js +0 -1
  170. package/lib/types/number.d.ts +0 -173
  171. package/lib/types/number.js +0 -1
  172. package/lib/types/plural-rules.d.ts +0 -16
  173. package/lib/types/plural-rules.js +0 -1
  174. package/lib/types/relative-time.d.ts +0 -40
  175. package/lib/types/relative-time.js +0 -1
  176. package/lib/utils.d.ts +0 -30
  177. 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>>;