Files
klz-cables.com/.pnpm-store/v10/files/27/849a088c5eeae4432eda45399237e5add2251ccd96188d06a0231c32104e7e6ba800d29ec6f68be22a28a2753fcd02fa0b54e06b96d70bcc71f315dccfc055
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

65 lines
3.3 KiB
Plaintext

import { GetOption } from "../GetOption.js";
import { IsWellFormedCurrencyCode } from "../IsWellFormedCurrencyCode.js";
import { IsWellFormedUnitIdentifier } from "../IsWellFormedUnitIdentifier.js";
import "../types/number.js";
import { invariant } from "../utils.js";
/**
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
*/
export function SetNumberFormatUnitOptions(internalSlots, options = Object.create(null)) {
// 1. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal").
const style = GetOption(options, "style", "string", [
"decimal",
"percent",
"currency",
"unit"
], "decimal");
// 2. Set internalSlots.[[Style]] to style.
internalSlots.style = style;
// 3. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
const currency = GetOption(options, "currency", "string", undefined, undefined);
// 4. If currency is not undefined, then
// a. If the result of IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception.
invariant(currency === undefined || IsWellFormedCurrencyCode(currency), "Malformed currency code", RangeError);
// 5. If style is "currency" and currency is undefined, throw a TypeError exception.
invariant(style !== "currency" || currency !== undefined, "currency cannot be undefined", TypeError);
// 6. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
const currencyDisplay = GetOption(options, "currencyDisplay", "string", [
"code",
"symbol",
"narrowSymbol",
"name"
], "symbol");
// 7. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard").
const currencySign = GetOption(options, "currencySign", "string", ["standard", "accounting"], "standard");
// 8. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
const unit = GetOption(options, "unit", "string", undefined, undefined);
// 9. If unit is not undefined, then
// a. If the result of IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception.
invariant(unit === undefined || IsWellFormedUnitIdentifier(unit), "Invalid unit argument for Intl.NumberFormat()", RangeError);
// 10. If style is "unit" and unit is undefined, throw a TypeError exception.
invariant(style !== "unit" || unit !== undefined, "unit cannot be undefined", TypeError);
// 11. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
const unitDisplay = GetOption(options, "unitDisplay", "string", [
"short",
"narrow",
"long"
], "short");
// 12. If style is "currency", then
if (style === "currency") {
// a. Set internalSlots.[[Currency]] to the result of converting currency to upper case as specified in 6.1.
internalSlots.currency = currency.toUpperCase();
// b. Set internalSlots.[[CurrencyDisplay]] to currencyDisplay.
internalSlots.currencyDisplay = currencyDisplay;
// c. Set internalSlots.[[CurrencySign]] to currencySign.
internalSlots.currencySign = currencySign;
}
// 13. If style is "unit", then
if (style === "unit") {
// a. Set internalSlots.[[Unit]] to unit.
internalSlots.unit = unit;
// b. Set internalSlots.[[UnitDisplay]] to unitDisplay.
internalSlots.unitDisplay = unitDisplay;
}
}