@poe-platform/safe-js 0.1.289 → 0.1.290

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.
@@ -10501,6 +10501,96 @@ function formatNumber(value, methodName, argument, budget) {
10501
10501
 
10502
10502
  // packages/safe-js/src/interp/methods/string.ts
10503
10503
  import { types as types5 } from "node:util";
10504
+
10505
+ // packages/safe-js/src/interp/intl-options.ts
10506
+ var canonicalLocales = Intl.getCanonicalLocales;
10507
+ function readIntlProperty(value, key, budget, context) {
10508
+ budget.visitNode();
10509
+ if (context?.getProperty !== void 0) return context.getProperty(value, key);
10510
+ const descriptor = getSandboxPropertyDescriptor(value, key, budget);
10511
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
10512
+ }
10513
+ function intlOptionsObject(value, budget) {
10514
+ if (value === void 0) return /* @__PURE__ */ Object.create(null);
10515
+ if (value === null) throw new TypeError("Cannot convert null to an object.");
10516
+ if (typeof value === "object") return value;
10517
+ const box = createSandboxBox(value);
10518
+ allocateProducedSandboxValue(box, budget);
10519
+ return box;
10520
+ }
10521
+ async function canonicalizeGuestLocales(input, budget, context) {
10522
+ const locales = [];
10523
+ if (input === void 0) return locales;
10524
+ if (input === null) return Reflect.apply(canonicalLocales, Intl, [input]);
10525
+ const release = retainValues(budget, () => [locales]);
10526
+ try {
10527
+ const list2 = typeof input === "string" ? [input] : intlOptionsObject(input, budget);
10528
+ const count = await sandboxNumber(await readIntlProperty(list2, "length", budget, context), budget, context);
10529
+ const length = Number.isNaN(count) || count <= 0 ? 0 : Math.min(Math.floor(count), Number.MAX_SAFE_INTEGER);
10530
+ for (let index = 0; index < length; index++) {
10531
+ budget.visitNode();
10532
+ const key = String(index);
10533
+ if (getSandboxPropertyDescriptor(list2, key, budget) === void 0 && !(isFloat32Array(list2) && Object.hasOwn(list2, key))) continue;
10534
+ const value = await readIntlProperty(list2, key, budget, context);
10535
+ if (typeof value !== "string" && (typeof value !== "object" || value === null))
10536
+ return Reflect.apply(canonicalLocales, Intl, [[value]]);
10537
+ const tag = await sandboxString(value, budget, context);
10538
+ budget.visitNode(tag.length);
10539
+ const canonical = canonicalLocales(tag)[0];
10540
+ budget.visitNode(locales.length);
10541
+ if (!locales.includes(canonical)) locales.push(budget.allocateString(canonical));
10542
+ }
10543
+ return locales;
10544
+ } finally {
10545
+ release();
10546
+ }
10547
+ }
10548
+ async function convertIntlOption(value, key, type, budget, context, invalid) {
10549
+ if (type === "boolean") return Boolean(value);
10550
+ const text = await sandboxString(value, budget, context);
10551
+ budget.visitNode(text.length);
10552
+ if (type === "unicodeType") {
10553
+ const valid = text.split("-").every((part) => part.length >= 3 && part.length <= 8 && [...part].every((char) => char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char >= "0" && char <= "9"));
10554
+ if (valid) return text;
10555
+ } else if (type.includes(text)) return text;
10556
+ invalid?.(text);
10557
+ throw new RangeError(`Invalid ${key} option.`);
10558
+ }
10559
+
10560
+ // packages/safe-js/src/interp/methods/string-locale.ts
10561
+ var collatorOptions = [
10562
+ ["usage", ["sort", "search"]],
10563
+ ["localeMatcher", ["lookup", "best fit"]],
10564
+ ["collation", "unicodeType"],
10565
+ ["numeric", "boolean"],
10566
+ ["caseFirst", ["upper", "lower", "false"]],
10567
+ ["sensitivity", ["base", "accent", "case", "variant"]],
10568
+ ["ignorePunctuation", "boolean"]
10569
+ ];
10570
+ async function compareStringLocale(value, args, budget, context) {
10571
+ let comparison = "";
10572
+ let locales = [];
10573
+ const options = /* @__PURE__ */ Object.create(null);
10574
+ const release = retainValues(budget, () => [value, comparison, locales, options]);
10575
+ try {
10576
+ comparison = await sandboxString(args[0], budget, context);
10577
+ locales = await canonicalizeGuestLocales(args[1], budget, context);
10578
+ if (args[2] === null) return Reflect.apply(String.prototype.localeCompare, value, [comparison, locales, null]);
10579
+ const inputOptions = intlOptionsObject(args[2], budget);
10580
+ for (const [key, type] of collatorOptions) {
10581
+ const option = await readIntlProperty(inputOptions, key, budget, context);
10582
+ if (option !== void 0) options[key] = await convertIntlOption(option, key, type, budget, context, (text) => {
10583
+ Reflect.apply(String.prototype.localeCompare, "", ["", [], { [key]: text }]);
10584
+ });
10585
+ }
10586
+ budget.visitNode(value.length + comparison.length);
10587
+ return Reflect.apply(String.prototype.localeCompare, value, [comparison, locales, options]);
10588
+ } finally {
10589
+ release();
10590
+ }
10591
+ }
10592
+
10593
+ // packages/safe-js/src/interp/methods/string.ts
10504
10594
  var stringMethodNames = /* @__PURE__ */ new Set([
10505
10595
  "at",
10506
10596
  "charAt",
@@ -10685,6 +10775,8 @@ function callStringMethodBody(value, methodName, args, budget, parent, context)
10685
10775
  if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
10686
10776
  return callStringPattern(value, methodName, args[0], budget, parent, context);
10687
10777
  }
10778
+ if (methodName === "localeCompare" && context?.getProperty !== void 0)
10779
+ return compareStringLocale(value, args, budget, context);
10688
10780
  const operation = budget.acquireCompileOwner(false, parent?.owner);
10689
10781
  const compilation = new CompileScope(operation.owner);
10690
10782
  try {
@@ -20371,7 +20463,6 @@ async function parseJsonWithReviver(text, reviver, budget, context) {
20371
20463
 
20372
20464
  // packages/safe-js/src/interp/date-locale.ts
20373
20465
  var NativeDateTimeFormat = Intl.DateTimeFormat;
20374
- var canonicalLocales = Intl.getCanonicalLocales;
20375
20466
  var dateTimeOptions = [
20376
20467
  ["localeMatcher", ["lookup", "best fit"]],
20377
20468
  ["calendar", "unicodeType"],
@@ -20396,63 +20487,26 @@ var dateTimeOptions = [
20396
20487
  ];
20397
20488
  async function formatDateLocale(name, time, args, budget, context) {
20398
20489
  if (Number.isNaN(time)) return budget.allocateString("Invalid Date");
20399
- const locales = [];
20490
+ let locales = [];
20400
20491
  const options = /* @__PURE__ */ Object.create(null);
20401
20492
  const release = retainValues(budget, () => [locales, options]);
20402
- const read = (value, key) => {
20403
- budget.visitNode();
20404
- if (context?.getProperty !== void 0) return context.getProperty(value, key);
20405
- const descriptor = getSandboxPropertyDescriptor(value, key, budget);
20406
- return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
20407
- };
20408
- const toObject = (value) => {
20409
- if (value === null || value === void 0) throw new TypeError("Cannot convert null or undefined to an object.");
20410
- if (typeof value === "object") return value;
20411
- const box = createSandboxBox(value);
20412
- allocateProducedSandboxValue(box, budget);
20413
- return box;
20414
- };
20415
20493
  try {
20416
- const inputLocales = args[0];
20417
- if (inputLocales !== void 0) {
20418
- const list2 = typeof inputLocales === "string" ? [inputLocales] : toObject(inputLocales);
20419
- const count = await sandboxNumber(await read(list2, "length"), budget, context);
20420
- const length = Number.isNaN(count) || count <= 0 ? 0 : Math.min(Math.floor(count), Number.MAX_SAFE_INTEGER);
20421
- for (let index = 0; index < length; index++) {
20422
- budget.visitNode();
20423
- const key = String(index);
20424
- if (getSandboxPropertyDescriptor(list2, key, budget) === void 0 && !(isFloat32Array(list2) && Object.hasOwn(list2, key))) continue;
20425
- const value = await read(list2, key);
20426
- if (typeof value !== "string" && (typeof value !== "object" || value === null))
20427
- throw new TypeError("Locale entries must be strings or objects.");
20428
- const tag = await sandboxString(value, budget, context);
20429
- budget.visitNode(tag.length);
20430
- const canonical = canonicalLocales(tag)[0];
20431
- budget.visitNode(locales.length);
20432
- if (!locales.includes(canonical)) locales.push(budget.allocateString(canonical));
20433
- }
20434
- }
20435
- const inputOptions = args[1] === void 0 ? /* @__PURE__ */ Object.create(null) : toObject(args[1]);
20494
+ locales = await canonicalizeGuestLocales(args[0], budget, context);
20495
+ const inputOptions = intlOptionsObject(args[1], budget);
20436
20496
  for (const [key, type] of dateTimeOptions) {
20437
- const value = await read(inputOptions, key);
20497
+ const value = await readIntlProperty(inputOptions, key, budget, context);
20438
20498
  if (value === void 0) continue;
20439
- if (type === "boolean") options[key] = Boolean(value);
20440
- else if (type === "number") {
20499
+ if (type === "number") {
20441
20500
  const number = await sandboxNumber(value, budget, context);
20442
20501
  if (!Number.isFinite(number) || number < 1 || number > 3)
20443
20502
  throw new RangeError("fractionalSecondDigits must be between 1 and 3.");
20444
20503
  options[key] = Math.floor(number);
20445
- } else {
20504
+ } else if (type === "zone") {
20446
20505
  const text = await sandboxString(value, budget, context);
20447
20506
  budget.visitNode(text.length);
20448
- if (type === "unicodeType") {
20449
- const valid = text.split("-").every((part) => part.length >= 3 && part.length <= 8 && [...part].every((char) => char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char >= "0" && char <= "9"));
20450
- if (!valid) throw new RangeError(`Invalid ${key} option.`);
20451
- } else if (type === "zone") {
20452
- new NativeDateTimeFormat("en", { timeZone: text });
20453
- } else if (!type.includes(text)) throw new RangeError(`Invalid ${key} option.`);
20507
+ new NativeDateTimeFormat("en", { timeZone: text });
20454
20508
  options[key] = text;
20455
- }
20509
+ } else options[key] = await convertIntlOption(value, key, type, budget, context);
20456
20510
  }
20457
20511
  const date = name !== "toLocaleTimeString";
20458
20512
  const clock = name !== "toLocaleDateString";
@@ -40449,4 +40503,4 @@ export {
40449
40503
  FileSnapshotBackend,
40450
40504
  run
40451
40505
  };
40452
- //# sourceMappingURL=chunk-KKMT52LR.js.map
40506
+ //# sourceMappingURL=chunk-GK6XA4H4.js.map