@formatjs/intl-numberformat 8.1.2 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/src/core.js CHANGED
@@ -85,6 +85,15 @@ defineProperty(NumberFormat.prototype, 'resolvedOptions', {
85
85
  ro[key] = value;
86
86
  }
87
87
  }
88
+ if (internalSlots.roundingType === 'morePrecision') {
89
+ ro.roundingPriority = 'morePrecision';
90
+ }
91
+ else if (internalSlots.roundingType === 'lessPrecision') {
92
+ ro.roundingPriority = 'lessPrecision';
93
+ }
94
+ else {
95
+ ro.roundingPriority = 'auto';
96
+ }
88
97
  return ro;
89
98
  },
90
99
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/intl-numberformat",
3
- "version": "8.1.2",
3
+ "version": "8.2.0",
4
4
  "description": "Ponyfill for ES2020 Intl.NumberFormat",
5
5
  "keywords": [
6
6
  "polyfill",
@@ -22,14 +22,14 @@
22
22
  "url": "git+https://github.com/formatjs/formatjs.git"
23
23
  },
24
24
  "dependencies": {
25
- "@formatjs/ecma402-abstract": "1.11.10",
26
- "@formatjs/intl-localematcher": "0.2.30",
25
+ "@formatjs/ecma402-abstract": "1.13.0",
26
+ "@formatjs/intl-localematcher": "0.2.31",
27
27
  "tslib": "2.4.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@formatjs/intl-getcanonicallocales": "2.0.4",
31
- "@formatjs/intl-locale": "3.0.5",
32
- "@formatjs/intl-pluralrules": "5.1.2"
31
+ "@formatjs/intl-locale": "3.0.7",
32
+ "@formatjs/intl-pluralrules": "5.1.4"
33
33
  },
34
34
  "bugs": {
35
35
  "url": "https://github.com/formatjs/formatjs/issues"
package/polyfill.iife.js CHANGED
@@ -128,6 +128,29 @@
128
128
  return fallback;
129
129
  }
130
130
 
131
+ // ../../../../../../../../execroot/formatjs/bazel-out/darwin-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/GetStringOrBooleanOption.js
132
+ function GetStringOrBooleanOption(opts, prop, values, trueValue, falsyValue, fallback) {
133
+ var value = opts[prop];
134
+ if (value === void 0) {
135
+ return fallback;
136
+ }
137
+ if (value === true) {
138
+ return trueValue;
139
+ }
140
+ var valueBoolean = Boolean(value);
141
+ if (valueBoolean === false) {
142
+ return falsyValue;
143
+ }
144
+ value = ToString(value);
145
+ if (value === "true" || value === "false") {
146
+ return fallback;
147
+ }
148
+ if ((values || []).indexOf(value) === -1) {
149
+ throw new RangeError("Invalid value ".concat(value));
150
+ }
151
+ return value;
152
+ }
153
+
131
154
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/IsSanctionedSimpleUnitIdentifier.js
132
155
  var SANCTIONED_UNITS = [
133
156
  "angle-degree",
@@ -552,7 +575,7 @@
552
575
  notation,
553
576
  exponent,
554
577
  numberingSystem,
555
- !compactNumberPattern && options.useGrouping,
578
+ !compactNumberPattern && Boolean(options.useGrouping),
556
579
  decimalNumberPattern
557
580
  ));
558
581
  break;
@@ -788,17 +811,22 @@
788
811
  var n;
789
812
  if (isNaN(x)) {
790
813
  n = symbols.nan;
791
- } else if (!isFinite(x)) {
814
+ } else if (x == Number.POSITIVE_INFINITY || x == Number.NEGATIVE_INFINITY) {
792
815
  n = symbols.infinity;
793
816
  } else {
794
- if (internalSlots.style === "percent") {
795
- x *= 100;
817
+ if (!SameValue(x, -0)) {
818
+ if (!isFinite(x)) {
819
+ throw new Error("Input must be a mathematical value");
820
+ }
821
+ if (internalSlots.style == "percent") {
822
+ x *= 100;
823
+ }
824
+ ;
825
+ _b = ComputeExponent(numberFormat, x, {
826
+ getInternalSlots: getInternalSlots2
827
+ }), exponent = _b[0], magnitude = _b[1];
828
+ x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
796
829
  }
797
- ;
798
- _b = ComputeExponent(numberFormat, x, {
799
- getInternalSlots: getInternalSlots2
800
- }), exponent = _b[0], magnitude = _b[1];
801
- x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
802
830
  var formatNumberResult = FormatNumericToString(internalSlots, x);
803
831
  n = formatNumberResult.formattedString;
804
832
  x = formatNumberResult.roundedNumber;
@@ -1125,29 +1153,81 @@
1125
1153
  var mnsd = opts.minimumSignificantDigits;
1126
1154
  var mxsd = opts.maximumSignificantDigits;
1127
1155
  internalSlots.minimumIntegerDigits = mnid;
1128
- if (mnsd !== void 0 || mxsd !== void 0) {
1129
- internalSlots.roundingType = "significantDigits";
1130
- mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
1131
- mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
1132
- internalSlots.minimumSignificantDigits = mnsd;
1133
- internalSlots.maximumSignificantDigits = mxsd;
1134
- } else if (mnfd !== void 0 || mxfd !== void 0) {
1135
- internalSlots.roundingType = "fractionDigits";
1136
- mnfd = DefaultNumberOption(mnfd, 0, 20, mnfdDefault);
1137
- var mxfdActualDefault = Math.max(mnfd, mxfdDefault);
1138
- mxfd = DefaultNumberOption(mxfd, mnfd, 20, mxfdActualDefault);
1139
- internalSlots.minimumFractionDigits = mnfd;
1140
- internalSlots.maximumFractionDigits = mxfd;
1141
- } else if (notation === "compact") {
1142
- internalSlots.roundingType = "compactRounding";
1156
+ var roundingPriority = GetOption(opts, "roundingPriority", "string", ["auto", "morePrecision", "lessPrecision"], "auto");
1157
+ var hasSd = mnsd !== void 0 || mxsd !== void 0;
1158
+ var hasFd = mnfd !== void 0 || mxfd !== void 0;
1159
+ var needSd = true;
1160
+ var needFd = true;
1161
+ if (roundingPriority === "auto") {
1162
+ needSd = hasSd;
1163
+ if (hasSd || !hasFd && notation === "compact") {
1164
+ needFd = false;
1165
+ }
1166
+ }
1167
+ if (needSd) {
1168
+ if (hasSd) {
1169
+ mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
1170
+ mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
1171
+ internalSlots.minimumSignificantDigits = mnsd;
1172
+ internalSlots.maximumSignificantDigits = mxsd;
1173
+ } else {
1174
+ internalSlots.minimumSignificantDigits = 1;
1175
+ internalSlots.maximumSignificantDigits = 21;
1176
+ }
1177
+ }
1178
+ if (needFd) {
1179
+ if (hasFd) {
1180
+ mnfd = DefaultNumberOption(mnfd, 0, 20, void 0);
1181
+ mxfd = DefaultNumberOption(mxfd, 0, 20, void 0);
1182
+ if (mnfd === void 0) {
1183
+ mnfd = Math.min(mnfdDefault, mxfd);
1184
+ } else if (mxfd === void 0) {
1185
+ mxfd = Math.max(mxfdDefault, mnfd);
1186
+ } else if (mnfd > mxfd) {
1187
+ throw new RangeError("Invalid range, ".concat(mnfd, " > ").concat(mxfd));
1188
+ }
1189
+ internalSlots.minimumFractionDigits = mnfd;
1190
+ internalSlots.maximumFractionDigits = mxfd;
1191
+ } else {
1192
+ internalSlots.minimumFractionDigits = mnfdDefault;
1193
+ internalSlots.maximumFractionDigits = mxfdDefault;
1194
+ }
1195
+ }
1196
+ if (needSd || needFd) {
1197
+ if (roundingPriority === "morePrecision") {
1198
+ internalSlots.roundingType = "morePrecision";
1199
+ } else if (roundingPriority === "lessPrecision") {
1200
+ internalSlots.roundingType = "lessPrecision";
1201
+ } else if (hasSd) {
1202
+ internalSlots.roundingType = "significantDigits";
1203
+ } else {
1204
+ internalSlots.roundingType = "fractionDigits";
1205
+ }
1143
1206
  } else {
1144
- internalSlots.roundingType = "fractionDigits";
1145
- internalSlots.minimumFractionDigits = mnfdDefault;
1146
- internalSlots.maximumFractionDigits = mxfdDefault;
1207
+ internalSlots.roundingType = "morePrecision";
1208
+ internalSlots.minimumFractionDigits = 0;
1209
+ internalSlots.maximumFractionDigits = 0;
1210
+ internalSlots.minimumSignificantDigits = 1;
1211
+ internalSlots.maximumSignificantDigits = 2;
1147
1212
  }
1148
1213
  }
1149
1214
 
1150
1215
  // ../../../../../../../../execroot/formatjs/bazel-out/darwin-fastbuild/bin/node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/lib/NumberFormat/InitializeNumberFormat.js
1216
+ var VALID_ROUND_INCREMENT_VALUES = [
1217
+ 1,
1218
+ 2,
1219
+ 5,
1220
+ 10,
1221
+ 20,
1222
+ 25,
1223
+ 50,
1224
+ 100,
1225
+ 200,
1226
+ 250,
1227
+ 500,
1228
+ 1e3,
1229
+ 2e3
1230
+ ];
1151
1231
  function InitializeNumberFormat(nf, locales, opts, _a) {
1152
1232
  var getInternalSlots2 = _a.getInternalSlots, localeData = _a.localeData, availableLocales = _a.availableLocales, numberingSystemNames2 = _a.numberingSystemNames, getDefaultLocale = _a.getDefaultLocale, currencyDigitsData2 = _a.currencyDigitsData;
1153
1233
  var requestedLocales = CanonicalizeLocaleList(locales);
@@ -1191,14 +1271,38 @@
1191
1271
  var notation = GetOption(options, "notation", "string", ["standard", "scientific", "engineering", "compact"], "standard");
1192
1272
  internalSlots.notation = notation;
1193
1273
  SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
1274
+ var roundingIncrement = GetNumberOption(options, "roundingIncrement", 1, 5e3, 1);
1275
+ if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
1276
+ throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
1277
+ }
1278
+ if (roundingIncrement !== 1 && internalSlots.roundingType !== "fractionDigits") {
1279
+ throw new TypeError("For roundingIncrement > 1 only fractionDigits is a valid roundingType");
1280
+ }
1281
+ if (roundingIncrement !== 1 && internalSlots.maximumFractionDigits !== internalSlots.minimumFractionDigits) {
1282
+ throw new RangeError("With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.");
1283
+ }
1284
+ internalSlots.roundingIncrement = roundingIncrement;
1285
+ var trailingZeroDisplay = GetOption(options, "trailingZeroDisplay", "string", ["auto", "stripIfInteger"], "auto");
1286
+ internalSlots.trailingZeroDisplay = trailingZeroDisplay;
1194
1287
  var compactDisplay = GetOption(options, "compactDisplay", "string", ["short", "long"], "short");
1288
+ var defaultUseGrouping = "auto";
1195
1289
  if (notation === "compact") {
1196
1290
  internalSlots.compactDisplay = compactDisplay;
1197
- }
1198
- var useGrouping = GetOption(options, "useGrouping", "boolean", void 0, true);
1199
- internalSlots.useGrouping = useGrouping;
1200
- var signDisplay = GetOption(options, "signDisplay", "string", ["auto", "never", "always", "exceptZero"], "auto");
1201
- internalSlots.signDisplay = signDisplay;
1291
+ defaultUseGrouping = "min2";
1292
+ }
1293
+ internalSlots.useGrouping = GetStringOrBooleanOption(options, "useGrouping", ["min2", "auto", "always"], "always", false, defaultUseGrouping);
1294
+ internalSlots.signDisplay = GetOption(options, "signDisplay", "string", ["auto", "never", "always", "exceptZero", "negative"], "auto");
1295
+ internalSlots.roundingMode = GetOption(options, "roundingMode", "string", [
1296
+ "ceil",
1297
+ "floor",
1298
+ "expand",
1299
+ "trunc",
1300
+ "halfCeil",
1301
+ "halfFloor",
1302
+ "halfExpand",
1303
+ "halfTrunc",
1304
+ "halfEven"
1305
+ ], "halfExpand");
1202
1306
  return nf;
1203
1307
  }
1204
1308
 
@@ -1348,6 +1452,13 @@
1348
1452
  ro[key] = value;
1349
1453
  }
1350
1454
  }
1455
+ if (internalSlots.roundingType === "morePrecision") {
1456
+ ro.roundingPriority = "morePrecision";
1457
+ } else if (internalSlots.roundingType === "lessPrecision") {
1458
+ ro.roundingPriority = "lessPrecision";
1459
+ } else {
1460
+ ro.roundingPriority = "auto";
1461
+ }
1351
1462
  return ro;
1352
1463
  }
1353
1464
  });
package/src/core.js CHANGED
@@ -89,6 +89,15 @@ catch (e) {
89
89
  ro[key] = value;
90
90
  }
91
91
  }
92
+ if (internalSlots.roundingType === 'morePrecision') {
93
+ ro.roundingPriority = 'morePrecision';
94
+ }
95
+ else if (internalSlots.roundingType === 'lessPrecision') {
96
+ ro.roundingPriority = 'lessPrecision';
97
+ }
98
+ else {
99
+ ro.roundingPriority = 'auto';
100
+ }
92
101
  return ro;
93
102
  },
94
103
  });