@formatjs/ecma402-abstract 3.0.6 → 3.0.8

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 (99) hide show
  1. package/262.d.ts +55 -55
  2. package/262.js +322 -327
  3. package/CanonicalizeLocaleList.d.ts +3 -3
  4. package/CanonicalizeLocaleList.js +5 -5
  5. package/CanonicalizeTimeZoneName.d.ts +13 -6
  6. package/CanonicalizeTimeZoneName.js +88 -15
  7. package/CoerceOptionsToObject.d.ts +4 -4
  8. package/CoerceOptionsToObject.js +9 -9
  9. package/DefaultNumberOption.d.ts +6 -6
  10. package/DefaultNumberOption.js +15 -15
  11. package/GetNumberOption.d.ts +5 -9
  12. package/GetNumberOption.js +10 -10
  13. package/GetOption.d.ts +12 -8
  14. package/GetOption.js +28 -28
  15. package/GetOptionsObject.d.ts +4 -4
  16. package/GetOptionsObject.js +11 -11
  17. package/GetStringOrBooleanOption.d.ts +4 -10
  18. package/GetStringOrBooleanOption.js +28 -28
  19. package/IsSanctionedSimpleUnitIdentifier.d.ts +8 -6
  20. package/IsSanctionedSimpleUnitIdentifier.js +53 -53
  21. package/IsValidTimeZoneName.d.ts +15 -7
  22. package/IsValidTimeZoneName.js +69 -15
  23. package/IsWellFormedCurrencyCode.d.ts +2 -2
  24. package/IsWellFormedCurrencyCode.js +15 -15
  25. package/IsWellFormedUnitIdentifier.d.ts +3 -3
  26. package/IsWellFormedUnitIdentifier.js +21 -22
  27. package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
  28. package/NumberFormat/ApplyUnsignedRoundingMode.js +31 -31
  29. package/NumberFormat/CollapseNumberRange.d.ts +6 -6
  30. package/NumberFormat/CollapseNumberRange.js +47 -47
  31. package/NumberFormat/ComputeExponent.d.ts +8 -8
  32. package/NumberFormat/ComputeExponent.js +48 -58
  33. package/NumberFormat/ComputeExponentForMagnitude.d.ts +6 -6
  34. package/NumberFormat/ComputeExponentForMagnitude.js +64 -63
  35. package/NumberFormat/CurrencyDigits.d.ts +3 -3
  36. package/NumberFormat/CurrencyDigits.js +5 -8
  37. package/NumberFormat/FormatApproximately.d.ts +3 -3
  38. package/NumberFormat/FormatApproximately.js +10 -6
  39. package/NumberFormat/FormatNumeric.d.ts +2 -2
  40. package/NumberFormat/FormatNumeric.js +4 -3
  41. package/NumberFormat/FormatNumericRange.d.ts +6 -6
  42. package/NumberFormat/FormatNumericRange.js +7 -9
  43. package/NumberFormat/FormatNumericRangeToParts.d.ts +6 -6
  44. package/NumberFormat/FormatNumericRangeToParts.js +12 -14
  45. package/NumberFormat/FormatNumericToParts.d.ts +3 -3
  46. package/NumberFormat/FormatNumericToParts.js +12 -12
  47. package/NumberFormat/FormatNumericToString.d.ts +7 -7
  48. package/NumberFormat/FormatNumericToString.js +79 -81
  49. package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
  50. package/NumberFormat/GetUnsignedRoundingMode.js +25 -24
  51. package/NumberFormat/InitializeNumberFormat.d.ts +10 -10
  52. package/NumberFormat/InitializeNumberFormat.js +83 -64
  53. package/NumberFormat/PartitionNumberPattern.d.ts +4 -4
  54. package/NumberFormat/PartitionNumberPattern.js +112 -123
  55. package/NumberFormat/PartitionNumberRangePattern.d.ts +6 -6
  56. package/NumberFormat/PartitionNumberRangePattern.js +41 -38
  57. package/NumberFormat/SetNumberFormatDigitOptions.d.ts +3 -3
  58. package/NumberFormat/SetNumberFormatDigitOptions.js +185 -174
  59. package/NumberFormat/SetNumberFormatUnitOptions.d.ts +3 -3
  60. package/NumberFormat/SetNumberFormatUnitOptions.js +62 -48
  61. package/NumberFormat/ToRawFixed.d.ts +7 -7
  62. package/NumberFormat/ToRawFixed.js +103 -107
  63. package/NumberFormat/ToRawPrecision.d.ts +7 -7
  64. package/NumberFormat/ToRawPrecision.js +199 -202
  65. package/NumberFormat/decimal-cache.d.ts +10 -10
  66. package/NumberFormat/decimal-cache.js +13 -13
  67. package/NumberFormat/digit-mapping.generated.js +781 -781
  68. package/NumberFormat/format_to_parts.d.ts +24 -20
  69. package/NumberFormat/format_to_parts.js +446 -420
  70. package/PartitionPattern.d.ts +6 -6
  71. package/PartitionPattern.js +33 -33
  72. package/SupportedLocales.d.ts +6 -6
  73. package/SupportedLocales.js +17 -17
  74. package/ToIntlMathematicalValue.d.ts +1 -1
  75. package/ToIntlMathematicalValue.js +24 -25
  76. package/constants.d.ts +1 -1
  77. package/constants.js +4 -4
  78. package/data.d.ts +1 -1
  79. package/data.js +4 -11
  80. package/index.d.ts +47 -47
  81. package/index.js +45 -45
  82. package/package.json +3 -3
  83. package/regex.generated.d.ts +1 -0
  84. package/regex.generated.js +1 -1
  85. package/types/core.d.ts +5 -5
  86. package/types/date-time.d.ts +123 -128
  87. package/types/date-time.js +6 -6
  88. package/types/displaynames.d.ts +55 -55
  89. package/types/displaynames.js +1 -1
  90. package/types/list.d.ts +11 -11
  91. package/types/list.js +1 -1
  92. package/types/number.d.ts +151 -137
  93. package/types/number.js +2 -1
  94. package/types/plural-rules.d.ts +11 -11
  95. package/types/plural-rules.js +2 -1
  96. package/types/relative-time.d.ts +26 -32
  97. package/types/relative-time.js +2 -1
  98. package/utils.d.ts +40 -14
  99. package/utils.js +63 -116
@@ -1,66 +1,67 @@
1
- import { Decimal } from 'decimal.js';
2
- import { invariant } from '../utils.js';
3
- import { getPowerOf10 } from './decimal-cache.js';
4
- Decimal.set({
5
- toExpPos: 100,
6
- });
1
+ import { Decimal } from "decimal.js";
2
+ import "../types/number.js";
3
+ import { invariant } from "../utils.js";
4
+ import { getPowerOf10 } from "./decimal-cache.js";
5
+ Decimal.set({ toExpPos: 100 });
7
6
  /**
8
- * The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
9
- * number of the given magnitude (power of ten of the most significant digit) according to the
10
- * locale and the desired notation (scientific, engineering, or compact).
11
- */
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
+ */
12
11
  export function ComputeExponentForMagnitude(internalSlots, magnitude) {
13
- var notation = internalSlots.notation, dataLocaleData = internalSlots.dataLocaleData, numberingSystem = internalSlots.numberingSystem;
14
- switch (notation) {
15
- case 'standard':
16
- return 0;
17
- case 'scientific':
18
- return magnitude.toNumber();
19
- case 'engineering':
20
- var thousands = magnitude.div(3).floor();
21
- return thousands.times(3).toNumber();
22
- default: {
23
- invariant(notation === 'compact', 'Invalid notation');
24
- // Let exponent be an implementation- and locale-dependent (ILD) integer by which to scale a
25
- // number of the given magnitude in compact notation for the current locale.
26
- var compactDisplay = internalSlots.compactDisplay, style = internalSlots.style, currencyDisplay = internalSlots.currencyDisplay;
27
- var thresholdMap = void 0;
28
- if (style === 'currency' && currencyDisplay !== 'name') {
29
- var currency = dataLocaleData.numbers.currency[numberingSystem] ||
30
- dataLocaleData.numbers.currency[dataLocaleData.numbers.nu[0]];
31
- thresholdMap = currency.short;
32
- }
33
- else {
34
- var decimal = dataLocaleData.numbers.decimal[numberingSystem] ||
35
- dataLocaleData.numbers.decimal[dataLocaleData.numbers.nu[0]];
36
- thresholdMap = compactDisplay === 'long' ? decimal.long : decimal.short;
37
- }
38
- if (!thresholdMap) {
39
- return 0;
40
- }
41
- var num = getPowerOf10(magnitude).toString();
42
- var thresholds = Object.keys(thresholdMap); // TODO: this can be pre-processed
43
- if (num < thresholds[0]) {
44
- return 0;
45
- }
46
- if (num > thresholds[thresholds.length - 1]) {
47
- return thresholds[thresholds.length - 1].length - 1;
48
- }
49
- var i = thresholds.indexOf(num);
50
- if (i === -1) {
51
- return 0;
52
- }
53
- // See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
54
- // Special handling if the pattern is precisely `0`.
55
- var magnitudeKey = thresholds[i];
56
- // TODO: do we need to handle plural here?
57
- var compactPattern = thresholdMap[magnitudeKey].other;
58
- if (compactPattern === '0') {
59
- return 0;
60
- }
61
- // Example: in zh-TW, `10000000` maps to `0000萬`. So we need to return 8 - 4 = 4 here.
62
- return (magnitudeKey.length -
63
- thresholdMap[magnitudeKey].other.match(/0+/)[0].length);
64
- }
65
- }
12
+ const { notation, dataLocaleData, numberingSystem } = internalSlots;
13
+ switch (notation) {
14
+ case "standard": return 0;
15
+ case "scientific": return magnitude.toNumber();
16
+ case "engineering":
17
+ const thousands = magnitude.div(3).floor();
18
+ return thousands.times(3).toNumber();
19
+ default: {
20
+ invariant(notation === "compact", "Invalid notation");
21
+ // Let exponent be an implementation- and locale-dependent (ILD) integer by which to scale a
22
+ // number of the given magnitude in compact notation for the current locale.
23
+ const { compactDisplay, style, currencyDisplay } = internalSlots;
24
+ let thresholdMap;
25
+ if (style === "currency" && currencyDisplay !== "name") {
26
+ const currency = dataLocaleData.numbers.currency[numberingSystem] || dataLocaleData.numbers.currency[dataLocaleData.numbers.nu[0]];
27
+ thresholdMap = currency.short;
28
+ } else {
29
+ const decimal = dataLocaleData.numbers.decimal[numberingSystem] || dataLocaleData.numbers.decimal[dataLocaleData.numbers.nu[0]];
30
+ thresholdMap = compactDisplay === "long" ? decimal.long : decimal.short;
31
+ }
32
+ if (!thresholdMap) {
33
+ return 0;
34
+ }
35
+ const num = getPowerOf10(magnitude).toString();
36
+ const thresholds = Object.keys(thresholdMap);
37
+ if (num < thresholds[0]) {
38
+ return 0;
39
+ }
40
+ if (num > thresholds[thresholds.length - 1]) {
41
+ // GH #4236: When number exceeds max threshold, use the exponent
42
+ // corresponding to the largest available threshold in locale data.
43
+ // Calculate exponent the same way as for normal thresholds (lines 70-73).
44
+ const magnitudeKey = thresholds[thresholds.length - 1];
45
+ const compactPattern = thresholdMap[magnitudeKey].other;
46
+ if (compactPattern === "0") {
47
+ return 0;
48
+ }
49
+ return magnitudeKey.length - thresholdMap[magnitudeKey].other.match(/0+/)[0].length;
50
+ }
51
+ const i = thresholds.indexOf(num);
52
+ if (i === -1) {
53
+ return 0;
54
+ }
55
+ // See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
56
+ // Special handling if the pattern is precisely `0`.
57
+ const magnitudeKey = thresholds[i];
58
+ // TODO: do we need to handle plural here?
59
+ const compactPattern = thresholdMap[magnitudeKey].other;
60
+ if (compactPattern === "0") {
61
+ return 0;
62
+ }
63
+ // Example: in zh-TW, `10000000` maps to `0000萬`. So we need to return 8 - 4 = 4 here.
64
+ return magnitudeKey.length - thresholdMap[magnitudeKey].other.match(/0+/)[0].length;
65
+ }
66
+ }
66
67
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
- * https://tc39.es/ecma402/#sec-currencydigits
3
- */
2
+ * https://tc39.es/ecma402/#sec-currencydigits
3
+ */
4
4
  export declare function CurrencyDigits(c: string, { currencyDigitsData }: {
5
- currencyDigitsData: Record<string, number>;
5
+ currencyDigitsData: Record<string, number>;
6
6
  }): number;
@@ -1,10 +1,7 @@
1
- import { HasOwnProperty } from '../262.js';
1
+ import { HasOwnProperty } from "../262.js";
2
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;
3
+ * https://tc39.es/ecma402/#sec-currencydigits
4
+ */
5
+ export function CurrencyDigits(c, { currencyDigitsData }) {
6
+ return HasOwnProperty(currencyDigitsData, c) ? currencyDigitsData[c] : 2;
10
7
  }
@@ -1,5 +1,5 @@
1
- import { NumberFormatInternal, NumberFormatPart } from '../types/number.js';
1
+ import { type NumberFormatInternal, type NumberFormatPart } from "../types/number.js";
2
2
  /**
3
- * https://tc39.es/ecma402/#sec-formatapproximately
4
- */
3
+ * https://tc39.es/ecma402/#sec-formatapproximately
4
+ */
5
5
  export declare function FormatApproximately(internalSlots: NumberFormatInternal, result: NumberFormatPart[]): NumberFormatPart[];
@@ -1,9 +1,13 @@
1
+ import "../types/number.js";
1
2
  /**
2
- * https://tc39.es/ecma402/#sec-formatapproximately
3
- */
3
+ * https://tc39.es/ecma402/#sec-formatapproximately
4
+ */
4
5
  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;
6
+ const symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
7
+ const approximatelySign = symbols.approximatelySign;
8
+ result.push({
9
+ type: "approximatelySign",
10
+ value: approximatelySign
11
+ });
12
+ return result;
9
13
  }
@@ -1,3 +1,3 @@
1
- import { Decimal } from 'decimal.js';
2
- import { NumberFormatInternal } from '../types/number.js';
1
+ import type { Decimal } from "decimal.js";
2
+ import { type NumberFormatInternal } from "../types/number.js";
3
3
  export declare function FormatNumeric(internalSlots: NumberFormatInternal, x: Decimal): string;
@@ -1,5 +1,6 @@
1
- import { PartitionNumberPattern } from './PartitionNumberPattern.js';
1
+ import "../types/number.js";
2
+ import { PartitionNumberPattern } from "./PartitionNumberPattern.js";
2
3
  export function FormatNumeric(internalSlots, x) {
3
- var parts = PartitionNumberPattern(internalSlots, x);
4
- return parts.map(function (p) { return p.value; }).join('');
4
+ const parts = PartitionNumberPattern(internalSlots, x);
5
+ return parts.map((p) => p.value).join("");
5
6
  }
@@ -1,8 +1,8 @@
1
- import { Decimal } from 'decimal.js';
2
- import { NumberFormatInternal } from '../types/number.js';
1
+ import type { Decimal } from "decimal.js";
2
+ import { type NumberFormatInternal } from "../types/number.js";
3
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;
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
8
  }): string;
@@ -1,11 +1,9 @@
1
- import { PartitionNumberRangePattern } from './PartitionNumberRangePattern.js';
1
+ import "../types/number.js";
2
+ import { PartitionNumberRangePattern } from "./PartitionNumberRangePattern.js";
2
3
  /**
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('');
4
+ * https://tc39.es/ecma402/#sec-formatnumericrange
5
+ */
6
+ export function FormatNumericRange(numberFormat, x, y, { getInternalSlots }) {
7
+ const parts = PartitionNumberRangePattern(numberFormat, x, y, { getInternalSlots });
8
+ return parts.map((part) => part.value).join("");
11
9
  }
@@ -1,8 +1,8 @@
1
- import { Decimal } from 'decimal.js';
2
- import { NumberFormatInternal, NumberRangeToParts } from '../types/number.js';
1
+ import type { Decimal } from "decimal.js";
2
+ import { type NumberFormatInternal, type NumberRangeToParts } from "../types/number.js";
3
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;
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
8
  }): NumberRangeToParts[];
@@ -1,16 +1,14 @@
1
- import { PartitionNumberRangePattern } from './PartitionNumberRangePattern.js';
1
+ import "../types/number.js";
2
+ import { PartitionNumberRangePattern } from "./PartitionNumberRangePattern.js";
2
3
  /**
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
- }); });
4
+ * https://tc39.es/ecma402/#sec-formatnumericrangetoparts
5
+ */
6
+ export function FormatNumericRangeToParts(numberFormat, x, y, { getInternalSlots }) {
7
+ const parts = PartitionNumberRangePattern(numberFormat, x, y, { getInternalSlots });
8
+ return parts.map((part, index) => ({
9
+ type: part.type,
10
+ value: part.value,
11
+ source: part.source,
12
+ result: index.toString()
13
+ }));
16
14
  }
@@ -1,5 +1,5 @@
1
- import { Decimal } from 'decimal.js';
2
- import { NumberFormatInternal, NumberFormatPart } from '../types/number.js';
1
+ import type { Decimal } from "decimal.js";
2
+ import { type NumberFormatInternal, type NumberFormatPart } from "../types/number.js";
3
3
  export declare function FormatNumericToParts(nf: Intl.NumberFormat, x: Decimal, implDetails: {
4
- getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
4
+ getInternalSlots(nf: Intl.NumberFormat): NumberFormatInternal;
5
5
  }): NumberFormatPart[];
@@ -1,14 +1,14 @@
1
- import { ArrayCreate } from '../262.js';
2
- import { PartitionNumberPattern } from './PartitionNumberPattern.js';
1
+ import { ArrayCreate } from "../262.js";
2
+ import "../types/number.js";
3
+ import { PartitionNumberPattern } from "./PartitionNumberPattern.js";
3
4
  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;
5
+ const parts = PartitionNumberPattern(implDetails.getInternalSlots(nf), x);
6
+ const result = ArrayCreate(0);
7
+ for (const part of parts) {
8
+ result.push({
9
+ type: part.type,
10
+ value: part.value
11
+ });
12
+ }
13
+ return result;
14
14
  }
@@ -1,9 +1,9 @@
1
- import { Decimal } from 'decimal.js';
2
- import { NumberFormatDigitInternalSlots } from '../types/number.js';
1
+ import type { Decimal } from "decimal.js";
2
+ import { type NumberFormatDigitInternalSlots } from "../types/number.js";
3
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;
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
9
  };
@@ -1,84 +1,82 @@
1
- import { NEGATIVE_ZERO, ZERO } from '../constants.js';
2
- import { invariant, repeat } from '../utils.js';
3
- import { GetUnsignedRoundingMode } from './GetUnsignedRoundingMode.js';
4
- import { ToRawFixed } from './ToRawFixed.js';
5
- import { ToRawPrecision } from './ToRawPrecision.js';
1
+ import { NEGATIVE_ZERO, ZERO } from "../constants.js";
2
+ import "../types/number.js";
3
+ import { invariant, repeat } from "../utils.js";
4
+ import { GetUnsignedRoundingMode } from "./GetUnsignedRoundingMode.js";
5
+ import { ToRawFixed } from "./ToRawFixed.js";
6
+ import { ToRawPrecision } from "./ToRawPrecision.js";
6
7
  /**
7
- * https://tc39.es/ecma402/#sec-formatnumberstring
8
- */
8
+ * https://tc39.es/ecma402/#sec-formatnumberstring
9
+ */
9
10
  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 };
11
+ let x = _x;
12
+ let sign;
13
+ // -0
14
+ if (x.isZero() && x.isNegative()) {
15
+ sign = "negative";
16
+ x = ZERO;
17
+ } else {
18
+ invariant(x.isFinite(), "NumberFormatDigitInternalSlots value is not finite");
19
+ if (x.lessThan(0)) {
20
+ sign = "negative";
21
+ } else {
22
+ sign = "positive";
23
+ }
24
+ if (sign === "negative") {
25
+ x = x.negated();
26
+ }
27
+ }
28
+ let result;
29
+ const roundingType = intlObject.roundingType;
30
+ const unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign === "negative");
31
+ switch (roundingType) {
32
+ case "significantDigits":
33
+ result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
34
+ break;
35
+ case "fractionDigits":
36
+ result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
37
+ break;
38
+ default:
39
+ let sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
40
+ let fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
41
+ if (intlObject.roundingType === "morePrecision") {
42
+ if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
43
+ result = sResult;
44
+ } else {
45
+ result = fResult;
46
+ }
47
+ } else {
48
+ invariant(intlObject.roundingType === "lessPrecision", "Invalid roundingType");
49
+ if (sResult.roundingMagnitude <= fResult.roundingMagnitude) {
50
+ result = fResult;
51
+ } else {
52
+ result = sResult;
53
+ }
54
+ }
55
+ break;
56
+ }
57
+ x = result.roundedNumber;
58
+ let string = result.formattedString;
59
+ if (intlObject.trailingZeroDisplay === "stripIfInteger" && x.isInteger()) {
60
+ let i = string.indexOf(".");
61
+ if (i > -1) {
62
+ string = string.slice(0, i);
63
+ }
64
+ }
65
+ const int = result.integerDigitsCount;
66
+ const minInteger = intlObject.minimumIntegerDigits;
67
+ if (int < minInteger) {
68
+ const forwardZeros = repeat("0", minInteger - int);
69
+ string = forwardZeros + string;
70
+ }
71
+ if (sign === "negative") {
72
+ if (x.isZero()) {
73
+ x = NEGATIVE_ZERO;
74
+ } else {
75
+ x = x.negated();
76
+ }
77
+ }
78
+ return {
79
+ roundedNumber: x,
80
+ formattedString: string
81
+ };
84
82
  }
@@ -1,2 +1,2 @@
1
- import { RoundingModeType, UnsignedRoundingModeType } from '../types/number.js';
1
+ import { type RoundingModeType, type UnsignedRoundingModeType } from "../types/number.js";
2
2
  export declare function GetUnsignedRoundingMode(roundingMode: RoundingModeType, isNegative: boolean): UnsignedRoundingModeType;
@@ -1,28 +1,29 @@
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',
1
+ import "../types/number.js";
2
+ const negativeMapping = {
3
+ ceil: "zero",
4
+ floor: "infinity",
5
+ expand: "infinity",
6
+ trunc: "zero",
7
+ halfCeil: "half-zero",
8
+ halfFloor: "half-infinity",
9
+ halfExpand: "half-infinity",
10
+ halfTrunc: "half-zero",
11
+ halfEven: "half-even"
11
12
  };
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',
13
+ const positiveMapping = {
14
+ ceil: "infinity",
15
+ floor: "zero",
16
+ expand: "infinity",
17
+ trunc: "zero",
18
+ halfCeil: "half-infinity",
19
+ halfFloor: "half-zero",
20
+ halfExpand: "half-infinity",
21
+ halfTrunc: "half-zero",
22
+ halfEven: "half-even"
22
23
  };
23
24
  export function GetUnsignedRoundingMode(roundingMode, isNegative) {
24
- if (isNegative) {
25
- return negativeMapping[roundingMode];
26
- }
27
- return positiveMapping[roundingMode];
25
+ if (isNegative) {
26
+ return negativeMapping[roundingMode];
27
+ }
28
+ return positiveMapping[roundingMode];
28
29
  }
@@ -1,12 +1,12 @@
1
- import { NumberFormatInternal, NumberFormatLocaleInternalData, NumberFormatOptions } from '../types/number.js';
1
+ import { type NumberFormatInternal, type NumberFormatLocaleInternalData, type NumberFormatOptions } from "../types/number.js";
2
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>;
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
12
  }): Intl.NumberFormat;