Socket
Socket
Sign inDemoInstall

@formatjs/ecma402-abstract

Package Overview
Dependencies
Maintainers
3
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/ecma402-abstract - npm Package Compare versions

Comparing version 1.12.0 to 1.13.0

GetStringOrBooleanOption.d.ts

6

index.d.ts

@@ -7,2 +7,3 @@ export * from './CanonicalizeLocaleList';

export * from './GetOptionsObject';
export * from './GetStringOrBooleanOption';
export * from './IsSanctionedSimpleUnitIdentifier';

@@ -12,9 +13,14 @@ export * from './IsValidTimeZoneName';

export * from './IsWellFormedUnitIdentifier';
export * from './NumberFormat/ApplyUnsignedRoundingMode';
export * from './NumberFormat/CollapseNumberRange';
export * from './NumberFormat/ComputeExponent';
export * from './NumberFormat/ComputeExponentForMagnitude';
export * from './NumberFormat/CurrencyDigits';
export * from './NumberFormat/FormatApproximately';
export * from './NumberFormat/FormatNumericToParts';
export * from './NumberFormat/FormatNumericToString';
export * from './NumberFormat/GetUnsignedRoundingMode';
export * from './NumberFormat/InitializeNumberFormat';
export * from './NumberFormat/PartitionNumberPattern';
export * from './NumberFormat/PartitionNumberRangePattern';
export * from './NumberFormat/SetNumberFormatDigitOptions';

@@ -21,0 +27,0 @@ export * from './NumberFormat/SetNumberFormatUnitOptions';

@@ -11,2 +11,3 @@ "use strict";

tslib_1.__exportStar(require("./GetOptionsObject"), exports);
tslib_1.__exportStar(require("./GetStringOrBooleanOption"), exports);
tslib_1.__exportStar(require("./IsSanctionedSimpleUnitIdentifier"), exports);

@@ -16,9 +17,14 @@ tslib_1.__exportStar(require("./IsValidTimeZoneName"), exports);

tslib_1.__exportStar(require("./IsWellFormedUnitIdentifier"), exports);
tslib_1.__exportStar(require("./NumberFormat/ApplyUnsignedRoundingMode"), exports);
tslib_1.__exportStar(require("./NumberFormat/CollapseNumberRange"), exports);
tslib_1.__exportStar(require("./NumberFormat/ComputeExponent"), exports);
tslib_1.__exportStar(require("./NumberFormat/ComputeExponentForMagnitude"), exports);
tslib_1.__exportStar(require("./NumberFormat/CurrencyDigits"), exports);
tslib_1.__exportStar(require("./NumberFormat/FormatApproximately"), exports);
tslib_1.__exportStar(require("./NumberFormat/FormatNumericToParts"), exports);
tslib_1.__exportStar(require("./NumberFormat/FormatNumericToString"), exports);
tslib_1.__exportStar(require("./NumberFormat/GetUnsignedRoundingMode"), exports);
tslib_1.__exportStar(require("./NumberFormat/InitializeNumberFormat"), exports);
tslib_1.__exportStar(require("./NumberFormat/PartitionNumberPattern"), exports);
tslib_1.__exportStar(require("./NumberFormat/PartitionNumberRangePattern"), exports);
tslib_1.__exportStar(require("./NumberFormat/SetNumberFormatDigitOptions"), exports);

@@ -25,0 +31,0 @@ tslib_1.__exportStar(require("./NumberFormat/SetNumberFormatUnitOptions"), exports);

@@ -7,2 +7,3 @@ export * from './CanonicalizeLocaleList';

export * from './GetOptionsObject';
export * from './GetStringOrBooleanOption';
export * from './IsSanctionedSimpleUnitIdentifier';

@@ -12,9 +13,14 @@ export * from './IsValidTimeZoneName';

export * from './IsWellFormedUnitIdentifier';
export * from './NumberFormat/ApplyUnsignedRoundingMode';
export * from './NumberFormat/CollapseNumberRange';
export * from './NumberFormat/ComputeExponent';
export * from './NumberFormat/ComputeExponentForMagnitude';
export * from './NumberFormat/CurrencyDigits';
export * from './NumberFormat/FormatApproximately';
export * from './NumberFormat/FormatNumericToParts';
export * from './NumberFormat/FormatNumericToString';
export * from './NumberFormat/GetUnsignedRoundingMode';
export * from './NumberFormat/InitializeNumberFormat';
export * from './NumberFormat/PartitionNumberPattern';
export * from './NumberFormat/PartitionNumberRangePattern';
export * from './NumberFormat/SetNumberFormatDigitOptions';

@@ -21,0 +27,0 @@ export * from './NumberFormat/SetNumberFormatUnitOptions';

@@ -7,2 +7,3 @@ export * from './CanonicalizeLocaleList';

export * from './GetOptionsObject';
export * from './GetStringOrBooleanOption';
export * from './IsSanctionedSimpleUnitIdentifier';

@@ -12,9 +13,14 @@ export * from './IsValidTimeZoneName';

export * from './IsWellFormedUnitIdentifier';
export * from './NumberFormat/ApplyUnsignedRoundingMode';
export * from './NumberFormat/CollapseNumberRange';
export * from './NumberFormat/ComputeExponent';
export * from './NumberFormat/ComputeExponentForMagnitude';
export * from './NumberFormat/CurrencyDigits';
export * from './NumberFormat/FormatApproximately';
export * from './NumberFormat/FormatNumericToParts';
export * from './NumberFormat/FormatNumericToString';
export * from './NumberFormat/GetUnsignedRoundingMode';
export * from './NumberFormat/InitializeNumberFormat';
export * from './NumberFormat/PartitionNumberPattern';
export * from './NumberFormat/PartitionNumberRangePattern';
export * from './NumberFormat/SetNumberFormatDigitOptions';

@@ -21,0 +27,0 @@ export * from './NumberFormat/SetNumberFormatUnitOptions';

4

lib/NumberFormat/format_to_parts.d.ts

@@ -1,2 +0,2 @@

import { NumberFormatOptionsStyle, NumberFormatOptionsNotation, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsUnitDisplay, NumberFormatLocaleInternalData, NumberFormatPart } from '../types/number';
import { NumberFormatOptionsStyle, NumberFormatOptionsNotation, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsUnitDisplay, NumberFormatLocaleInternalData, NumberFormatPart, UseGroupingType } from '../types/number';
interface NumberResult {

@@ -11,3 +11,3 @@ formattedString: string;

numberingSystem: string;
useGrouping: boolean;
useGrouping?: UseGroupingType;
style: NumberFormatOptionsStyle;

@@ -14,0 +14,0 @@ notation: NumberFormatOptionsNotation;

@@ -120,3 +120,3 @@ import { ToRawFixed } from './ToRawFixed';

// If compact number pattern exists, do not insert group separators.
!compactNumberPattern && options.useGrouping, decimalNumberPattern));
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern));
break;

@@ -123,0 +123,0 @@ }

@@ -9,2 +9,7 @@ import { CanonicalizeLocaleList } from '../CanonicalizeLocaleList';

import { CoerceOptionsToObject } from '../CoerceOptionsToObject';
import { GetNumberOption } from '../GetNumberOption';
import { GetStringOrBooleanOption } from '../GetStringOrBooleanOption';
var VALID_ROUND_INCREMENT_VALUES = [
1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000,
];
/**

@@ -56,11 +61,37 @@ * https://tc39.es/ecma402/#sec-initializenumberformat

SetNumberFormatDigitOptions(internalSlots, options, mnfdDefault, mxfdDefault, notation);
var roundingIncrement = GetNumberOption(options, 'roundingIncrement', 1, 5000, 1);
if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
}
if (roundingIncrement !== 1 &&
internalSlots.roundingType !== 'fractionDigits') {
throw new TypeError("For roundingIncrement > 1 only fractionDigits is a valid roundingType");
}
if (roundingIncrement !== 1 &&
internalSlots.maximumFractionDigits !== internalSlots.minimumFractionDigits) {
throw new RangeError('With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.');
}
internalSlots.roundingIncrement = roundingIncrement;
var trailingZeroDisplay = GetOption(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
internalSlots.trailingZeroDisplay = trailingZeroDisplay;
var compactDisplay = GetOption(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
var defaultUseGrouping = 'auto';
if (notation === 'compact') {
internalSlots.compactDisplay = compactDisplay;
defaultUseGrouping = 'min2';
}
var useGrouping = GetOption(options, 'useGrouping', 'boolean', undefined, true);
internalSlots.useGrouping = useGrouping;
var signDisplay = GetOption(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero'], 'auto');
internalSlots.signDisplay = signDisplay;
internalSlots.useGrouping = GetStringOrBooleanOption(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
internalSlots.signDisplay = GetOption(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
internalSlots.roundingMode = GetOption(options, 'roundingMode', 'string', [
'ceil',
'floor',
'expand',
'trunc',
'halfCeil',
'halfFloor',
'halfExpand',
'halfTrunc',
'halfEven',
], 'halfExpand');
return nf;
}

@@ -21,15 +21,20 @@ import { FormatNumericToString } from './FormatNumericToString';

}
else if (!isFinite(x)) {
else if (x == Number.POSITIVE_INFINITY || x == Number.NEGATIVE_INFINITY) {
n = symbols.infinity;
}
else {
if (internalSlots.style === 'percent') {
x *= 100;
if (!SameValue(x, -0)) {
if (!isFinite(x)) {
throw new Error('Input must be a mathematical value');
}
if (internalSlots.style == 'percent') {
x *= 100;
}
;
_b = ComputeExponent(numberFormat, x, {
getInternalSlots: getInternalSlots,
}), exponent = _b[0], magnitude = _b[1];
// Preserve more precision by doing multiplication when exponent is negative.
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
}
;
_b = ComputeExponent(numberFormat, x, {
getInternalSlots: getInternalSlots,
}), exponent = _b[0], magnitude = _b[1];
// Preserve more precision by doing multiplication when exponent is negative.
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
var formatNumberResult = FormatNumericToString(internalSlots, x);

@@ -36,0 +41,0 @@ n = formatNumberResult.formattedString;

import { GetNumberOption } from '../GetNumberOption';
import { DefaultNumberOption } from '../DefaultNumberOption';
import { GetOption } from '../GetOption';
/**

@@ -13,25 +14,69 @@ * https://tc39.es/ecma402/#sec-setnfdigitoptions

internalSlots.minimumIntegerDigits = mnid;
if (mnsd !== undefined || mxsd !== undefined) {
internalSlots.roundingType = 'significantDigits';
mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
internalSlots.minimumSignificantDigits = mnsd;
internalSlots.maximumSignificantDigits = mxsd;
var roundingPriority = GetOption(opts, 'roundingPriority', 'string', ['auto', 'morePrecision', 'lessPrecision'], 'auto');
var hasSd = mnsd !== undefined || mxsd !== undefined;
var hasFd = mnfd !== undefined || mxfd !== undefined;
var needSd = true;
var needFd = true;
if (roundingPriority === 'auto') {
needSd = hasSd;
if (hasSd || (!hasFd && notation === 'compact')) {
needFd = false;
}
}
else if (mnfd !== undefined || mxfd !== undefined) {
internalSlots.roundingType = 'fractionDigits';
mnfd = DefaultNumberOption(mnfd, 0, 20, mnfdDefault);
var mxfdActualDefault = Math.max(mnfd, mxfdDefault);
mxfd = DefaultNumberOption(mxfd, mnfd, 20, mxfdActualDefault);
internalSlots.minimumFractionDigits = mnfd;
internalSlots.maximumFractionDigits = mxfd;
if (needSd) {
if (hasSd) {
mnsd = DefaultNumberOption(mnsd, 1, 21, 1);
mxsd = DefaultNumberOption(mxsd, mnsd, 21, 21);
internalSlots.minimumSignificantDigits = mnsd;
internalSlots.maximumSignificantDigits = mxsd;
}
else {
internalSlots.minimumSignificantDigits = 1;
internalSlots.maximumSignificantDigits = 21;
}
}
else if (notation === 'compact') {
internalSlots.roundingType = 'compactRounding';
if (needFd) {
if (hasFd) {
// @ts-expect-error
mnfd = DefaultNumberOption(mnfd, 0, 20, undefined);
// @ts-expect-error
mxfd = DefaultNumberOption(mxfd, 0, 20, undefined);
if (mnfd === undefined) {
mnfd = Math.min(mnfdDefault, mxfd);
}
else if (mxfd === undefined) {
mxfd = Math.max(mxfdDefault, mnfd);
}
else if (mnfd > mxfd) {
throw new RangeError("Invalid range, ".concat(mnfd, " > ").concat(mxfd));
}
internalSlots.minimumFractionDigits = mnfd;
internalSlots.maximumFractionDigits = mxfd;
}
else {
internalSlots.minimumFractionDigits = mnfdDefault;
internalSlots.maximumFractionDigits = mxfdDefault;
}
}
if (needSd || needFd) {
if (roundingPriority === 'morePrecision') {
internalSlots.roundingType = 'morePrecision';
}
else if (roundingPriority === 'lessPrecision') {
internalSlots.roundingType = 'lessPrecision';
}
else if (hasSd) {
internalSlots.roundingType = 'significantDigits';
}
else {
internalSlots.roundingType = 'fractionDigits';
}
}
else {
internalSlots.roundingType = 'fractionDigits';
internalSlots.minimumFractionDigits = mnfdDefault;
internalSlots.maximumFractionDigits = mxfdDefault;
internalSlots.roundingType = 'morePrecision';
internalSlots.minimumFractionDigits = 0;
internalSlots.maximumFractionDigits = 0;
internalSlots.minimumSignificantDigits = 1;
internalSlots.maximumSignificantDigits = 2;
}
}

@@ -1,2 +0,2 @@

export declare type Formats = Pick<Intl.DateTimeFormatOptions, 'weekday' | 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'timeZoneName'> & {
export declare type Formats = Pick<Intl.DateTimeFormatOptions, 'weekday' | 'era' | 'year' | 'month' | 'day' | 'dayPeriod' | 'hour' | 'minute' | 'second' | 'timeZoneName'> & {
fractionalSecondDigits?: 0 | 1 | 2;

@@ -26,3 +26,3 @@ hour12?: boolean;

second: '2-digit' | 'numeric';
timeZoneName: 'short' | 'long';
timeZoneName: 'short' | 'long' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric';
fractionalSecondDigits?: 1 | 2 | 3;

@@ -50,3 +50,3 @@ hourCycle: string;

}
export declare type TABLE_6 = 'weekday' | 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'fractionalSecondDigits' | 'timeZoneName';
export declare type TABLE_6 = 'weekday' | 'era' | 'year' | 'month' | 'day' | 'dayPeriod' | 'hour' | 'minute' | 'second' | 'fractionalSecondDigits' | 'timeZoneName';
export declare type TABLE_2 = 'era' | 'year' | 'month' | 'day' | 'dayPeriod' | 'ampm' | 'hour' | 'minute' | 'second' | 'fractionalSecondDigits';

@@ -53,0 +53,0 @@ export declare type TimeZoneNameData = Record<string, {

import { LDMLPluralRule } from './plural-rules';
import { LocaleData } from './core';
export declare type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
export declare type NumberFormatRoundingType = 'significantDigits' | 'fractionDigits' | 'compactRounding';
export declare type RoundingPriorityType = 'auto' | 'morePrecision' | 'lessPrecision';
export declare type NumberFormatRoundingType = 'morePrecision' | 'lessPrecision' | 'significantDigits' | 'fractionDigits';
export declare type RoundingModeType = 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven';
export declare type UnsignedRoundingModeType = 'infinity' | 'zero' | 'half-infinity' | 'half-zero' | 'half-even';
export declare type UseGroupingType = 'min2' | 'auto' | 'always' | boolean;
export interface NumberFormatDigitOptions {

@@ -11,2 +15,3 @@ minimumIntegerDigits?: number;

maximumFractionDigits?: number;
roundingPriority?: RoundingPriorityType;
}

@@ -21,2 +26,4 @@ export interface NumberFormatDigitInternalSlots {

notation?: NumberFormatNotation;
roundingIncrement?: number;
trailingZeroDisplay?: TrailingZeroDisplay;
}

@@ -83,2 +90,3 @@ export declare type RawNumberLocaleData = LocaleData<NumberFormatLocaleInternalData>;

timeSeparator: string;
approximatelySign: string;
}

@@ -110,4 +118,5 @@ export interface RawNumberData {

export declare type NumberFormatOptionsNotation = NumberFormatNotation;
export declare type NumberFormatOptionsSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero';
export declare type NumberFormatOptionsSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero' | 'negative';
export declare type NumberFormatOptionsUnitDisplay = 'long' | 'short' | 'narrow';
export declare type TrailingZeroDisplay = 'auto' | 'stripIfInteger';
export interface NumberFormatInternal extends NumberFormatDigitInternalSlots {

@@ -125,3 +134,3 @@ locale: string;

signDisplay: NumberFormatOptionsSignDisplay;
useGrouping: boolean;
useGrouping?: UseGroupingType;
pl: Intl.PluralRules;

@@ -131,4 +140,5 @@ boundFormat?: Intl.NumberFormat['format'];

dataLocaleData: NumberFormatLocaleInternalData;
roundingMode?: RoundingModeType;
}
export declare type NumberFormatOptions = Omit<Intl.NumberFormatOptions, 'signDisplay'> & NumberFormatDigitOptions & {
export declare type NumberFormatOptions = Omit<Intl.NumberFormatOptions, 'signDisplay' | 'useGrouping'> & NumberFormatDigitOptions & {
localeMatcher?: NumberFormatOptionsLocaleMatcher;

@@ -144,11 +154,15 @@ style?: NumberFormatOptionsStyle;

numberingSystem?: string;
trailingZeroDisplay?: 'auto' | 'stripIfInteger';
roundingPriority?: 'auto' | 'morePrecision' | 'lessPrecision';
trailingZeroDisplay?: TrailingZeroDisplay;
roundingPriority?: RoundingPriorityType;
roundingIncrement?: number;
roundingMode?: RoundingModeType;
useGrouping?: UseGroupingType;
};
export declare type ResolvedNumberFormatOptions = Intl.ResolvedNumberFormatOptions & Pick<NumberFormatInternal, 'currencySign' | 'unit' | 'unitDisplay' | 'notation' | 'compactDisplay' | 'signDisplay'>;
export declare type NumberFormatPartTypes = Intl.NumberFormatPartTypes | 'exponentSeparator' | 'exponentMinusSign' | 'exponentInteger' | 'compact' | 'unit' | 'literal';
export declare type NumberFormatPartTypes = Intl.NumberFormatPartTypes | 'exponentSeparator' | 'exponentMinusSign' | 'exponentInteger' | 'compact' | 'unit' | 'literal' | 'approximatelySign';
export interface NumberFormatPart {
type: NumberFormatPartTypes;
value: string;
source?: string;
}
//# sourceMappingURL=number.d.ts.map

@@ -1,2 +0,2 @@

import { NumberFormatOptionsStyle, NumberFormatOptionsNotation, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsUnitDisplay, NumberFormatLocaleInternalData, NumberFormatPart } from '../types/number';
import { NumberFormatOptionsStyle, NumberFormatOptionsNotation, NumberFormatOptionsCompactDisplay, NumberFormatOptionsCurrencyDisplay, NumberFormatOptionsCurrencySign, NumberFormatOptionsUnitDisplay, NumberFormatLocaleInternalData, NumberFormatPart, UseGroupingType } from '../types/number';
interface NumberResult {

@@ -11,3 +11,3 @@ formattedString: string;

numberingSystem: string;
useGrouping: boolean;
useGrouping?: UseGroupingType;
style: NumberFormatOptionsStyle;

@@ -14,0 +14,0 @@ notation: NumberFormatOptionsNotation;

@@ -122,3 +122,3 @@ "use strict";

// If compact number pattern exists, do not insert group separators.
!compactNumberPattern && options.useGrouping, decimalNumberPattern));
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern));
break;

@@ -125,0 +125,0 @@ }

@@ -12,2 +12,7 @@ "use strict";

var CoerceOptionsToObject_1 = require("../CoerceOptionsToObject");
var GetNumberOption_1 = require("../GetNumberOption");
var GetStringOrBooleanOption_1 = require("../GetStringOrBooleanOption");
var VALID_ROUND_INCREMENT_VALUES = [
1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000,
];
/**

@@ -59,12 +64,38 @@ * https://tc39.es/ecma402/#sec-initializenumberformat

(0, SetNumberFormatDigitOptions_1.SetNumberFormatDigitOptions)(internalSlots, options, mnfdDefault, mxfdDefault, notation);
var roundingIncrement = (0, GetNumberOption_1.GetNumberOption)(options, 'roundingIncrement', 1, 5000, 1);
if (VALID_ROUND_INCREMENT_VALUES.indexOf(roundingIncrement) === -1) {
throw new RangeError("Invalid rounding increment value: ".concat(roundingIncrement, ".\nValid values are ").concat(VALID_ROUND_INCREMENT_VALUES, "."));
}
if (roundingIncrement !== 1 &&
internalSlots.roundingType !== 'fractionDigits') {
throw new TypeError("For roundingIncrement > 1 only fractionDigits is a valid roundingType");
}
if (roundingIncrement !== 1 &&
internalSlots.maximumFractionDigits !== internalSlots.minimumFractionDigits) {
throw new RangeError('With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.');
}
internalSlots.roundingIncrement = roundingIncrement;
var trailingZeroDisplay = (0, GetOption_1.GetOption)(options, 'trailingZeroDisplay', 'string', ['auto', 'stripIfInteger'], 'auto');
internalSlots.trailingZeroDisplay = trailingZeroDisplay;
var compactDisplay = (0, GetOption_1.GetOption)(options, 'compactDisplay', 'string', ['short', 'long'], 'short');
var defaultUseGrouping = 'auto';
if (notation === 'compact') {
internalSlots.compactDisplay = compactDisplay;
defaultUseGrouping = 'min2';
}
var useGrouping = (0, GetOption_1.GetOption)(options, 'useGrouping', 'boolean', undefined, true);
internalSlots.useGrouping = useGrouping;
var signDisplay = (0, GetOption_1.GetOption)(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero'], 'auto');
internalSlots.signDisplay = signDisplay;
internalSlots.useGrouping = (0, GetStringOrBooleanOption_1.GetStringOrBooleanOption)(options, 'useGrouping', ['min2', 'auto', 'always'], 'always', false, defaultUseGrouping);
internalSlots.signDisplay = (0, GetOption_1.GetOption)(options, 'signDisplay', 'string', ['auto', 'never', 'always', 'exceptZero', 'negative'], 'auto');
internalSlots.roundingMode = (0, GetOption_1.GetOption)(options, 'roundingMode', 'string', [
'ceil',
'floor',
'expand',
'trunc',
'halfCeil',
'halfFloor',
'halfExpand',
'halfTrunc',
'halfEven',
], 'halfExpand');
return nf;
}
exports.InitializeNumberFormat = InitializeNumberFormat;

@@ -25,15 +25,20 @@ "use strict";

}
else if (!isFinite(x)) {
else if (x == Number.POSITIVE_INFINITY || x == Number.NEGATIVE_INFINITY) {
n = symbols.infinity;
}
else {
if (internalSlots.style === 'percent') {
x *= 100;
if (!(0, _262_1.SameValue)(x, -0)) {
if (!isFinite(x)) {
throw new Error('Input must be a mathematical value');
}
if (internalSlots.style == 'percent') {
x *= 100;
}
;
_b = (0, ComputeExponent_1.ComputeExponent)(numberFormat, x, {
getInternalSlots: getInternalSlots,
}), exponent = _b[0], magnitude = _b[1];
// Preserve more precision by doing multiplication when exponent is negative.
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
}
;
_b = (0, ComputeExponent_1.ComputeExponent)(numberFormat, x, {
getInternalSlots: getInternalSlots,
}), exponent = _b[0], magnitude = _b[1];
// Preserve more precision by doing multiplication when exponent is negative.
x = exponent < 0 ? x * Math.pow(10, -exponent) : x / Math.pow(10, exponent);
var formatNumberResult = (0, FormatNumericToString_1.FormatNumericToString)(internalSlots, x);

@@ -40,0 +45,0 @@ n = formatNumberResult.formattedString;

@@ -6,2 +6,3 @@ "use strict";

var DefaultNumberOption_1 = require("../DefaultNumberOption");
var GetOption_1 = require("../GetOption");
/**

@@ -17,26 +18,70 @@ * https://tc39.es/ecma402/#sec-setnfdigitoptions

internalSlots.minimumIntegerDigits = mnid;
if (mnsd !== undefined || mxsd !== undefined) {
internalSlots.roundingType = 'significantDigits';
mnsd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnsd, 1, 21, 1);
mxsd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxsd, mnsd, 21, 21);
internalSlots.minimumSignificantDigits = mnsd;
internalSlots.maximumSignificantDigits = mxsd;
var roundingPriority = (0, GetOption_1.GetOption)(opts, 'roundingPriority', 'string', ['auto', 'morePrecision', 'lessPrecision'], 'auto');
var hasSd = mnsd !== undefined || mxsd !== undefined;
var hasFd = mnfd !== undefined || mxfd !== undefined;
var needSd = true;
var needFd = true;
if (roundingPriority === 'auto') {
needSd = hasSd;
if (hasSd || (!hasFd && notation === 'compact')) {
needFd = false;
}
}
else if (mnfd !== undefined || mxfd !== undefined) {
internalSlots.roundingType = 'fractionDigits';
mnfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnfd, 0, 20, mnfdDefault);
var mxfdActualDefault = Math.max(mnfd, mxfdDefault);
mxfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxfd, mnfd, 20, mxfdActualDefault);
internalSlots.minimumFractionDigits = mnfd;
internalSlots.maximumFractionDigits = mxfd;
if (needSd) {
if (hasSd) {
mnsd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnsd, 1, 21, 1);
mxsd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxsd, mnsd, 21, 21);
internalSlots.minimumSignificantDigits = mnsd;
internalSlots.maximumSignificantDigits = mxsd;
}
else {
internalSlots.minimumSignificantDigits = 1;
internalSlots.maximumSignificantDigits = 21;
}
}
else if (notation === 'compact') {
internalSlots.roundingType = 'compactRounding';
if (needFd) {
if (hasFd) {
// @ts-expect-error
mnfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mnfd, 0, 20, undefined);
// @ts-expect-error
mxfd = (0, DefaultNumberOption_1.DefaultNumberOption)(mxfd, 0, 20, undefined);
if (mnfd === undefined) {
mnfd = Math.min(mnfdDefault, mxfd);
}
else if (mxfd === undefined) {
mxfd = Math.max(mxfdDefault, mnfd);
}
else if (mnfd > mxfd) {
throw new RangeError("Invalid range, ".concat(mnfd, " > ").concat(mxfd));
}
internalSlots.minimumFractionDigits = mnfd;
internalSlots.maximumFractionDigits = mxfd;
}
else {
internalSlots.minimumFractionDigits = mnfdDefault;
internalSlots.maximumFractionDigits = mxfdDefault;
}
}
if (needSd || needFd) {
if (roundingPriority === 'morePrecision') {
internalSlots.roundingType = 'morePrecision';
}
else if (roundingPriority === 'lessPrecision') {
internalSlots.roundingType = 'lessPrecision';
}
else if (hasSd) {
internalSlots.roundingType = 'significantDigits';
}
else {
internalSlots.roundingType = 'fractionDigits';
}
}
else {
internalSlots.roundingType = 'fractionDigits';
internalSlots.minimumFractionDigits = mnfdDefault;
internalSlots.maximumFractionDigits = mxfdDefault;
internalSlots.roundingType = 'morePrecision';
internalSlots.minimumFractionDigits = 0;
internalSlots.maximumFractionDigits = 0;
internalSlots.minimumSignificantDigits = 1;
internalSlots.maximumSignificantDigits = 2;
}
}
exports.SetNumberFormatDigitOptions = SetNumberFormatDigitOptions;
{
"name": "@formatjs/ecma402-abstract",
"version": "1.12.0",
"version": "1.13.0",
"description": "A collection of implementation for ECMAScript abstract operations",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,2 +0,2 @@

export declare type Formats = Pick<Intl.DateTimeFormatOptions, 'weekday' | 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'timeZoneName'> & {
export declare type Formats = Pick<Intl.DateTimeFormatOptions, 'weekday' | 'era' | 'year' | 'month' | 'day' | 'dayPeriod' | 'hour' | 'minute' | 'second' | 'timeZoneName'> & {
fractionalSecondDigits?: 0 | 1 | 2;

@@ -26,3 +26,3 @@ hour12?: boolean;

second: '2-digit' | 'numeric';
timeZoneName: 'short' | 'long';
timeZoneName: 'short' | 'long' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric';
fractionalSecondDigits?: 1 | 2 | 3;

@@ -50,3 +50,3 @@ hourCycle: string;

}
export declare type TABLE_6 = 'weekday' | 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'fractionalSecondDigits' | 'timeZoneName';
export declare type TABLE_6 = 'weekday' | 'era' | 'year' | 'month' | 'day' | 'dayPeriod' | 'hour' | 'minute' | 'second' | 'fractionalSecondDigits' | 'timeZoneName';
export declare type TABLE_2 = 'era' | 'year' | 'month' | 'day' | 'dayPeriod' | 'ampm' | 'hour' | 'minute' | 'second' | 'fractionalSecondDigits';

@@ -53,0 +53,0 @@ export declare type TimeZoneNameData = Record<string, {

import { LDMLPluralRule } from './plural-rules';
import { LocaleData } from './core';
export declare type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
export declare type NumberFormatRoundingType = 'significantDigits' | 'fractionDigits' | 'compactRounding';
export declare type RoundingPriorityType = 'auto' | 'morePrecision' | 'lessPrecision';
export declare type NumberFormatRoundingType = 'morePrecision' | 'lessPrecision' | 'significantDigits' | 'fractionDigits';
export declare type RoundingModeType = 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven';
export declare type UnsignedRoundingModeType = 'infinity' | 'zero' | 'half-infinity' | 'half-zero' | 'half-even';
export declare type UseGroupingType = 'min2' | 'auto' | 'always' | boolean;
export interface NumberFormatDigitOptions {

@@ -11,2 +15,3 @@ minimumIntegerDigits?: number;

maximumFractionDigits?: number;
roundingPriority?: RoundingPriorityType;
}

@@ -21,2 +26,4 @@ export interface NumberFormatDigitInternalSlots {

notation?: NumberFormatNotation;
roundingIncrement?: number;
trailingZeroDisplay?: TrailingZeroDisplay;
}

@@ -83,2 +90,3 @@ export declare type RawNumberLocaleData = LocaleData<NumberFormatLocaleInternalData>;

timeSeparator: string;
approximatelySign: string;
}

@@ -110,4 +118,5 @@ export interface RawNumberData {

export declare type NumberFormatOptionsNotation = NumberFormatNotation;
export declare type NumberFormatOptionsSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero';
export declare type NumberFormatOptionsSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero' | 'negative';
export declare type NumberFormatOptionsUnitDisplay = 'long' | 'short' | 'narrow';
export declare type TrailingZeroDisplay = 'auto' | 'stripIfInteger';
export interface NumberFormatInternal extends NumberFormatDigitInternalSlots {

@@ -125,3 +134,3 @@ locale: string;

signDisplay: NumberFormatOptionsSignDisplay;
useGrouping: boolean;
useGrouping?: UseGroupingType;
pl: Intl.PluralRules;

@@ -131,4 +140,5 @@ boundFormat?: Intl.NumberFormat['format'];

dataLocaleData: NumberFormatLocaleInternalData;
roundingMode?: RoundingModeType;
}
export declare type NumberFormatOptions = Omit<Intl.NumberFormatOptions, 'signDisplay'> & NumberFormatDigitOptions & {
export declare type NumberFormatOptions = Omit<Intl.NumberFormatOptions, 'signDisplay' | 'useGrouping'> & NumberFormatDigitOptions & {
localeMatcher?: NumberFormatOptionsLocaleMatcher;

@@ -144,11 +154,15 @@ style?: NumberFormatOptionsStyle;

numberingSystem?: string;
trailingZeroDisplay?: 'auto' | 'stripIfInteger';
roundingPriority?: 'auto' | 'morePrecision' | 'lessPrecision';
trailingZeroDisplay?: TrailingZeroDisplay;
roundingPriority?: RoundingPriorityType;
roundingIncrement?: number;
roundingMode?: RoundingModeType;
useGrouping?: UseGroupingType;
};
export declare type ResolvedNumberFormatOptions = Intl.ResolvedNumberFormatOptions & Pick<NumberFormatInternal, 'currencySign' | 'unit' | 'unitDisplay' | 'notation' | 'compactDisplay' | 'signDisplay'>;
export declare type NumberFormatPartTypes = Intl.NumberFormatPartTypes | 'exponentSeparator' | 'exponentMinusSign' | 'exponentInteger' | 'compact' | 'unit' | 'literal';
export declare type NumberFormatPartTypes = Intl.NumberFormatPartTypes | 'exponentSeparator' | 'exponentMinusSign' | 'exponentInteger' | 'compact' | 'unit' | 'literal' | 'approximatelySign';
export interface NumberFormatPart {
type: NumberFormatPartTypes;
value: string;
source?: string;
}
//# sourceMappingURL=number.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc