frontend/.pnpm-store/v3/files/36/57db8db84454acc61013fb13c978cfb583658f8712c7b33b62ecffe1ebf3126394119e4d3cc560cd3771d4114bac0152b61ee743de00b095448867f5dc5ef4-exec

40 lines
1.9 KiB
Plaintext
Executable File

import { GetOption } from '../GetOption';
import { IsWellFormedCurrencyCode } from '../IsWellFormedCurrencyCode';
import { IsWellFormedUnitIdentifier } from '../IsWellFormedUnitIdentifier';
/**
* https://tc39.es/ecma402/#sec-setnumberformatunitoptions
*/
export function SetNumberFormatUnitOptions(nf, options, _a) {
if (options === void 0) { options = Object.create(null); }
var getInternalSlots = _a.getInternalSlots;
var internalSlots = getInternalSlots(nf);
var style = GetOption(options, 'style', 'string', ['decimal', 'percent', 'currency', 'unit'], 'decimal');
internalSlots.style = style;
var currency = GetOption(options, 'currency', 'string', undefined, undefined);
if (currency !== undefined && !IsWellFormedCurrencyCode(currency)) {
throw RangeError('Malformed currency code');
}
if (style === 'currency' && currency === undefined) {
throw TypeError('currency cannot be undefined');
}
var currencyDisplay = GetOption(options, 'currencyDisplay', 'string', ['code', 'symbol', 'narrowSymbol', 'name'], 'symbol');
var currencySign = GetOption(options, 'currencySign', 'string', ['standard', 'accounting'], 'standard');
var unit = GetOption(options, 'unit', 'string', undefined, undefined);
if (unit !== undefined && !IsWellFormedUnitIdentifier(unit)) {
throw RangeError('Invalid unit argument for Intl.NumberFormat()');
}
if (style === 'unit' && unit === undefined) {
throw TypeError('unit cannot be undefined');
}
var unitDisplay = GetOption(options, 'unitDisplay', 'string', ['short', 'narrow', 'long'], 'short');
if (style === 'currency') {
internalSlots.currency = currency.toUpperCase();
internalSlots.currencyDisplay = currencyDisplay;
internalSlots.currencySign = currencySign;
}
if (style === 'unit') {
internalSlots.unit = unit;
internalSlots.unitDisplay = unitDisplay;
}
}