@formatjs/ecma402-abstract 1.17.4 → 1.18.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.
Files changed (65) hide show
  1. package/CanonicalizeTimeZoneName.d.ts +2 -2
  2. package/CanonicalizeTimeZoneName.js +2 -2
  3. package/DefaultNumberOption.d.ts +1 -1
  4. package/DefaultNumberOption.js +16 -8
  5. package/GetNumberOption.d.ts +1 -1
  6. package/GetNumberOption.js +0 -1
  7. package/GetOption.d.ts +1 -1
  8. package/IsValidTimeZoneName.d.ts +2 -2
  9. package/IsValidTimeZoneName.js +2 -4
  10. package/LICENSE.md +1 -1
  11. package/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  12. package/NumberFormat/SetNumberFormatDigitOptions.js +2 -3
  13. package/lib/262.js +23 -49
  14. package/lib/CanonicalizeLocaleList.js +1 -5
  15. package/lib/CanonicalizeTimeZoneName.d.ts +2 -2
  16. package/lib/CanonicalizeTimeZoneName.js +3 -7
  17. package/lib/CoerceOptionsToObject.js +3 -7
  18. package/lib/DefaultNumberOption.d.ts +1 -1
  19. package/lib/DefaultNumberOption.js +16 -12
  20. package/lib/GetNumberOption.d.ts +1 -1
  21. package/lib/GetNumberOption.js +3 -8
  22. package/lib/GetOption.d.ts +1 -1
  23. package/lib/GetOption.js +3 -7
  24. package/lib/GetOptionsObject.js +1 -5
  25. package/lib/GetStringOrBooleanOption.js +3 -7
  26. package/lib/IsSanctionedSimpleUnitIdentifier.js +5 -10
  27. package/lib/IsValidTimeZoneName.d.ts +2 -2
  28. package/lib/IsValidTimeZoneName.js +3 -9
  29. package/lib/IsWellFormedCurrencyCode.js +1 -5
  30. package/lib/IsWellFormedUnitIdentifier.js +5 -9
  31. package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +1 -5
  32. package/lib/NumberFormat/CollapseNumberRange.js +1 -5
  33. package/lib/NumberFormat/ComputeExponent.js +9 -13
  34. package/lib/NumberFormat/ComputeExponentForMagnitude.js +1 -5
  35. package/lib/NumberFormat/CurrencyDigits.js +3 -7
  36. package/lib/NumberFormat/FormatApproximately.js +1 -5
  37. package/lib/NumberFormat/FormatNumericRange.js +3 -7
  38. package/lib/NumberFormat/FormatNumericRangeToParts.js +3 -7
  39. package/lib/NumberFormat/FormatNumericToParts.js +5 -9
  40. package/lib/NumberFormat/FormatNumericToString.js +11 -15
  41. package/lib/NumberFormat/GetUnsignedRoundingMode.js +1 -5
  42. package/lib/NumberFormat/InitializeNumberFormat.js +27 -31
  43. package/lib/NumberFormat/PartitionNumberPattern.js +11 -16
  44. package/lib/NumberFormat/PartitionNumberRangePattern.js +8 -12
  45. package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +1 -1
  46. package/lib/NumberFormat/SetNumberFormatDigitOptions.js +11 -16
  47. package/lib/NumberFormat/SetNumberFormatUnitOptions.js +12 -16
  48. package/lib/NumberFormat/ToRawFixed.js +4 -8
  49. package/lib/NumberFormat/ToRawPrecision.js +7 -11
  50. package/lib/NumberFormat/digit-mapping.generated.js +1 -4
  51. package/lib/NumberFormat/format_to_parts.js +8 -11
  52. package/lib/PartitionPattern.js +3 -7
  53. package/lib/SupportedLocales.js +8 -12
  54. package/lib/data.js +3 -7
  55. package/lib/index.js +42 -56
  56. package/lib/regex.generated.js +1 -4
  57. package/lib/types/core.js +1 -2
  58. package/lib/types/date-time.js +2 -5
  59. package/lib/types/displaynames.js +1 -2
  60. package/lib/types/list.js +1 -2
  61. package/lib/types/number.js +1 -2
  62. package/lib/types/plural-rules.js +1 -2
  63. package/lib/types/relative-time.js +1 -2
  64. package/lib/utils.js +10 -22
  65. package/package.json +2 -2
@@ -3,7 +3,7 @@
3
3
  * @param tz
4
4
  * @param implDetails implementation details
5
5
  */
6
- export declare function IsValidTimeZoneName(tz: string, { tzData, uppercaseLinks, }: {
7
- tzData: Record<string, unknown>;
6
+ export declare function IsValidTimeZoneName(tz: string, { zoneNamesFromData, uppercaseLinks, }: {
7
+ zoneNamesFromData: readonly string[];
8
8
  uppercaseLinks: Record<string, string>;
9
9
  }): boolean;
@@ -1,23 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsValidTimeZoneName = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#sec-isvalidtimezonename
6
3
  * @param tz
7
4
  * @param implDetails implementation details
8
5
  */
9
- function IsValidTimeZoneName(tz, _a) {
10
- var tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
6
+ export function IsValidTimeZoneName(tz, _a) {
7
+ var zoneNamesFromData = _a.zoneNamesFromData, uppercaseLinks = _a.uppercaseLinks;
11
8
  var uppercasedTz = tz.toUpperCase();
12
9
  var zoneNames = new Set();
13
10
  var linkNames = new Set();
14
- Object.keys(tzData)
15
- .map(function (z) { return z.toUpperCase(); })
16
- .forEach(function (z) { return zoneNames.add(z); });
11
+ zoneNamesFromData.map(function (z) { return z.toUpperCase(); }).forEach(function (z) { return zoneNames.add(z); });
17
12
  Object.keys(uppercaseLinks).forEach(function (linkName) {
18
13
  linkNames.add(linkName.toUpperCase());
19
14
  zoneNames.add(uppercaseLinks[linkName].toUpperCase());
20
15
  });
21
16
  return zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz);
22
17
  }
23
- exports.IsValidTimeZoneName = IsValidTimeZoneName;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsWellFormedCurrencyCode = void 0;
4
1
  /**
5
2
  * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
6
3
  * @param str string to convert
@@ -12,7 +9,7 @@ var NOT_A_Z_REGEX = /[^A-Z]/;
12
9
  /**
13
10
  * https://tc39.es/ecma402/#sec-iswellformedcurrencycode
14
11
  */
15
- function IsWellFormedCurrencyCode(currency) {
12
+ export function IsWellFormedCurrencyCode(currency) {
16
13
  currency = toUpperCase(currency);
17
14
  if (currency.length !== 3) {
18
15
  return false;
@@ -22,4 +19,3 @@ function IsWellFormedCurrencyCode(currency) {
22
19
  }
23
20
  return true;
24
21
  }
25
- exports.IsWellFormedCurrencyCode = IsWellFormedCurrencyCode;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsWellFormedUnitIdentifier = void 0;
4
- var IsSanctionedSimpleUnitIdentifier_1 = require("./IsSanctionedSimpleUnitIdentifier");
1
+ import { IsSanctionedSimpleUnitIdentifier } from './IsSanctionedSimpleUnitIdentifier';
5
2
  /**
6
3
  * This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
7
4
  * @param str string to convert
@@ -13,9 +10,9 @@ function toLowerCase(str) {
13
10
  * https://tc39.es/ecma402/#sec-iswellformedunitidentifier
14
11
  * @param unit
15
12
  */
16
- function IsWellFormedUnitIdentifier(unit) {
13
+ export function IsWellFormedUnitIdentifier(unit) {
17
14
  unit = toLowerCase(unit);
18
- if ((0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(unit)) {
15
+ if (IsSanctionedSimpleUnitIdentifier(unit)) {
19
16
  return true;
20
17
  }
21
18
  var units = unit.split('-per-');
@@ -23,10 +20,9 @@ function IsWellFormedUnitIdentifier(unit) {
23
20
  return false;
24
21
  }
25
22
  var numerator = units[0], denominator = units[1];
26
- if (!(0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(numerator) ||
27
- !(0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(denominator)) {
23
+ if (!IsSanctionedSimpleUnitIdentifier(numerator) ||
24
+ !IsSanctionedSimpleUnitIdentifier(denominator)) {
28
25
  return false;
29
26
  }
30
27
  return true;
31
28
  }
32
- exports.IsWellFormedUnitIdentifier = IsWellFormedUnitIdentifier;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplyUnsignedRoundingMode = void 0;
4
- function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
1
+ export function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
5
2
  if (x === r1)
6
3
  return r1;
7
4
  if (unsignedRoundingMode === undefined) {
@@ -39,4 +36,3 @@ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
39
36
  }
40
37
  return r2;
41
38
  }
42
- exports.ApplyUnsignedRoundingMode = ApplyUnsignedRoundingMode;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollapseNumberRange = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#sec-collapsenumberrange
6
3
  */
7
- function CollapseNumberRange(result) {
4
+ export function CollapseNumberRange(result) {
8
5
  return result;
9
6
  }
10
- exports.CollapseNumberRange = CollapseNumberRange;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComputeExponent = void 0;
4
- var utils_1 = require("../utils");
5
- var ComputeExponentForMagnitude_1 = require("./ComputeExponentForMagnitude");
6
- var FormatNumericToString_1 = require("./FormatNumericToString");
1
+ import { getMagnitude } from '../utils';
2
+ import { ComputeExponentForMagnitude } from './ComputeExponentForMagnitude';
3
+ import { FormatNumericToString } from './FormatNumericToString';
7
4
  /**
8
5
  * The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x
9
6
  * according to the number formatting settings. It handles cases such as 999 rounding up to 1000,
@@ -11,7 +8,7 @@ var FormatNumericToString_1 = require("./FormatNumericToString");
11
8
  *
12
9
  * NOT IN SPEC: it returns [exponent, magnitude].
13
10
  */
14
- function ComputeExponent(numberFormat, x, _a) {
11
+ export function ComputeExponent(numberFormat, x, _a) {
15
12
  var getInternalSlots = _a.getInternalSlots;
16
13
  if (x === 0) {
17
14
  return [0, 0];
@@ -19,25 +16,24 @@ function ComputeExponent(numberFormat, x, _a) {
19
16
  if (x < 0) {
20
17
  x = -x;
21
18
  }
22
- var magnitude = (0, utils_1.getMagnitude)(x);
23
- var exponent = (0, ComputeExponentForMagnitude_1.ComputeExponentForMagnitude)(numberFormat, magnitude, {
19
+ var magnitude = getMagnitude(x);
20
+ var exponent = ComputeExponentForMagnitude(numberFormat, magnitude, {
24
21
  getInternalSlots: getInternalSlots,
25
22
  });
26
23
  // Preserve more precision by doing multiplication when exponent is negative.
27
24
  x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
28
- var formatNumberResult = (0, FormatNumericToString_1.FormatNumericToString)(getInternalSlots(numberFormat), x);
25
+ var formatNumberResult = FormatNumericToString(getInternalSlots(numberFormat), x);
29
26
  if (formatNumberResult.roundedNumber === 0) {
30
27
  return [exponent, magnitude];
31
28
  }
32
- var newMagnitude = (0, utils_1.getMagnitude)(formatNumberResult.roundedNumber);
29
+ var newMagnitude = getMagnitude(formatNumberResult.roundedNumber);
33
30
  if (newMagnitude === magnitude - exponent) {
34
31
  return [exponent, magnitude];
35
32
  }
36
33
  return [
37
- (0, ComputeExponentForMagnitude_1.ComputeExponentForMagnitude)(numberFormat, magnitude + 1, {
34
+ ComputeExponentForMagnitude(numberFormat, magnitude + 1, {
38
35
  getInternalSlots: getInternalSlots,
39
36
  }),
40
37
  magnitude + 1,
41
38
  ];
42
39
  }
43
- exports.ComputeExponent = ComputeExponent;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComputeExponentForMagnitude = void 0;
4
1
  /**
5
2
  * The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
6
3
  * number of the given magnitude (power of ten of the most significant digit) according to the
7
4
  * locale and the desired notation (scientific, engineering, or compact).
8
5
  */
9
- function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
6
+ export function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
10
7
  var getInternalSlots = _a.getInternalSlots;
11
8
  var internalSlots = getInternalSlots(numberFormat);
12
9
  var notation = internalSlots.notation, dataLocaleData = internalSlots.dataLocaleData, numberingSystem = internalSlots.numberingSystem;
@@ -61,4 +58,3 @@ function ComputeExponentForMagnitude(numberFormat, magnitude, _a) {
61
58
  }
62
59
  }
63
60
  }
64
- exports.ComputeExponentForMagnitude = ComputeExponentForMagnitude;
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CurrencyDigits = void 0;
4
- var _262_1 = require("../262");
1
+ import { HasOwnProperty } from '../262';
5
2
  /**
6
3
  * https://tc39.es/ecma402/#sec-currencydigits
7
4
  */
8
- function CurrencyDigits(c, _a) {
5
+ export function CurrencyDigits(c, _a) {
9
6
  var currencyDigitsData = _a.currencyDigitsData;
10
- return (0, _262_1.HasOwnProperty)(currencyDigitsData, c)
7
+ return HasOwnProperty(currencyDigitsData, c)
11
8
  ? currencyDigitsData[c]
12
9
  : 2;
13
10
  }
14
- exports.CurrencyDigits = CurrencyDigits;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatApproximately = void 0;
4
1
  /**
5
2
  * https://tc39.es/ecma402/#sec-formatapproximately
6
3
  */
7
- function FormatApproximately(numberFormat, result, _a) {
4
+ export function FormatApproximately(numberFormat, result, _a) {
8
5
  var getInternalSlots = _a.getInternalSlots;
9
6
  var internalSlots = getInternalSlots(numberFormat);
10
7
  var symbols = internalSlots.dataLocaleData.numbers.symbols[internalSlots.numberingSystem];
@@ -12,4 +9,3 @@ function FormatApproximately(numberFormat, result, _a) {
12
9
  result.push({ type: 'approximatelySign', value: approximatelySign });
13
10
  return result;
14
11
  }
15
- exports.FormatApproximately = FormatApproximately;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericRange = void 0;
4
- var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
1
+ import { PartitionNumberRangePattern } from './PartitionNumberRangePattern';
5
2
  /**
6
3
  * https://tc39.es/ecma402/#sec-formatnumericrange
7
4
  */
8
- function FormatNumericRange(numberFormat, x, y, _a) {
5
+ export function FormatNumericRange(numberFormat, x, y, _a) {
9
6
  var getInternalSlots = _a.getInternalSlots;
10
- var parts = (0, PartitionNumberRangePattern_1.PartitionNumberRangePattern)(numberFormat, x, y, {
7
+ var parts = PartitionNumberRangePattern(numberFormat, x, y, {
11
8
  getInternalSlots: getInternalSlots,
12
9
  });
13
10
  return parts.map(function (part) { return part.value; }).join('');
14
11
  }
15
- exports.FormatNumericRange = FormatNumericRange;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericRangeToParts = void 0;
4
- var PartitionNumberRangePattern_1 = require("./PartitionNumberRangePattern");
1
+ import { PartitionNumberRangePattern } from './PartitionNumberRangePattern';
5
2
  /**
6
3
  * https://tc39.es/ecma402/#sec-formatnumericrangetoparts
7
4
  */
8
- function FormatNumericRangeToParts(numberFormat, x, y, _a) {
5
+ export function FormatNumericRangeToParts(numberFormat, x, y, _a) {
9
6
  var getInternalSlots = _a.getInternalSlots;
10
- var parts = (0, PartitionNumberRangePattern_1.PartitionNumberRangePattern)(numberFormat, x, y, {
7
+ var parts = PartitionNumberRangePattern(numberFormat, x, y, {
11
8
  getInternalSlots: getInternalSlots,
12
9
  });
13
10
  return parts.map(function (part, index) { return ({
@@ -17,4 +14,3 @@ function FormatNumericRangeToParts(numberFormat, x, y, _a) {
17
14
  result: index.toString(),
18
15
  }); });
19
16
  }
20
- exports.FormatNumericRangeToParts = FormatNumericRangeToParts;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericToParts = void 0;
4
- var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
5
- var _262_1 = require("../262");
6
- function FormatNumericToParts(nf, x, implDetails) {
7
- var parts = (0, PartitionNumberPattern_1.PartitionNumberPattern)(nf, x, implDetails);
8
- var result = (0, _262_1.ArrayCreate)(0);
1
+ import { PartitionNumberPattern } from './PartitionNumberPattern';
2
+ import { ArrayCreate } from '../262';
3
+ export function FormatNumericToParts(nf, x, implDetails) {
4
+ var parts = PartitionNumberPattern(nf, x, implDetails);
5
+ var result = ArrayCreate(0);
9
6
  for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
10
7
  var part = parts_1[_i];
11
8
  result.push({
@@ -15,4 +12,3 @@ function FormatNumericToParts(nf, x, implDetails) {
15
12
  }
16
13
  return result;
17
14
  }
18
- exports.FormatNumericToParts = FormatNumericToParts;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatNumericToString = void 0;
4
- var _262_1 = require("../262");
5
- var ToRawPrecision_1 = require("./ToRawPrecision");
6
- var utils_1 = require("../utils");
7
- var ToRawFixed_1 = require("./ToRawFixed");
1
+ import { SameValue } from '../262';
2
+ import { ToRawPrecision } from './ToRawPrecision';
3
+ import { repeat } from '../utils';
4
+ import { ToRawFixed } from './ToRawFixed';
8
5
  /**
9
6
  * https://tc39.es/ecma402/#sec-formatnumberstring
10
7
  */
11
- function FormatNumericToString(intlObject, x) {
12
- var isNegative = x < 0 || (0, _262_1.SameValue)(x, -0);
8
+ export function FormatNumericToString(intlObject, x) {
9
+ var isNegative = x < 0 || SameValue(x, -0);
13
10
  if (isNegative) {
14
11
  x = -x;
15
12
  }
@@ -17,15 +14,15 @@ function FormatNumericToString(intlObject, x) {
17
14
  var rourndingType = intlObject.roundingType;
18
15
  switch (rourndingType) {
19
16
  case 'significantDigits':
20
- result = (0, ToRawPrecision_1.ToRawPrecision)(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
17
+ result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits);
21
18
  break;
22
19
  case 'fractionDigits':
23
- result = (0, ToRawFixed_1.ToRawFixed)(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
20
+ result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits);
24
21
  break;
25
22
  default:
26
- result = (0, ToRawPrecision_1.ToRawPrecision)(x, 1, 2);
23
+ result = ToRawPrecision(x, 1, 2);
27
24
  if (result.integerDigitsCount > 1) {
28
- result = (0, ToRawFixed_1.ToRawFixed)(x, 0, 0);
25
+ result = ToRawFixed(x, 0, 0);
29
26
  }
30
27
  break;
31
28
  }
@@ -34,7 +31,7 @@ function FormatNumericToString(intlObject, x) {
34
31
  var int = result.integerDigitsCount;
35
32
  var minInteger = intlObject.minimumIntegerDigits;
36
33
  if (int < minInteger) {
37
- var forwardZeros = (0, utils_1.repeat)('0', minInteger - int);
34
+ var forwardZeros = repeat('0', minInteger - int);
38
35
  string = forwardZeros + string;
39
36
  }
40
37
  if (isNegative) {
@@ -42,4 +39,3 @@ function FormatNumericToString(intlObject, x) {
42
39
  }
43
40
  return { roundedNumber: x, formattedString: string };
44
41
  }
45
- exports.FormatNumericToString = FormatNumericToString;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetUnsignedRoundingMode = void 0;
4
1
  var negativeMapping = {
5
2
  ceil: 'zero',
6
3
  floor: 'infinity',
@@ -23,10 +20,9 @@ var positiveMapping = {
23
20
  halfTrunc: 'half-zero',
24
21
  halfEven: 'half-even',
25
22
  };
26
- function GetUnsignedRoundingMode(roundingMode, isNegative) {
23
+ export function GetUnsignedRoundingMode(roundingMode, isNegative) {
27
24
  if (isNegative) {
28
25
  return negativeMapping[roundingMode];
29
26
  }
30
27
  return positiveMapping[roundingMode];
31
28
  }
32
- exports.GetUnsignedRoundingMode = GetUnsignedRoundingMode;
@@ -1,31 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InitializeNumberFormat = void 0;
4
- var intl_localematcher_1 = require("@formatjs/intl-localematcher");
5
- var CanonicalizeLocaleList_1 = require("../CanonicalizeLocaleList");
6
- var CoerceOptionsToObject_1 = require("../CoerceOptionsToObject");
7
- var GetNumberOption_1 = require("../GetNumberOption");
8
- var GetOption_1 = require("../GetOption");
9
- var GetStringOrBooleanOption_1 = require("../GetStringOrBooleanOption");
10
- var utils_1 = require("../utils");
11
- var CurrencyDigits_1 = require("./CurrencyDigits");
12
- var SetNumberFormatDigitOptions_1 = require("./SetNumberFormatDigitOptions");
13
- var SetNumberFormatUnitOptions_1 = require("./SetNumberFormatUnitOptions");
1
+ import { ResolveLocale } from '@formatjs/intl-localematcher';
2
+ import { CanonicalizeLocaleList } from '../CanonicalizeLocaleList';
3
+ import { CoerceOptionsToObject } from '../CoerceOptionsToObject';
4
+ import { GetNumberOption } from '../GetNumberOption';
5
+ import { GetOption } from '../GetOption';
6
+ import { GetStringOrBooleanOption } from '../GetStringOrBooleanOption';
7
+ import { invariant } from '../utils';
8
+ import { CurrencyDigits } from './CurrencyDigits';
9
+ import { SetNumberFormatDigitOptions } from './SetNumberFormatDigitOptions';
10
+ import { SetNumberFormatUnitOptions } from './SetNumberFormatUnitOptions';
14
11
  var VALID_ROUND_INCREMENT_VALUES = [
15
12
  1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000,
16
13
  ];
17
14
  /**
18
15
  * https://tc39.es/ecma402/#sec-initializenumberformat
19
16
  */
20
- function InitializeNumberFormat(nf, locales, opts, _a) {
17
+ export function InitializeNumberFormat(nf, locales, opts, _a) {
21
18
  var getInternalSlots = _a.getInternalSlots, localeData = _a.localeData, availableLocales = _a.availableLocales, numberingSystemNames = _a.numberingSystemNames, getDefaultLocale = _a.getDefaultLocale, currencyDigitsData = _a.currencyDigitsData;
22
19
  // @ts-ignore
23
- var requestedLocales = (0, CanonicalizeLocaleList_1.CanonicalizeLocaleList)(locales);
24
- var options = (0, CoerceOptionsToObject_1.CoerceOptionsToObject)(opts);
20
+ var requestedLocales = CanonicalizeLocaleList(locales);
21
+ var options = CoerceOptionsToObject(opts);
25
22
  var opt = Object.create(null);
26
- var matcher = (0, GetOption_1.GetOption)(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
23
+ var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit');
27
24
  opt.localeMatcher = matcher;
28
- var numberingSystem = (0, GetOption_1.GetOption)(options, 'numberingSystem', 'string', undefined, undefined);
25
+ var numberingSystem = GetOption(options, 'numberingSystem', 'string', undefined, undefined);
29
26
  if (numberingSystem !== undefined &&
30
27
  numberingSystemNames.indexOf(numberingSystem) < 0) {
31
28
  // 8.a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal,
@@ -33,23 +30,23 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
33
30
  throw RangeError("Invalid numberingSystems: ".concat(numberingSystem));
34
31
  }
35
32
  opt.nu = numberingSystem;
36
- var r = (0, intl_localematcher_1.ResolveLocale)(Array.from(availableLocales), requestedLocales, opt,
33
+ var r = ResolveLocale(Array.from(availableLocales), requestedLocales, opt,
37
34
  // [[RelevantExtensionKeys]] slot, which is a constant
38
35
  ['nu'], localeData, getDefaultLocale);
39
36
  var dataLocaleData = localeData[r.dataLocale];
40
- (0, utils_1.invariant)(!!dataLocaleData, "Missing locale data for ".concat(r.dataLocale));
37
+ invariant(!!dataLocaleData, "Missing locale data for ".concat(r.dataLocale));
41
38
  var internalSlots = getInternalSlots(nf);
42
39
  internalSlots.locale = r.locale;
43
40
  internalSlots.dataLocale = r.dataLocale;
44
41
  internalSlots.numberingSystem = r.nu;
45
42
  internalSlots.dataLocaleData = dataLocaleData;
46
- (0, SetNumberFormatUnitOptions_1.SetNumberFormatUnitOptions)(nf, options, { getInternalSlots: getInternalSlots });
43
+ SetNumberFormatUnitOptions(nf, options, { getInternalSlots: getInternalSlots });
47
44
  var style = internalSlots.style;
48
45
  var mnfdDefault;
49
46
  var mxfdDefault;
50
47
  if (style === 'currency') {
51
48
  var currency = internalSlots.currency;
52
- var cDigits = (0, CurrencyDigits_1.CurrencyDigits)(currency, { currencyDigitsData: currencyDigitsData });
49
+ var cDigits = CurrencyDigits(currency, { currencyDigitsData: currencyDigitsData });
53
50
  mnfdDefault = cDigits;
54
51
  mxfdDefault = cDigits;
55
52
  }
@@ -57,10 +54,10 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
57
54
  mnfdDefault = 0;
58
55
  mxfdDefault = style === 'percent' ? 0 : 3;
59
56
  }
60
- var notation = (0, GetOption_1.GetOption)(options, 'notation', 'string', ['standard', 'scientific', 'engineering', 'compact'], 'standard');
57
+ var notation = GetOption(options, 'notation', 'string', ['standard', 'scientific', 'engineering', 'compact'], 'standard');
61
58
  internalSlots.notation = notation;
62
- (0, SetNumberFormatDigitOptions_1.SetNumberFormatDigitOptions)(internalSlots, options, mnfdDefault, mxfdDefault, notation);
63
- var roundingIncrement = (0, GetNumberOption_1.GetNumberOption)(options, 'roundingIncrement', 1, 5000, 1);
59
+ SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
60
+ var roundingIncrement = GetNumberOption(options, 'roundingIncrement', 1, 5000, 1);
64
61
  if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
65
62
  throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
66
63
  }
@@ -73,17 +70,17 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
73
70
  throw new RangeError('With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.');
74
71
  }
75
72
  internalSlots.roundingIncrement = roundingIncrement;
76
- var trailingZeroDisplay = (0, GetOption_1.GetOption)(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
73
+ var trailingZeroDisplay = GetOption(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
77
74
  internalSlots.trailingZeroDisplay = trailingZeroDisplay;
78
- var compactDisplay = (0, GetOption_1.GetOption)(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
75
+ var compactDisplay = GetOption(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
79
76
  var defaultUseGrouping = 'auto';
80
77
  if (notation === 'compact') {
81
78
  internalSlots.compactDisplay = compactDisplay;
82
79
  defaultUseGrouping = 'min2';
83
80
  }
84
- internalSlots.useGrouping = (0, GetStringOrBooleanOption_1.GetStringOrBooleanOption)(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
85
- internalSlots.signDisplay = (0, GetOption_1.GetOption)(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
86
- internalSlots.roundingMode = (0, GetOption_1.GetOption)(options, 'roundingMode', 'string', [
81
+ internalSlots.useGrouping = GetStringOrBooleanOption(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
82
+ internalSlots.signDisplay = GetOption(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
83
+ internalSlots.roundingMode = GetOption(options, 'roundingMode', 'string', [
87
84
  'ceil',
88
85
  'floor',
89
86
  'expand',
@@ -96,4 +93,3 @@ function InitializeNumberFormat(nf, locales, opts, _a) {
96
93
  ], 'halfExpand');
97
94
  return nf;
98
95
  }
99
- exports.InitializeNumberFormat = InitializeNumberFormat;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionNumberPattern = void 0;
4
- var tslib_1 = require("tslib");
5
- var FormatNumericToString_1 = require("./FormatNumericToString");
6
- var _262_1 = require("../262");
7
- var ComputeExponent_1 = require("./ComputeExponent");
8
- var format_to_parts_1 = tslib_1.__importDefault(require("./format_to_parts"));
1
+ import { FormatNumericToString } from './FormatNumericToString';
2
+ import { SameValue } from '../262';
3
+ import { ComputeExponent } from './ComputeExponent';
4
+ import formatToParts from './format_to_parts';
9
5
  /**
10
6
  * https://tc39.es/ecma402/#sec-formatnumberstring
11
7
  */
12
- function PartitionNumberPattern(numberFormat, x, _a) {
8
+ export function PartitionNumberPattern(numberFormat, x, _a) {
13
9
  var _b;
14
10
  var getInternalSlots = _a.getInternalSlots;
15
11
  var internalSlots = getInternalSlots(numberFormat);
@@ -26,7 +22,7 @@ function PartitionNumberPattern(numberFormat, x, _a) {
26
22
  n = symbols.infinity;
27
23
  }
28
24
  else {
29
- if (!(0, _262_1.SameValue)(x, -0)) {
25
+ if (!SameValue(x, -0)) {
30
26
  if (!isFinite(x)) {
31
27
  throw new Error('Input must be a mathematical value');
32
28
  }
@@ -34,13 +30,13 @@ function PartitionNumberPattern(numberFormat, x, _a) {
34
30
  x *= 100;
35
31
  }
36
32
  ;
37
- _b = (0, ComputeExponent_1.ComputeExponent)(numberFormat, x, {
33
+ _b = ComputeExponent(numberFormat, x, {
38
34
  getInternalSlots: getInternalSlots,
39
35
  }), exponent = _b[0], magnitude = _b[1];
40
36
  // Preserve more precision by doing multiplication when exponent is negative.
41
37
  x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
42
38
  }
43
- var formatNumberResult = (0, FormatNumericToString_1.FormatNumericToString)(internalSlots, x);
39
+ var formatNumberResult = FormatNumericToString(internalSlots, x);
44
40
  n = formatNumberResult.formattedString;
45
41
  x = formatNumberResult.roundedNumber;
46
42
  }
@@ -53,7 +49,7 @@ function PartitionNumberPattern(numberFormat, x, _a) {
53
49
  sign = 0;
54
50
  break;
55
51
  case 'auto':
56
- if ((0, _262_1.SameValue)(x, 0) || x > 0 || isNaN(x)) {
52
+ if (SameValue(x, 0) || x > 0 || isNaN(x)) {
57
53
  sign = 0;
58
54
  }
59
55
  else {
@@ -61,7 +57,7 @@ function PartitionNumberPattern(numberFormat, x, _a) {
61
57
  }
62
58
  break;
63
59
  case 'always':
64
- if ((0, _262_1.SameValue)(x, 0) || x > 0 || isNaN(x)) {
60
+ if (SameValue(x, 0) || x > 0 || isNaN(x)) {
65
61
  sign = 1;
66
62
  }
67
63
  else {
@@ -80,6 +76,5 @@ function PartitionNumberPattern(numberFormat, x, _a) {
80
76
  sign = -1;
81
77
  }
82
78
  }
83
- return (0, format_to_parts_1.default)({ roundedNumber: x, formattedString: n, exponent: exponent, magnitude: magnitude, sign: sign }, internalSlots.dataLocaleData, pl, internalSlots);
79
+ return formatToParts({ roundedNumber: x, formattedString: n, exponent: exponent, magnitude: magnitude, sign: sign }, internalSlots.dataLocaleData, pl, internalSlots);
84
80
  }
85
- exports.PartitionNumberPattern = PartitionNumberPattern;
@@ -1,22 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PartitionNumberRangePattern = void 0;
4
- var PartitionNumberPattern_1 = require("./PartitionNumberPattern");
5
- var CollapseNumberRange_1 = require("./CollapseNumberRange");
6
- var FormatApproximately_1 = require("./FormatApproximately");
1
+ import { PartitionNumberPattern } from './PartitionNumberPattern';
2
+ import { CollapseNumberRange } from './CollapseNumberRange';
3
+ import { FormatApproximately } from './FormatApproximately';
7
4
  /**
8
5
  * https://tc39.es/ecma402/#sec-partitionnumberrangepattern
9
6
  */
10
- function PartitionNumberRangePattern(numberFormat, x, y, _a) {
7
+ export function PartitionNumberRangePattern(numberFormat, x, y, _a) {
11
8
  var getInternalSlots = _a.getInternalSlots;
12
9
  if (isNaN(x) || isNaN(y)) {
13
10
  throw new RangeError('Input must be a number');
14
11
  }
15
12
  var result = [];
16
- var xResult = (0, PartitionNumberPattern_1.PartitionNumberPattern)(numberFormat, x, { getInternalSlots: getInternalSlots });
17
- var yResult = (0, PartitionNumberPattern_1.PartitionNumberPattern)(numberFormat, y, { getInternalSlots: getInternalSlots });
13
+ var xResult = PartitionNumberPattern(numberFormat, x, { getInternalSlots: getInternalSlots });
14
+ var yResult = PartitionNumberPattern(numberFormat, y, { getInternalSlots: getInternalSlots });
18
15
  if (xResult === yResult) {
19
- return (0, FormatApproximately_1.FormatApproximately)(numberFormat, xResult, { getInternalSlots: getInternalSlots });
16
+ return FormatApproximately(numberFormat, xResult, { getInternalSlots: getInternalSlots });
20
17
  }
21
18
  for (var _i = 0, xResult_1 = xResult; _i < xResult_1.length; _i++) {
22
19
  var r = xResult_1[_i];
@@ -31,6 +28,5 @@ function PartitionNumberRangePattern(numberFormat, x, y, _a) {
31
28
  r.source = 'endRange';
32
29
  }
33
30
  result = result.concat(yResult);
34
- return (0, CollapseNumberRange_1.CollapseNumberRange)(result);
31
+ return CollapseNumberRange(result);
35
32
  }
36
- exports.PartitionNumberRangePattern = PartitionNumberRangePattern;
@@ -1,4 +1,4 @@
1
- import { NumberFormatDigitOptions, NumberFormatNotation, NumberFormatDigitInternalSlots } from '../types/number';
1
+ import { NumberFormatDigitInternalSlots, NumberFormatDigitOptions, NumberFormatNotation } from '../types/number';
2
2
  /**
3
3
  * https://tc39.es/ecma402/#sec-setnfdigitoptions
4
4
  */