@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,63 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
3
- */
4
- export var SANCTIONED_UNITS = [
5
- 'angle-degree',
6
- 'area-acre',
7
- 'area-hectare',
8
- 'concentr-percent',
9
- 'digital-bit',
10
- 'digital-byte',
11
- 'digital-gigabit',
12
- 'digital-gigabyte',
13
- 'digital-kilobit',
14
- 'digital-kilobyte',
15
- 'digital-megabit',
16
- 'digital-megabyte',
17
- 'digital-petabyte',
18
- 'digital-terabit',
19
- 'digital-terabyte',
20
- 'duration-day',
21
- 'duration-hour',
22
- 'duration-millisecond',
23
- 'duration-minute',
24
- 'duration-month',
25
- 'duration-second',
26
- 'duration-week',
27
- 'duration-year',
28
- 'length-centimeter',
29
- 'length-foot',
30
- 'length-inch',
31
- 'length-kilometer',
32
- 'length-meter',
33
- 'length-mile-scandinavian',
34
- 'length-mile',
35
- 'length-millimeter',
36
- 'length-yard',
37
- 'mass-gram',
38
- 'mass-kilogram',
39
- 'mass-ounce',
40
- 'mass-pound',
41
- 'mass-stone',
42
- 'temperature-celsius',
43
- 'temperature-fahrenheit',
44
- 'volume-fluid-ounce',
45
- 'volume-gallon',
46
- 'volume-liter',
47
- 'volume-milliliter',
48
- ];
49
- // In CLDR, the unit name always follows the form `namespace-unit` pattern.
50
- // For example: `digital-bit` instead of `bit`. This function removes the namespace prefix.
51
- export function removeUnitNamespace(unit) {
52
- return unit.slice(unit.indexOf('-') + 1);
53
- }
54
- /**
55
- * https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
56
- */
57
- export var SIMPLE_UNITS = SANCTIONED_UNITS.map(removeUnitNamespace);
58
- /**
59
- * https://tc39.es/ecma402/#sec-issanctionedsimpleunitidentifier
60
- */
61
- export function IsSanctionedSimpleUnitIdentifier(unitIdentifier) {
62
- return SIMPLE_UNITS.indexOf(unitIdentifier) > -1;
63
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-isvalidtimezonename
3
- * @param tz
4
- * @param implDetails implementation details
5
- */
6
- export declare function IsValidTimeZoneName(tz: string, { zoneNamesFromData, uppercaseLinks, }: {
7
- zoneNamesFromData: readonly string[];
8
- uppercaseLinks: Record<string, string>;
9
- }): boolean;
@@ -1,17 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-isvalidtimezonename
3
- * @param tz
4
- * @param implDetails implementation details
5
- */
6
- export function IsValidTimeZoneName(tz, _a) {
7
- var zoneNamesFromData = _a.zoneNamesFromData, uppercaseLinks = _a.uppercaseLinks;
8
- var uppercasedTz = tz.toUpperCase();
9
- var zoneNames = new Set();
10
- var linkNames = new Set();
11
- zoneNamesFromData.map(function (z) { return z.toUpperCase(); }).forEach(function (z) { return zoneNames.add(z); });
12
- Object.keys(uppercaseLinks).forEach(function (linkName) {
13
- linkNames.add(linkName.toUpperCase());
14
- zoneNames.add(uppercaseLinks[linkName].toUpperCase());
15
- });
16
- return zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz);
17
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-iswellformedcurrencycode
3
- */
4
- export declare function IsWellFormedCurrencyCode(currency: string): boolean;
@@ -1,21 +0,0 @@
1
- /**
2
- * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
3
- * @param str string to convert
4
- */
5
- function toUpperCase(str) {
6
- return str.replace(/([a-z])/g, function (_, c) { return c.toUpperCase(); });
7
- }
8
- var NOT_A_Z_REGEX = /[^A-Z]/;
9
- /**
10
- * https://tc39.es/ecma402/#sec-iswellformedcurrencycode
11
- */
12
- export function IsWellFormedCurrencyCode(currency) {
13
- currency = toUpperCase(currency);
14
- if (currency.length !== 3) {
15
- return false;
16
- }
17
- if (NOT_A_Z_REGEX.test(currency)) {
18
- return false;
19
- }
20
- return true;
21
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-iswellformedunitidentifier
3
- * @param unit
4
- */
5
- export declare function IsWellFormedUnitIdentifier(unit: string): boolean;
@@ -1,28 +0,0 @@
1
- import { IsSanctionedSimpleUnitIdentifier } from './IsSanctionedSimpleUnitIdentifier';
2
- /**
3
- * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
4
- * @param str string to convert
5
- */
6
- function toLowerCase(str) {
7
- return str.replace(/([A-Z])/g, function (_, c) { return c.toLowerCase(); });
8
- }
9
- /**
10
- * https://tc39.es/ecma402/#sec-iswellformedunitidentifier
11
- * @param unit
12
- */
13
- export function IsWellFormedUnitIdentifier(unit) {
14
- unit = toLowerCase(unit);
15
- if (IsSanctionedSimpleUnitIdentifier(unit)) {
16
- return true;
17
- }
18
- var units = unit.split('-per-');
19
- if (units.length !== 2) {
20
- return false;
21
- }
22
- var numerator = units[0], denominator = units[1];
23
- if (!IsSanctionedSimpleUnitIdentifier(numerator) ||
24
- !IsSanctionedSimpleUnitIdentifier(denominator)) {
25
- return false;
26
- }
27
- return true;
28
- }
@@ -1,3 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { UnsignedRoundingModeType } from '../types/number';
3
- export declare function ApplyUnsignedRoundingMode(x: Decimal, r1: Decimal, r2: Decimal, unsignedRoundingMode: UnsignedRoundingModeType): Decimal;
@@ -1,33 +0,0 @@
1
- import { invariant } from '../utils';
2
- export function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
3
- if (x.eq(r1))
4
- return r1;
5
- invariant(r1.lessThan(x) && x.lessThan(r2), "x should be between r1 and r2 but x=".concat(x, ", r1=").concat(r1, ", r2=").concat(r2));
6
- if (unsignedRoundingMode === 'zero') {
7
- return r1;
8
- }
9
- if (unsignedRoundingMode === 'infinity') {
10
- return r2;
11
- }
12
- var d1 = x.minus(r1);
13
- var d2 = r2.minus(x);
14
- if (d1.lessThan(d2)) {
15
- return r1;
16
- }
17
- if (d2.lessThan(d1)) {
18
- return r2;
19
- }
20
- invariant(d1.eq(d2), 'd1 should be equal to d2');
21
- if (unsignedRoundingMode === 'half-zero') {
22
- return r1;
23
- }
24
- if (unsignedRoundingMode === 'half-infinity') {
25
- return r2;
26
- }
27
- invariant(unsignedRoundingMode === 'half-even', 'unsignedRoundingMode should be half-even');
28
- var cardinality = r1.div(r2.minus(r1)).mod(2);
29
- if (cardinality.isZero()) {
30
- return r1;
31
- }
32
- return r2;
33
- }
@@ -1,8 +0,0 @@
1
- import { NumberFormatInternal, NumberFormatPart } from '../types/number';
2
- /**
3
- * https://tc39.es/ecma402/#sec-collapsenumberrange
4
- * LDML: https://unicode-org.github.io/cldr/ldml/tr35-numbers.html#collapsing-number-ranges
5
- */
6
- export declare function CollapseNumberRange(numberFormat: Intl.NumberFormat, result: NumberFormatPart[], { getInternalSlots, }: {
7
- getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
8
- }): NumberFormatPart[];
@@ -1,50 +0,0 @@
1
- var PART_TYPES_TO_COLLAPSE = new Set([
2
- 'unit',
3
- 'exponentMinusSign',
4
- 'minusSign',
5
- 'plusSign',
6
- 'percentSign',
7
- 'exponentSeparator',
8
- 'percent',
9
- 'percentSign',
10
- 'currency',
11
- 'literal',
12
- ]);
13
- /**
14
- * https://tc39.es/ecma402/#sec-collapsenumberrange
15
- * LDML: https://unicode-org.github.io/cldr/ldml/tr35-numbers.html#collapsing-number-ranges
16
- */
17
- export function CollapseNumberRange(numberFormat, result, _a) {
18
- var getInternalSlots = _a.getInternalSlots;
19
- var internalSlots = getInternalSlots(numberFormat);
20
- var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
21
- var rangeSignRegex = new RegExp("s?[".concat(symbols.rangeSign, "]s?"));
22
- var rangeSignIndex = result.findIndex(function (r) { return r.type === 'literal' && rangeSignRegex.test(r.value); });
23
- var prefixSignParts = [];
24
- for (var i = rangeSignIndex - 1; i >= 0; i--) {
25
- if (!PART_TYPES_TO_COLLAPSE.has(result[i].type)) {
26
- break;
27
- }
28
- prefixSignParts.unshift(result[i]);
29
- }
30
- // Don't collapse if it's a single code point
31
- if (Array.from(prefixSignParts.map(function (p) { return p.value; }).join('')).length > 1) {
32
- var newResult = Array.from(result);
33
- newResult.splice(rangeSignIndex - prefixSignParts.length, prefixSignParts.length);
34
- return newResult;
35
- }
36
- var suffixSignParts = [];
37
- for (var i = rangeSignIndex + 1; i < result.length; i++) {
38
- if (!PART_TYPES_TO_COLLAPSE.has(result[i].type)) {
39
- break;
40
- }
41
- suffixSignParts.push(result[i]);
42
- }
43
- // Don't collapse if it's a single code point
44
- if (Array.from(suffixSignParts.map(function (p) { return p.value; }).join('')).length > 1) {
45
- var newResult = Array.from(result);
46
- newResult.splice(rangeSignIndex + 1, suffixSignParts.length);
47
- return newResult;
48
- }
49
- return result;
50
- }
@@ -1,10 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatInternal } from '../types/number';
3
- /**
4
- * The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x
5
- * according to the number formatting settings. It handles cases such as 999 rounding up to 1000,
6
- * requiring a different exponent.
7
- *
8
- * NOT IN SPEC: it returns [exponent, magnitude].
9
- */
10
- export declare function ComputeExponent(internalSlots: NumberFormatInternal, x: Decimal): [number, number];
@@ -1,34 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { ComputeExponentForMagnitude } from './ComputeExponentForMagnitude';
3
- import { FormatNumericToString } from './FormatNumericToString';
4
- /**
5
- * The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x
6
- * according to the number formatting settings. It handles cases such as 999 rounding up to 1000,
7
- * requiring a different exponent.
8
- *
9
- * NOT IN SPEC: it returns [exponent, magnitude].
10
- */
11
- export function ComputeExponent(internalSlots, x) {
12
- if (x.isZero()) {
13
- return [0, 0];
14
- }
15
- if (x.isNegative()) {
16
- x = x.negated();
17
- }
18
- var magnitude = x.log(10).floor();
19
- var exponent = ComputeExponentForMagnitude(internalSlots, magnitude);
20
- // Preserve more precision by doing multiplication when exponent is negative.
21
- x = x.times(Decimal.pow(10, -exponent));
22
- var formatNumberResult = FormatNumericToString(internalSlots, x);
23
- if (formatNumberResult.roundedNumber.isZero()) {
24
- return [exponent, magnitude.toNumber()];
25
- }
26
- var newMagnitude = formatNumberResult.roundedNumber.log(10).floor();
27
- if (newMagnitude.eq(magnitude.minus(exponent))) {
28
- return [exponent, magnitude.toNumber()];
29
- }
30
- return [
31
- ComputeExponentForMagnitude(internalSlots, magnitude.plus(1)),
32
- magnitude.plus(1).toNumber(),
33
- ];
34
- }
@@ -1,8 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatInternal } from '../types/number';
3
- /**
4
- * The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
5
- * number of the given magnitude (power of ten of the most significant digit) according to the
6
- * locale and the desired notation (scientific, engineering, or compact).
7
- */
8
- export declare function ComputeExponentForMagnitude(internalSlots: NumberFormatInternal, magnitude: Decimal): number;
@@ -1,65 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { invariant } from '../utils';
3
- Decimal.set({
4
- toExpPos: 100,
5
- });
6
- /**
7
- * The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
8
- * number of the given magnitude (power of ten of the most significant digit) according to the
9
- * locale and the desired notation (scientific, engineering, or compact).
10
- */
11
- export function ComputeExponentForMagnitude(internalSlots, magnitude) {
12
- var notation = internalSlots.notation, dataLocaleData = internalSlots.dataLocaleData, numberingSystem = internalSlots.numberingSystem;
13
- switch (notation) {
14
- case 'standard':
15
- return 0;
16
- case 'scientific':
17
- return magnitude.toNumber();
18
- case 'engineering':
19
- var thousands = magnitude.div(3).floor();
20
- return thousands.times(3).toNumber();
21
- default: {
22
- invariant(notation === 'compact', 'Invalid notation');
23
- // Let exponent be an implementation- and locale-dependent (ILD) integer by which to scale a
24
- // number of the given magnitude in compact notation for the current locale.
25
- var compactDisplay = internalSlots.compactDisplay, style = internalSlots.style, currencyDisplay = internalSlots.currencyDisplay;
26
- var thresholdMap = void 0;
27
- if (style === 'currency' && currencyDisplay !== 'name') {
28
- var currency = dataLocaleData.numbers.currency[numberingSystem] ||
29
- dataLocaleData.numbers.currency[dataLocaleData.numbers.nu[0]];
30
- thresholdMap = currency.short;
31
- }
32
- else {
33
- var decimal = dataLocaleData.numbers.decimal[numberingSystem] ||
34
- dataLocaleData.numbers.decimal[dataLocaleData.numbers.nu[0]];
35
- thresholdMap = compactDisplay === 'long' ? decimal.long : decimal.short;
36
- }
37
- if (!thresholdMap) {
38
- return 0;
39
- }
40
- var num = Decimal.pow(10, magnitude).toString();
41
- var thresholds = Object.keys(thresholdMap); // TODO: this can be pre-processed
42
- if (num < thresholds[0]) {
43
- return 0;
44
- }
45
- if (num > thresholds[thresholds.length - 1]) {
46
- return thresholds[thresholds.length - 1].length - 1;
47
- }
48
- var i = thresholds.indexOf(num);
49
- if (i === -1) {
50
- return 0;
51
- }
52
- // See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
53
- // Special handling if the pattern is precisely `0`.
54
- var magnitudeKey = thresholds[i];
55
- // TODO: do we need to handle plural here?
56
- var compactPattern = thresholdMap[magnitudeKey].other;
57
- if (compactPattern === '0') {
58
- return 0;
59
- }
60
- // Example: in zh-TW, `10000000` maps to `0000萬`. So we need to return 8 - 4 = 4 here.
61
- return (magnitudeKey.length -
62
- thresholdMap[magnitudeKey].other.match(/0+/)[0].length);
63
- }
64
- }
65
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-currencydigits
3
- */
4
- export declare function CurrencyDigits(c: string, { currencyDigitsData }: {
5
- currencyDigitsData: Record<string, number>;
6
- }): number;
@@ -1,10 +0,0 @@
1
- import { HasOwnProperty } from '../262';
2
- /**
3
- * https://tc39.es/ecma402/#sec-currencydigits
4
- */
5
- export function CurrencyDigits(c, _a) {
6
- var currencyDigitsData = _a.currencyDigitsData;
7
- return HasOwnProperty(currencyDigitsData, c)
8
- ? currencyDigitsData[c]
9
- : 2;
10
- }
@@ -1,5 +0,0 @@
1
- import { NumberFormatInternal, NumberFormatPart } from '../types/number';
2
- /**
3
- * https://tc39.es/ecma402/#sec-formatapproximately
4
- */
5
- export declare function FormatApproximately(internalSlots: NumberFormatInternal, result: NumberFormatPart[]): NumberFormatPart[];
@@ -1,9 +0,0 @@
1
- /**
2
- * https://tc39.es/ecma402/#sec-formatapproximately
3
- */
4
- export function FormatApproximately(internalSlots, result) {
5
- var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
6
- var approximatelySign = symbols.approximatelySign;
7
- result.push({ type: 'approximatelySign', value: approximatelySign });
8
- return result;
9
- }
@@ -1,3 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatInternal } from '../types/number';
3
- export declare function FormatNumeric(internalSlots: NumberFormatInternal, x: Decimal): string;
@@ -1,5 +0,0 @@
1
- import { PartitionNumberPattern } from './PartitionNumberPattern';
2
- export function FormatNumeric(internalSlots, x) {
3
- var parts = PartitionNumberPattern(internalSlots, x);
4
- return parts.map(function (p) { return p.value; }).join('');
5
- }
@@ -1,8 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatInternal } from '../types/number';
3
- /**
4
- * https://tc39.es/ecma402/#sec-formatnumericrange
5
- */
6
- export declare function FormatNumericRange(numberFormat: Intl.NumberFormat, x: Decimal, y: Decimal, { getInternalSlots, }: {
7
- getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
8
- }): string;
@@ -1,11 +0,0 @@
1
- import { PartitionNumberRangePattern } from './PartitionNumberRangePattern';
2
- /**
3
- * https://tc39.es/ecma402/#sec-formatnumericrange
4
- */
5
- export function FormatNumericRange(numberFormat, x, y, _a) {
6
- var getInternalSlots = _a.getInternalSlots;
7
- var parts = PartitionNumberRangePattern(numberFormat, x, y, {
8
- getInternalSlots: getInternalSlots,
9
- });
10
- return parts.map(function (part) { return part.value; }).join('');
11
- }
@@ -1,8 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatInternal, NumberRangeToParts } from '../types/number';
3
- /**
4
- * https://tc39.es/ecma402/#sec-formatnumericrangetoparts
5
- */
6
- export declare function FormatNumericRangeToParts(numberFormat: Intl.NumberFormat, x: Decimal, y: Decimal, { getInternalSlots, }: {
7
- getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
8
- }): NumberRangeToParts[];
@@ -1,16 +0,0 @@
1
- import { PartitionNumberRangePattern } from './PartitionNumberRangePattern';
2
- /**
3
- * https://tc39.es/ecma402/#sec-formatnumericrangetoparts
4
- */
5
- export function FormatNumericRangeToParts(numberFormat, x, y, _a) {
6
- var getInternalSlots = _a.getInternalSlots;
7
- var parts = PartitionNumberRangePattern(numberFormat, x, y, {
8
- getInternalSlots: getInternalSlots,
9
- });
10
- return parts.map(function (part, index) { return ({
11
- type: part.type,
12
- value: part.value,
13
- source: part.source,
14
- result: index.toString(),
15
- }); });
16
- }
@@ -1,5 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatInternal, NumberFormatPart } from '../types/number';
3
- export declare function FormatNumericToParts(nf: Intl.NumberFormat, x: Decimal, implDetails: {
4
- getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
5
- }): NumberFormatPart[];
@@ -1,14 +0,0 @@
1
- import { ArrayCreate } from '../262';
2
- import { PartitionNumberPattern } from './PartitionNumberPattern';
3
- export function FormatNumericToParts(nf, x, implDetails) {
4
- var parts = PartitionNumberPattern(implDetails.getInternalSlots(nf), x);
5
- var result = ArrayCreate(0);
6
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
7
- var part = parts_1[_i];
8
- result.push({
9
- type: part.type,
10
- value: part.value,
11
- });
12
- }
13
- return result;
14
- }
@@ -1,9 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { NumberFormatDigitInternalSlots } from '../types/number';
3
- /**
4
- * https://tc39.es/ecma402/#sec-formatnumberstring
5
- */
6
- export declare function FormatNumericToString(intlObject: Pick<NumberFormatDigitInternalSlots, 'roundingType' | 'minimumSignificantDigits' | 'maximumSignificantDigits' | 'minimumIntegerDigits' | 'minimumFractionDigits' | 'maximumFractionDigits' | 'roundingIncrement' | 'roundingMode' | 'trailingZeroDisplay'>, _x: Decimal): {
7
- roundedNumber: Decimal;
8
- formattedString: string;
9
- };
@@ -1,84 +0,0 @@
1
- import { NEGATIVE_ZERO, ZERO } from '../constants';
2
- import { invariant, repeat } from '../utils';
3
- import { GetUnsignedRoundingMode } from './GetUnsignedRoundingMode';
4
- import { ToRawFixed } from './ToRawFixed';
5
- import { ToRawPrecision } from './ToRawPrecision';
6
- /**
7
- * https://tc39.es/ecma402/#sec-formatnumberstring
8
- */
9
- export function FormatNumericToString(intlObject, _x) {
10
- var x = _x;
11
- var sign;
12
- // -0
13
- if (x.isZero() && x.isNegative()) {
14
- sign = 'negative';
15
- x = ZERO;
16
- }
17
- else {
18
- invariant(x.isFinite(), 'NumberFormatDigitInternalSlots value is not finite');
19
- if (x.lessThan(0)) {
20
- sign = 'negative';
21
- }
22
- else {
23
- sign = 'positive';
24
- }
25
- if (sign === 'negative') {
26
- x = x.negated();
27
- }
28
- }
29
- var result;
30
- var roundingType = intlObject.roundingType;
31
- var unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign === 'negative');
32
- switch (roundingType) {
33
- case 'significantDigits':
34
- result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
35
- break;
36
- case 'fractionDigits':
37
- result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
38
- break;
39
- default:
40
- var sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
41
- var fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
42
- if (intlObject.roundingType === 'morePrecision') {
43
- if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
44
- result = sResult;
45
- }
46
- else {
47
- result = fResult;
48
- }
49
- }
50
- else {
51
- invariant(intlObject.roundingType === 'lessPrecision', 'Invalid roundingType');
52
- if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
53
- result = fResult;
54
- }
55
- else {
56
- result = sResult;
57
- }
58
- }
59
- break;
60
- }
61
- x = result.roundedNumber;
62
- var string = result.formattedString;
63
- if (intlObject.trailingZeroDisplay === 'stripIfInteger' && x.isInteger()) {
64
- var i = string.indexOf('.');
65
- if (i > -1) {
66
- string = string.slice(0, i);
67
- }
68
- }
69
- var int = result.integerDigitsCount;
70
- var minInteger = intlObject.minimumIntegerDigits;
71
- if (int < minInteger) {
72
- var forwardZeros = repeat('0', minInteger - int);
73
- string = forwardZeros + string;
74
- }
75
- if (sign === 'negative') {
76
- if (x.isZero()) {
77
- x = NEGATIVE_ZERO;
78
- }
79
- else {
80
- x = x.negated();
81
- }
82
- }
83
- return { roundedNumber: x, formattedString: string };
84
- }
@@ -1,2 +0,0 @@
1
- import { RoundingModeType, UnsignedRoundingModeType } from '../types/number';
2
- export declare function GetUnsignedRoundingMode(roundingMode: RoundingModeType, isNegative: boolean): UnsignedRoundingModeType;
@@ -1,28 +0,0 @@
1
- var negativeMapping = {
2
- ceil: 'zero',
3
- floor: 'infinity',
4
- expand: 'infinity',
5
- trunc: 'zero',
6
- halfCeil: 'half-zero',
7
- halfFloor: 'half-infinity',
8
- halfExpand: 'half-infinity',
9
- halfTrunc: 'half-zero',
10
- halfEven: 'half-even',
11
- };
12
- var positiveMapping = {
13
- ceil: 'infinity',
14
- floor: 'zero',
15
- expand: 'infinity',
16
- trunc: 'zero',
17
- halfCeil: 'half-infinity',
18
- halfFloor: 'half-zero',
19
- halfExpand: 'half-infinity',
20
- halfTrunc: 'half-zero',
21
- halfEven: 'half-even',
22
- };
23
- export function GetUnsignedRoundingMode(roundingMode, isNegative) {
24
- if (isNegative) {
25
- return negativeMapping[roundingMode];
26
- }
27
- return positiveMapping[roundingMode];
28
- }
@@ -1,12 +0,0 @@
1
- import { NumberFormatInternal, NumberFormatLocaleInternalData, NumberFormatOptions } from '../types/number';
2
- /**
3
- * https://tc39.es/ecma402/#sec-initializenumberformat
4
- */
5
- export declare function InitializeNumberFormat(nf: Intl.NumberFormat, locales: string | ReadonlyArray<string> | undefined, opts: NumberFormatOptions | undefined, { getInternalSlots, localeData, availableLocales, numberingSystemNames, getDefaultLocale, currencyDigitsData, }: {
6
- getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
7
- localeData: Record<string, NumberFormatLocaleInternalData | undefined>;
8
- availableLocales: Set<string>;
9
- numberingSystemNames: ReadonlyArray<string>;
10
- getDefaultLocale(): string;
11
- currencyDigitsData: Record<string, number>;
12
- }): Intl.NumberFormat;