@formatjs/ecma402-abstract 2.2.5 → 2.3.0
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.
- package/262.d.ts +5 -4
- package/262.js +13 -17
- package/CanonicalizeLocaleList.d.ts +1 -1
- package/IsSanctionedSimpleUnitIdentifier.d.ts +1 -1
- package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -1
- package/NumberFormat/ApplyUnsignedRoundingMode.js +11 -16
- package/NumberFormat/ComputeExponent.d.ts +2 -1
- package/NumberFormat/ComputeExponent.js +13 -13
- package/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -1
- package/NumberFormat/ComputeExponentForMagnitude.js +12 -3
- package/NumberFormat/FormatNumericRange.d.ts +2 -1
- package/NumberFormat/FormatNumericRangeToParts.d.ts +2 -1
- package/NumberFormat/FormatNumericToParts.d.ts +2 -1
- package/NumberFormat/FormatNumericToParts.js +1 -1
- package/NumberFormat/FormatNumericToString.d.ts +3 -2
- package/NumberFormat/FormatNumericToString.js +56 -14
- package/NumberFormat/InitializeNumberFormat.js +7 -36
- package/NumberFormat/PartitionNumberPattern.d.ts +4 -3
- package/NumberFormat/PartitionNumberPattern.js +25 -18
- package/NumberFormat/PartitionNumberRangePattern.d.ts +2 -1
- package/NumberFormat/PartitionNumberRangePattern.js +2 -3
- package/NumberFormat/SetNumberFormatDigitOptions.js +53 -24
- package/NumberFormat/ToRawFixed.d.ts +3 -2
- package/NumberFormat/ToRawFixed.js +55 -18
- package/NumberFormat/ToRawPrecision.d.ts +3 -2
- package/NumberFormat/ToRawPrecision.js +75 -42
- package/NumberFormat/format_to_parts.d.ts +5 -2
- package/NumberFormat/format_to_parts.js +20 -15
- package/constants.d.ts +4 -0
- package/constants.js +8 -0
- package/index.d.ts +2 -1
- package/index.js +3 -2
- package/lib/262.d.ts +5 -4
- package/lib/262.js +13 -17
- package/lib/CanonicalizeLocaleList.d.ts +1 -1
- package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +1 -1
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -1
- package/lib/NumberFormat/ApplyUnsignedRoundingMode.js +11 -16
- package/lib/NumberFormat/ComputeExponent.d.ts +2 -1
- package/lib/NumberFormat/ComputeExponent.js +13 -13
- package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +2 -1
- package/lib/NumberFormat/ComputeExponentForMagnitude.js +11 -3
- package/lib/NumberFormat/FormatNumericRange.d.ts +2 -1
- package/lib/NumberFormat/FormatNumericRangeToParts.d.ts +2 -1
- package/lib/NumberFormat/FormatNumericToParts.d.ts +2 -1
- package/lib/NumberFormat/FormatNumericToParts.js +1 -1
- package/lib/NumberFormat/FormatNumericToString.d.ts +3 -2
- package/lib/NumberFormat/FormatNumericToString.js +57 -15
- package/lib/NumberFormat/InitializeNumberFormat.js +7 -36
- package/lib/NumberFormat/PartitionNumberPattern.d.ts +4 -3
- package/lib/NumberFormat/PartitionNumberPattern.js +25 -18
- package/lib/NumberFormat/PartitionNumberRangePattern.d.ts +2 -1
- package/lib/NumberFormat/PartitionNumberRangePattern.js +2 -3
- package/lib/NumberFormat/SetNumberFormatDigitOptions.js +53 -24
- package/lib/NumberFormat/ToRawFixed.d.ts +3 -2
- package/lib/NumberFormat/ToRawFixed.js +54 -18
- package/lib/NumberFormat/ToRawPrecision.d.ts +3 -2
- package/lib/NumberFormat/ToRawPrecision.js +75 -43
- package/lib/NumberFormat/format_to_parts.d.ts +5 -2
- package/lib/NumberFormat/format_to_parts.js +19 -15
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/types/number.d.ts +16 -9
- package/lib/utils.d.ts +0 -5
- package/lib/utils.js +0 -9
- package/package.json +4 -3
- package/types/number.d.ts +16 -9
- package/utils.d.ts +0 -5
- package/utils.js +0 -10
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
import { TEN } from '../constants';
|
|
1
3
|
import { S_UNICODE_REGEX } from '../regex.generated';
|
|
2
|
-
import { ToRawFixed } from './ToRawFixed';
|
|
3
4
|
import { digitMapping } from './digit-mapping.generated';
|
|
5
|
+
import { GetUnsignedRoundingMode } from './GetUnsignedRoundingMode';
|
|
6
|
+
import { ToRawFixed } from './ToRawFixed';
|
|
4
7
|
// This is from: unicode-12.1.0/General_Category/Symbol/regex.js
|
|
5
8
|
// IE11 does not support unicode flag, otherwise this is just /\p{S}/u.
|
|
6
9
|
// /^\p{S}/u
|
|
@@ -115,9 +118,9 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
115
118
|
switch (part) {
|
|
116
119
|
case '{0}': {
|
|
117
120
|
// We only need to handle scientific and engineering notation here.
|
|
118
|
-
numberParts.push.apply(numberParts,
|
|
121
|
+
numberParts.push.apply(numberParts, partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem,
|
|
119
122
|
// If compact number pattern exists, do not insert group separators.
|
|
120
|
-
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern, style));
|
|
123
|
+
!compactNumberPattern && Boolean(options.useGrouping), decimalNumberPattern, style, options.roundingIncrement, GetUnsignedRoundingMode(options.roundingMode, sign === -1)));
|
|
121
124
|
break;
|
|
122
125
|
}
|
|
123
126
|
case '-':
|
|
@@ -160,7 +163,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
160
163
|
var unitName = void 0;
|
|
161
164
|
var currencyNameData = data.currencies[options.currency];
|
|
162
165
|
if (currencyNameData) {
|
|
163
|
-
unitName = selectPlural(pl, numberResult.roundedNumber
|
|
166
|
+
unitName = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), currencyNameData.displayName);
|
|
164
167
|
}
|
|
165
168
|
else {
|
|
166
169
|
// Fallback for unknown currency
|
|
@@ -197,7 +200,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
197
200
|
var unitPattern = void 0;
|
|
198
201
|
if (unitData) {
|
|
199
202
|
// Simple unit pattern
|
|
200
|
-
unitPattern = selectPlural(pl, numberResult.roundedNumber
|
|
203
|
+
unitPattern = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), data.units.simple[unit][unitDisplay]);
|
|
201
204
|
}
|
|
202
205
|
else {
|
|
203
206
|
// See: http://unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
|
|
@@ -205,7 +208,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
205
208
|
// Implementation note: we are not following TR-35 here because we need to format to parts!
|
|
206
209
|
var _b = unit.split('-per-'), numeratorUnit = _b[0], denominatorUnit = _b[1];
|
|
207
210
|
unitData = data.units.simple[numeratorUnit];
|
|
208
|
-
var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber
|
|
211
|
+
var numeratorUnitPattern = selectPlural(pl, numberResult.roundedNumber.times(TEN.pow(exponent)).toNumber(), data.units.simple[numeratorUnit][unitDisplay]);
|
|
209
212
|
var perUnitPattern = data.units.simple[denominatorUnit].perUnit[unitDisplay];
|
|
210
213
|
if (perUnitPattern) {
|
|
211
214
|
// perUnitPattern exists, combine it with numeratorUnitPattern
|
|
@@ -251,7 +254,7 @@ export default function formatToParts(numberResult, data, pl, options) {
|
|
|
251
254
|
}
|
|
252
255
|
// A subset of https://tc39.es/ecma402/#sec-partitionnotationsubpattern
|
|
253
256
|
// Plus the exponent parts handling.
|
|
254
|
-
function
|
|
257
|
+
function partitionNumberIntoParts(symbols, numberResult, notation, exponent, numberingSystem, useGrouping,
|
|
255
258
|
/**
|
|
256
259
|
* This is the decimal number pattern without signs or symbols.
|
|
257
260
|
* It is used to infer the group size when `useGrouping` is true.
|
|
@@ -259,14 +262,14 @@ function paritionNumberIntoParts(symbols, numberResult, notation, exponent, numb
|
|
|
259
262
|
* A typical value looks like "#,##0.00" (primary group size is 3).
|
|
260
263
|
* Some locales like Hindi has secondary group size of 2 (e.g. "#,##,##0.00").
|
|
261
264
|
*/
|
|
262
|
-
decimalNumberPattern, style) {
|
|
265
|
+
decimalNumberPattern, style, roundingIncrement, unsignedRoundingMode) {
|
|
263
266
|
var result = [];
|
|
264
267
|
// eslint-disable-next-line prefer-const
|
|
265
268
|
var n = numberResult.formattedString, x = numberResult.roundedNumber;
|
|
266
|
-
if (isNaN(
|
|
269
|
+
if (x.isNaN()) {
|
|
267
270
|
return [{ type: 'nan', value: n }];
|
|
268
271
|
}
|
|
269
|
-
else if (!isFinite(
|
|
272
|
+
else if (!x.isFinite()) {
|
|
270
273
|
return [{ type: 'infinity', value: n }];
|
|
271
274
|
}
|
|
272
275
|
var digitReplacementTable = digitMapping[numberingSystem];
|
|
@@ -291,7 +294,8 @@ decimalNumberPattern, style) {
|
|
|
291
294
|
// unless the rounded number is greater than 10000:
|
|
292
295
|
// NumberFormat('de', {notation: 'compact', compactDisplay: 'short'}).format(1234) //=> "1234"
|
|
293
296
|
// NumberFormat('de').format(1234) //=> "1.234"
|
|
294
|
-
if (useGrouping &&
|
|
297
|
+
if (useGrouping &&
|
|
298
|
+
(notation !== 'compact' || x.greaterThanOrEqualTo(10000))) {
|
|
295
299
|
// a. Let groupSepSymbol be the implementation-, locale-, and numbering system-dependent (ILND) String representing the grouping separator.
|
|
296
300
|
// For currency we should use `currencyGroup` instead of generic `group`
|
|
297
301
|
var groupSepSymbol = style === 'currency' && symbols.currencyGroup != null
|
|
@@ -346,13 +350,13 @@ decimalNumberPattern, style) {
|
|
|
346
350
|
result.push({ type: 'decimal', value: decimalSepSymbol }, { type: 'fraction', value: fraction });
|
|
347
351
|
}
|
|
348
352
|
if ((notation === 'scientific' || notation === 'engineering') &&
|
|
349
|
-
isFinite(
|
|
353
|
+
x.isFinite()) {
|
|
350
354
|
result.push({ type: 'exponentSeparator', value: symbols.exponential });
|
|
351
355
|
if (exponent < 0) {
|
|
352
356
|
result.push({ type: 'exponentMinusSign', value: symbols.minusSign });
|
|
353
357
|
exponent = -exponent;
|
|
354
358
|
}
|
|
355
|
-
var exponentResult = ToRawFixed(exponent, 0, 0);
|
|
359
|
+
var exponentResult = ToRawFixed(new Decimal(exponent), 0, 0, roundingIncrement, unsignedRoundingMode);
|
|
356
360
|
result.push({
|
|
357
361
|
type: 'exponentInteger',
|
|
358
362
|
value: exponentResult.formattedString,
|
|
@@ -398,7 +402,7 @@ function getCompactDisplayPattern(numberResult, pl, data, style, compactDisplay,
|
|
|
398
402
|
if (!compactPluralRules) {
|
|
399
403
|
return null;
|
|
400
404
|
}
|
|
401
|
-
pattern = selectPlural(pl, roundedNumber, compactPluralRules);
|
|
405
|
+
pattern = selectPlural(pl, roundedNumber.toNumber(), compactPluralRules);
|
|
402
406
|
}
|
|
403
407
|
else {
|
|
404
408
|
var byNumberingSystem = data.numbers.decimal;
|
|
@@ -408,7 +412,7 @@ function getCompactDisplayPattern(numberResult, pl, data, style, compactDisplay,
|
|
|
408
412
|
if (!compactPlaralRule) {
|
|
409
413
|
return null;
|
|
410
414
|
}
|
|
411
|
-
pattern = selectPlural(pl, roundedNumber, compactPlaralRule);
|
|
415
|
+
pattern = selectPlural(pl, roundedNumber.toNumber(), compactPlaralRule);
|
|
412
416
|
}
|
|
413
417
|
// See https://unicode.org/reports/tr35/tr35-numbers.html#Compact_Number_Formats
|
|
414
418
|
// > If the value is precisely “0”, either explicit or defaulted, then the normal number format
|
package/lib/constants.js
ADDED
package/lib/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export * from './NumberFormat/ToRawFixed';
|
|
|
30
30
|
export * from './NumberFormat/ToRawPrecision';
|
|
31
31
|
export * from './PartitionPattern';
|
|
32
32
|
export * from './SupportedLocales';
|
|
33
|
-
export { createDataProperty, defineProperty, getInternalSlot,
|
|
33
|
+
export { createDataProperty, defineProperty, getInternalSlot, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
34
34
|
export type { LiteralPart } from './utils';
|
|
35
35
|
export * from './262';
|
|
36
36
|
export { isMissingLocaleDataError } from './data';
|
|
@@ -42,3 +42,4 @@ export * from './types/number';
|
|
|
42
42
|
export * from './types/plural-rules';
|
|
43
43
|
export * from './types/relative-time';
|
|
44
44
|
export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
|
|
45
|
+
export { ZERO } from './constants';
|
package/lib/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export * from './NumberFormat/ToRawFixed';
|
|
|
30
30
|
export * from './NumberFormat/ToRawPrecision';
|
|
31
31
|
export * from './PartitionPattern';
|
|
32
32
|
export * from './SupportedLocales';
|
|
33
|
-
export { createDataProperty, defineProperty, getInternalSlot,
|
|
33
|
+
export { createDataProperty, defineProperty, getInternalSlot, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
34
34
|
export * from './262';
|
|
35
35
|
export { isMissingLocaleDataError } from './data';
|
|
36
36
|
export * from './types/date-time';
|
|
@@ -40,3 +40,4 @@ export * from './types/number';
|
|
|
40
40
|
export * from './types/plural-rules';
|
|
41
41
|
export * from './types/relative-time';
|
|
42
42
|
export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
|
|
43
|
+
export { ZERO } from './constants';
|
package/lib/types/number.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
1
2
|
import { LocaleData } from './core';
|
|
2
3
|
import { LDMLPluralRule } from './plural-rules';
|
|
3
4
|
export type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
@@ -13,17 +14,22 @@ export interface NumberFormatDigitOptions {
|
|
|
13
14
|
minimumFractionDigits?: number;
|
|
14
15
|
maximumFractionDigits?: number;
|
|
15
16
|
roundingPriority?: RoundingPriorityType;
|
|
17
|
+
roundingIncrement?: number;
|
|
18
|
+
roundingMode?: RoundingModeType;
|
|
19
|
+
trailingZeroDisplay?: TrailingZeroDisplay;
|
|
16
20
|
}
|
|
17
21
|
export interface NumberFormatDigitInternalSlots {
|
|
18
22
|
minimumIntegerDigits: number;
|
|
19
|
-
minimumSignificantDigits
|
|
20
|
-
maximumSignificantDigits
|
|
23
|
+
minimumSignificantDigits: number;
|
|
24
|
+
maximumSignificantDigits: number;
|
|
21
25
|
roundingType: NumberFormatRoundingType;
|
|
22
|
-
minimumFractionDigits
|
|
23
|
-
maximumFractionDigits
|
|
24
|
-
notation
|
|
25
|
-
roundingIncrement
|
|
26
|
-
|
|
26
|
+
minimumFractionDigits: number;
|
|
27
|
+
maximumFractionDigits: number;
|
|
28
|
+
notation: NumberFormatNotation;
|
|
29
|
+
roundingIncrement: number;
|
|
30
|
+
roundingMode: RoundingModeType;
|
|
31
|
+
trailingZeroDisplay: TrailingZeroDisplay;
|
|
32
|
+
roundingPriority: RoundingPriorityType;
|
|
27
33
|
}
|
|
28
34
|
export type RawNumberLocaleData = LocaleData<NumberFormatLocaleInternalData>;
|
|
29
35
|
export interface NumberFormatLocaleInternalData {
|
|
@@ -106,8 +112,9 @@ export type LDMLPluralRuleMap<T> = Omit<Partial<Record<LDMLPluralRule, T>>, 'oth
|
|
|
106
112
|
};
|
|
107
113
|
export interface RawNumberFormatResult {
|
|
108
114
|
formattedString: string;
|
|
109
|
-
roundedNumber:
|
|
115
|
+
roundedNumber: Decimal;
|
|
110
116
|
integerDigitsCount: number;
|
|
117
|
+
roundingMagnitude: number;
|
|
111
118
|
}
|
|
112
119
|
export type NumberFormatOptionsLocaleMatcher = 'lookup' | 'best fit';
|
|
113
120
|
export type NumberFormatOptionsStyle = 'decimal' | 'percent' | 'currency' | 'unit';
|
|
@@ -135,7 +142,7 @@ export interface NumberFormatInternal extends NumberFormatDigitInternalSlots {
|
|
|
135
142
|
boundFormat?: Intl.NumberFormat['format'];
|
|
136
143
|
numberingSystem: string;
|
|
137
144
|
dataLocaleData: NumberFormatLocaleInternalData;
|
|
138
|
-
roundingMode
|
|
145
|
+
roundingMode: RoundingModeType;
|
|
139
146
|
}
|
|
140
147
|
export type NumberFormatOptions = Omit<Intl.NumberFormatOptions, 'signDisplay' | 'useGrouping'> & NumberFormatDigitOptions & {
|
|
141
148
|
localeMatcher?: NumberFormatOptionsLocaleMatcher;
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
3
|
-
* @param x number
|
|
4
|
-
*/
|
|
5
|
-
export declare function getMagnitude(x: number): number;
|
|
6
1
|
export declare function repeat(s: string, times: number): string;
|
|
7
2
|
export declare function setInternalSlot<Instance extends object, Internal extends object, Field extends keyof Internal>(map: WeakMap<Instance, Internal>, pl: Instance, field: Field, value: NonNullable<Internal>[Field]): void;
|
|
8
3
|
export declare function setMultiInternalSlots<Instance extends object, Internal extends object, K extends keyof Internal>(map: WeakMap<Instance, Internal>, pl: Instance, props: Pick<NonNullable<Internal>, K>): void;
|
package/lib/utils.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { __spreadArray } from "tslib";
|
|
2
2
|
import { memoize, strategies } from '@formatjs/fast-memoize';
|
|
3
|
-
/**
|
|
4
|
-
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
5
|
-
* @param x number
|
|
6
|
-
*/
|
|
7
|
-
export function getMagnitude(x) {
|
|
8
|
-
// Cannot count string length via Number.toString because it may use scientific notation
|
|
9
|
-
// for very small or very large numbers.
|
|
10
|
-
return Math.floor(Math.log(x) * Math.LOG10E);
|
|
11
|
-
}
|
|
12
3
|
export function repeat(s, times) {
|
|
13
4
|
if (typeof s.repeat === 'function') {
|
|
14
5
|
return s.repeat(times);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/ecma402-abstract",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A collection of implementation for ECMAScript abstract operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"format"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"decimal.js": "10",
|
|
17
18
|
"tslib": "2",
|
|
18
|
-
"@formatjs/fast-memoize": "2.2.
|
|
19
|
-
"@formatjs/intl-localematcher": "0.5.
|
|
19
|
+
"@formatjs/fast-memoize": "2.2.5",
|
|
20
|
+
"@formatjs/intl-localematcher": "0.5.9"
|
|
20
21
|
},
|
|
21
22
|
"author": "Long Ho <holevietlong@gmail.com",
|
|
22
23
|
"bugs": {
|
package/types/number.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
1
2
|
import { LocaleData } from './core';
|
|
2
3
|
import { LDMLPluralRule } from './plural-rules';
|
|
3
4
|
export type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
@@ -13,17 +14,22 @@ export interface NumberFormatDigitOptions {
|
|
|
13
14
|
minimumFractionDigits?: number;
|
|
14
15
|
maximumFractionDigits?: number;
|
|
15
16
|
roundingPriority?: RoundingPriorityType;
|
|
17
|
+
roundingIncrement?: number;
|
|
18
|
+
roundingMode?: RoundingModeType;
|
|
19
|
+
trailingZeroDisplay?: TrailingZeroDisplay;
|
|
16
20
|
}
|
|
17
21
|
export interface NumberFormatDigitInternalSlots {
|
|
18
22
|
minimumIntegerDigits: number;
|
|
19
|
-
minimumSignificantDigits
|
|
20
|
-
maximumSignificantDigits
|
|
23
|
+
minimumSignificantDigits: number;
|
|
24
|
+
maximumSignificantDigits: number;
|
|
21
25
|
roundingType: NumberFormatRoundingType;
|
|
22
|
-
minimumFractionDigits
|
|
23
|
-
maximumFractionDigits
|
|
24
|
-
notation
|
|
25
|
-
roundingIncrement
|
|
26
|
-
|
|
26
|
+
minimumFractionDigits: number;
|
|
27
|
+
maximumFractionDigits: number;
|
|
28
|
+
notation: NumberFormatNotation;
|
|
29
|
+
roundingIncrement: number;
|
|
30
|
+
roundingMode: RoundingModeType;
|
|
31
|
+
trailingZeroDisplay: TrailingZeroDisplay;
|
|
32
|
+
roundingPriority: RoundingPriorityType;
|
|
27
33
|
}
|
|
28
34
|
export type RawNumberLocaleData = LocaleData<NumberFormatLocaleInternalData>;
|
|
29
35
|
export interface NumberFormatLocaleInternalData {
|
|
@@ -106,8 +112,9 @@ export type LDMLPluralRuleMap<T> = Omit<Partial<Record<LDMLPluralRule, T>>, 'oth
|
|
|
106
112
|
};
|
|
107
113
|
export interface RawNumberFormatResult {
|
|
108
114
|
formattedString: string;
|
|
109
|
-
roundedNumber:
|
|
115
|
+
roundedNumber: Decimal;
|
|
110
116
|
integerDigitsCount: number;
|
|
117
|
+
roundingMagnitude: number;
|
|
111
118
|
}
|
|
112
119
|
export type NumberFormatOptionsLocaleMatcher = 'lookup' | 'best fit';
|
|
113
120
|
export type NumberFormatOptionsStyle = 'decimal' | 'percent' | 'currency' | 'unit';
|
|
@@ -135,7 +142,7 @@ export interface NumberFormatInternal extends NumberFormatDigitInternalSlots {
|
|
|
135
142
|
boundFormat?: Intl.NumberFormat['format'];
|
|
136
143
|
numberingSystem: string;
|
|
137
144
|
dataLocaleData: NumberFormatLocaleInternalData;
|
|
138
|
-
roundingMode
|
|
145
|
+
roundingMode: RoundingModeType;
|
|
139
146
|
}
|
|
140
147
|
export type NumberFormatOptions = Omit<Intl.NumberFormatOptions, 'signDisplay' | 'useGrouping'> & NumberFormatDigitOptions & {
|
|
141
148
|
localeMatcher?: NumberFormatOptionsLocaleMatcher;
|
package/utils.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
3
|
-
* @param x number
|
|
4
|
-
*/
|
|
5
|
-
export declare function getMagnitude(x: number): number;
|
|
6
1
|
export declare function repeat(s: string, times: number): string;
|
|
7
2
|
export declare function setInternalSlot<Instance extends object, Internal extends object, Field extends keyof Internal>(map: WeakMap<Instance, Internal>, pl: Instance, field: Field, value: NonNullable<Internal>[Field]): void;
|
|
8
3
|
export declare function setMultiInternalSlots<Instance extends object, Internal extends object, K extends keyof Internal>(map: WeakMap<Instance, Internal>, pl: Instance, props: Pick<NonNullable<Internal>, K>): void;
|
package/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMemoizedListFormat = exports.createMemoizedLocale = exports.createMemoizedPluralRules = exports.createMemoizedDateTimeFormat = exports.createMemoizedNumberFormat = exports.UNICODE_EXTENSION_SEQUENCE_REGEX = void 0;
|
|
4
|
-
exports.getMagnitude = getMagnitude;
|
|
5
4
|
exports.repeat = repeat;
|
|
6
5
|
exports.setInternalSlot = setInternalSlot;
|
|
7
6
|
exports.setMultiInternalSlots = setMultiInternalSlots;
|
|
@@ -13,15 +12,6 @@ exports.createDataProperty = createDataProperty;
|
|
|
13
12
|
exports.invariant = invariant;
|
|
14
13
|
var tslib_1 = require("tslib");
|
|
15
14
|
var fast_memoize_1 = require("@formatjs/fast-memoize");
|
|
16
|
-
/**
|
|
17
|
-
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
18
|
-
* @param x number
|
|
19
|
-
*/
|
|
20
|
-
function getMagnitude(x) {
|
|
21
|
-
// Cannot count string length via Number.toString because it may use scientific notation
|
|
22
|
-
// for very small or very large numbers.
|
|
23
|
-
return Math.floor(Math.log(x) * Math.LOG10E);
|
|
24
|
-
}
|
|
25
15
|
function repeat(s, times) {
|
|
26
16
|
if (typeof s.repeat === 'function') {
|
|
27
17
|
return s.repeat(times);
|