@poe-platform/safe-js 0.1.291 → 0.1.292

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.
@@ -10446,62 +10446,6 @@ function createNumericParsers(budget) {
10446
10446
  };
10447
10447
  }
10448
10448
 
10449
- // packages/safe-js/src/interp/methods/number.ts
10450
- var numberMethodNames = /* @__PURE__ */ new Set([
10451
- "toExponential",
10452
- "toFixed",
10453
- "toPrecision",
10454
- "toString"
10455
- ]);
10456
- function getNumberMember(property, budget) {
10457
- if (!isNumberMethodName(property)) {
10458
- return void 0;
10459
- }
10460
- return createSandboxClosure({
10461
- sandbox: true,
10462
- name: `Number#${property}`,
10463
- call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget, context)
10464
- });
10465
- }
10466
- function isNumberMethodName(property) {
10467
- return typeof property === "string" && numberMethodNames.has(property);
10468
- }
10469
- function callNumberMethod(value, methodName, args, budget, context) {
10470
- if (isSandboxBox(value)) value = boxedValue(value);
10471
- if (typeof value !== "number") {
10472
- throw new TypeError(`Number#${methodName} requires a number receiver.`);
10473
- }
10474
- const argument = args[0];
10475
- if (argument !== null && typeof argument === "object") {
10476
- return formatObjectArgument(value, methodName, argument, budget, context);
10477
- }
10478
- return formatNumber(value, methodName, argument === void 0 ? void 0 : +argument, budget);
10479
- }
10480
- async function formatObjectArgument(value, methodName, argument, budget, context) {
10481
- const retainedArgument = {};
10482
- budget.setRetainedValues(retainedArgument, () => [argument]);
10483
- try {
10484
- const number = await sandboxNumber(argument, budget, context);
10485
- return formatNumber(value, methodName, number, budget);
10486
- } finally {
10487
- budget.setRetainedValues(retainedArgument, void 0);
10488
- }
10489
- }
10490
- function formatNumber(value, methodName, argument, budget) {
10491
- let result;
10492
- try {
10493
- result = value[methodName](argument);
10494
- } catch (error) {
10495
- if (!(error instanceof RangeError)) throw error;
10496
- const detail = methodName === "toString" ? "radix must be between 2 and 36." : methodName === "toPrecision" ? "precision must be between 1 and 100." : "digits must be between 0 and 100.";
10497
- throw new RangeError(`Number#${methodName} ${detail}`);
10498
- }
10499
- return budget.allocateString(result);
10500
- }
10501
-
10502
- // packages/safe-js/src/interp/methods/string.ts
10503
- import { types as types5 } from "node:util";
10504
-
10505
10449
  // packages/safe-js/src/interp/intl-options.ts
10506
10450
  var canonicalLocales = Intl.getCanonicalLocales;
10507
10451
  function readIntlProperty(value, key, budget, context) {
@@ -10557,6 +10501,162 @@ async function convertIntlOption(value, key, type, budget, context, invalid) {
10557
10501
  throw new RangeError(`Invalid ${key} option.`);
10558
10502
  }
10559
10503
 
10504
+ // packages/safe-js/src/interp/number-locale.ts
10505
+ var NativeNumberFormat = Intl.NumberFormat;
10506
+ var roundingIncrements = [1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1e3, 2e3, 2500, 5e3];
10507
+ async function formatNumberLocale(value, args, budget, context) {
10508
+ let locales = [];
10509
+ const options = /* @__PURE__ */ Object.create(null);
10510
+ const digits = /* @__PURE__ */ Object.create(null);
10511
+ const release = retainValues(budget, () => [value, locales, options, digits]);
10512
+ const allocation = {};
10513
+ try {
10514
+ locales = await canonicalizeGuestLocales(args[0], budget, context);
10515
+ const input = intlOptionsObject(args[1], budget);
10516
+ const readString = async (key, type) => {
10517
+ const raw = await readIntlProperty(input, key, budget, context);
10518
+ if (raw === void 0) return void 0;
10519
+ const text = type === void 0 ? await sandboxString(raw, budget, context) : await convertIntlOption(raw, key, type, budget, context);
10520
+ if (type === void 0) budget.visitNode(text.length);
10521
+ options[key] = text;
10522
+ return text;
10523
+ };
10524
+ const numberOption = async (raw, key, minimum, maximum, fallback) => {
10525
+ if (raw === void 0) return fallback;
10526
+ const number = await sandboxNumber(raw, budget, context);
10527
+ if (!Number.isFinite(number) || number < minimum || number > maximum)
10528
+ throw new RangeError(`Invalid ${key} option.`);
10529
+ return Math.floor(number);
10530
+ };
10531
+ await readString("localeMatcher", ["lookup", "best fit"]);
10532
+ await readString("numberingSystem", "unicodeType");
10533
+ const style = await readString("style", ["decimal", "percent", "currency", "unit"]) ?? "decimal";
10534
+ const currency = await readString("currency");
10535
+ if (currency === void 0) {
10536
+ if (style === "currency") throw new TypeError("Currency formatting requires a currency.");
10537
+ } else if (currency.length !== 3 || ![...currency].every((char) => char >= "A" && char <= "Z" || char >= "a" && char <= "z"))
10538
+ throw new RangeError("Invalid currency code.");
10539
+ await readString("currencyDisplay", ["code", "symbol", "narrowSymbol", "name"]);
10540
+ await readString("currencySign", ["standard", "accounting"]);
10541
+ const unit = await readString("unit");
10542
+ if (unit === void 0) {
10543
+ if (style === "unit") throw new TypeError("Unit formatting requires a unit.");
10544
+ } else new NativeNumberFormat("en", { style: "unit", unit });
10545
+ await readString("unitDisplay", ["short", "narrow", "long"]);
10546
+ const notation = await readString("notation", ["standard", "scientific", "engineering", "compact"]) ?? "standard";
10547
+ let minimumDefault = 0;
10548
+ let maximumDefault = style === "percent" ? 0 : 3;
10549
+ if (style === "currency" && notation === "standard") {
10550
+ const currencyDefaults = new NativeNumberFormat("en", { style: "currency", currency }).resolvedOptions();
10551
+ minimumDefault = currencyDefaults.minimumFractionDigits;
10552
+ maximumDefault = currencyDefaults.maximumFractionDigits;
10553
+ }
10554
+ options.minimumIntegerDigits = await numberOption(await readIntlProperty(input, "minimumIntegerDigits", budget, context), "minimumIntegerDigits", 1, 21, 1);
10555
+ for (const key of ["minimumFractionDigits", "maximumFractionDigits", "minimumSignificantDigits", "maximumSignificantDigits"])
10556
+ digits[key] = await readIntlProperty(input, key, budget, context);
10557
+ const increment = await numberOption(await readIntlProperty(input, "roundingIncrement", budget, context), "roundingIncrement", 1, 5e3, 1);
10558
+ if (!roundingIncrements.includes(increment)) throw new RangeError("Invalid roundingIncrement option.");
10559
+ options.roundingIncrement = increment;
10560
+ await readString("roundingMode", ["ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"]);
10561
+ const priority = await readString("roundingPriority", ["auto", "morePrecision", "lessPrecision"]) ?? "auto";
10562
+ await readString("trailingZeroDisplay", ["auto", "stripIfInteger"]);
10563
+ if (increment !== 1) maximumDefault = minimumDefault;
10564
+ const hasSignificant = digits.minimumSignificantDigits !== void 0 || digits.maximumSignificantDigits !== void 0;
10565
+ const hasFraction = digits.minimumFractionDigits !== void 0 || digits.maximumFractionDigits !== void 0;
10566
+ const needSignificant = priority !== "auto" || hasSignificant;
10567
+ const needFraction = priority !== "auto" || !(hasSignificant || !hasFraction && notation === "compact");
10568
+ if (needSignificant) {
10569
+ const minimum = await numberOption(digits.minimumSignificantDigits, "minimumSignificantDigits", 1, 21, 1);
10570
+ options.minimumSignificantDigits = minimum;
10571
+ options.maximumSignificantDigits = await numberOption(digits.maximumSignificantDigits, "maximumSignificantDigits", minimum, 21, 21);
10572
+ }
10573
+ if (needFraction) {
10574
+ let minimum = await numberOption(digits.minimumFractionDigits, "minimumFractionDigits", 0, 100);
10575
+ let maximum = await numberOption(digits.maximumFractionDigits, "maximumFractionDigits", 0, 100);
10576
+ if (minimum === void 0 && maximum === void 0) {
10577
+ minimum = minimumDefault;
10578
+ maximum = maximumDefault;
10579
+ } else if (minimum === void 0) minimum = Math.min(minimumDefault, maximum);
10580
+ else if (maximum === void 0) maximum = Math.max(maximumDefault, minimum);
10581
+ if (minimum > maximum) throw new RangeError("minimumFractionDigits exceeds maximumFractionDigits.");
10582
+ options.minimumFractionDigits = minimum;
10583
+ options.maximumFractionDigits = maximum;
10584
+ }
10585
+ new NativeNumberFormat(locales, options);
10586
+ await readString("compactDisplay", ["short", "long"]);
10587
+ const grouping = await readIntlProperty(input, "useGrouping", budget, context);
10588
+ if (grouping !== void 0) options.useGrouping = grouping === true ? true : !grouping ? false : await convertIntlOption(grouping, "useGrouping", ["min2", "auto", "always", "true", "false"], budget, context);
10589
+ await readString("signDisplay", ["auto", "never", "always", "exceptZero", "negative"]);
10590
+ const size = typeof value === "bigint" ? value.toString(16).length * 4 : 64;
10591
+ budget.visitNode(size);
10592
+ budget.setRetainedDataUsage(allocation, size);
10593
+ const formatter = new NativeNumberFormat(locales, options);
10594
+ return budget.allocateString(formatter.format(value));
10595
+ } finally {
10596
+ budget.setRetainedDataUsage(allocation, 0);
10597
+ release();
10598
+ }
10599
+ }
10600
+
10601
+ // packages/safe-js/src/interp/methods/number.ts
10602
+ var numberMethodNames = /* @__PURE__ */ new Set([
10603
+ "toExponential",
10604
+ "toFixed",
10605
+ "toPrecision",
10606
+ "toString",
10607
+ "toLocaleString"
10608
+ ]);
10609
+ function getNumberMember(property, budget) {
10610
+ if (!isNumberMethodName(property)) {
10611
+ return void 0;
10612
+ }
10613
+ return createSandboxClosure({
10614
+ sandbox: true,
10615
+ name: `Number#${property}`,
10616
+ ...property === "toLocaleString" ? { guest: true, name: property, length: 0 } : {},
10617
+ call: (args, context) => callNumberMethod(context?.thisValue, property, args, budget, context)
10618
+ });
10619
+ }
10620
+ function isNumberMethodName(property) {
10621
+ return typeof property === "string" && numberMethodNames.has(property);
10622
+ }
10623
+ function callNumberMethod(value, methodName, args, budget, context) {
10624
+ if (isSandboxBox(value)) value = boxedValue(value);
10625
+ if (typeof value !== "number") {
10626
+ throw new TypeError(`Number#${methodName} requires a number receiver.`);
10627
+ }
10628
+ if (methodName === "toLocaleString") return formatNumberLocale(value, args, budget, context);
10629
+ const argument = args[0];
10630
+ if (argument !== null && typeof argument === "object") {
10631
+ return formatObjectArgument(value, methodName, argument, budget, context);
10632
+ }
10633
+ return formatNumber(value, methodName, argument === void 0 ? void 0 : +argument, budget);
10634
+ }
10635
+ async function formatObjectArgument(value, methodName, argument, budget, context) {
10636
+ const retainedArgument = {};
10637
+ budget.setRetainedValues(retainedArgument, () => [argument]);
10638
+ try {
10639
+ const number = await sandboxNumber(argument, budget, context);
10640
+ return formatNumber(value, methodName, number, budget);
10641
+ } finally {
10642
+ budget.setRetainedValues(retainedArgument, void 0);
10643
+ }
10644
+ }
10645
+ function formatNumber(value, methodName, argument, budget) {
10646
+ let result;
10647
+ try {
10648
+ result = value[methodName](argument);
10649
+ } catch (error) {
10650
+ if (!(error instanceof RangeError)) throw error;
10651
+ const detail = methodName === "toString" ? "radix must be between 2 and 36." : methodName === "toPrecision" ? "precision must be between 1 and 100." : "digits must be between 0 and 100.";
10652
+ throw new RangeError(`Number#${methodName} ${detail}`);
10653
+ }
10654
+ return budget.allocateString(result);
10655
+ }
10656
+
10657
+ // packages/safe-js/src/interp/methods/string.ts
10658
+ import { types as types5 } from "node:util";
10659
+
10560
10660
  // packages/safe-js/src/interp/methods/string-locale.ts
10561
10661
  var collatorOptions = [
10562
10662
  ["usage", ["sort", "search"]],
@@ -23642,6 +23742,17 @@ function createBigIntGlobal(budget) {
23642
23742
  writable: true,
23643
23743
  configurable: true
23644
23744
  },
23745
+ toLocaleString: {
23746
+ value: createSandboxClosure({
23747
+ guest: true,
23748
+ sandbox: true,
23749
+ name: "toLocaleString",
23750
+ length: 0,
23751
+ call: (args, context) => formatNumberLocale(primitiveReceiver(context?.thisValue, "bigint"), args, budget, context)
23752
+ }),
23753
+ writable: true,
23754
+ configurable: true
23755
+ },
23645
23756
  [Symbol.toStringTag]: { value: "BigInt", configurable: true }
23646
23757
  });
23647
23758
  const properties = materializeFunctionProperties(constructor);
@@ -40519,4 +40630,4 @@ export {
40519
40630
  FileSnapshotBackend,
40520
40631
  run
40521
40632
  };
40522
- //# sourceMappingURL=chunk-ZOLHW4OV.js.map
40633
+ //# sourceMappingURL=chunk-4MMZLA7N.js.map