mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
86 lines
3.5 KiB
TypeScript
86 lines
3.5 KiB
TypeScript
//// [tests/cases/conformance/es2023/intlNumberFormatES2023.ts] ////
|
|
|
|
//// [intlNumberFormatES2023.ts]
|
|
// New / updated resolved options in ES2023, including type change for useGrouping
|
|
const { roundingPriority, roundingMode, roundingIncrement, trailingZeroDisplay, useGrouping } = new Intl.NumberFormat('en-GB').resolvedOptions();
|
|
|
|
// Empty options
|
|
new Intl.NumberFormat('en-GB', {});
|
|
|
|
// Rounding
|
|
new Intl.NumberFormat('en-GB', { roundingPriority: 'lessPrecision', roundingIncrement: 100, roundingMode: 'trunc' });
|
|
|
|
// Changes to signDisplay
|
|
const { signDisplay } = new Intl.NumberFormat('en-GB', { signDisplay: 'negative' }).resolvedOptions();
|
|
|
|
// Changes to useGrouping
|
|
new Intl.NumberFormat('en-GB', { useGrouping: true });
|
|
new Intl.NumberFormat('en-GB', { useGrouping: 'true' });
|
|
new Intl.NumberFormat('en-GB', { useGrouping: 'always' });
|
|
|
|
// formatRange
|
|
new Intl.NumberFormat('en-GB').formatRange(10, 100);
|
|
new Intl.NumberFormat('en-GB').formatRange(10n, 1000n);
|
|
new Intl.NumberFormat('en-GB').formatRangeToParts(10, 1000)[0];
|
|
new Intl.NumberFormat('en-GB').formatRangeToParts(10n, 1000n)[0];
|
|
|
|
// Arbitrary-precision string arguments
|
|
new Intl.NumberFormat('en-GB').format('-12.3E-4');
|
|
new Intl.NumberFormat('en-GB').formatRange('123.4', '567.8');
|
|
new Intl.NumberFormat('en-GB').formatRangeToParts('123E-4', '567E8');
|
|
new Intl.NumberFormat('en-GB').format('Infinity');
|
|
new Intl.NumberFormat('en-GB').format('-Infinity');
|
|
new Intl.NumberFormat('en-GB').format('+Infinity');
|
|
|
|
// Test approximatelySign part type
|
|
const nf = new Intl.NumberFormat("en-US", {
|
|
style: "currency",
|
|
currency: "EUR",
|
|
maximumFractionDigits: 0,
|
|
});
|
|
|
|
const filtered = nf
|
|
.formatRangeToParts(100, 100)
|
|
.filter((part) => part.type !== "approximatelySign")
|
|
.map((part) => part.value)
|
|
.join("");
|
|
|
|
|
|
//// [intlNumberFormatES2023.js]
|
|
"use strict";
|
|
// New / updated resolved options in ES2023, including type change for useGrouping
|
|
const { roundingPriority, roundingMode, roundingIncrement, trailingZeroDisplay, useGrouping } = new Intl.NumberFormat('en-GB').resolvedOptions();
|
|
// Empty options
|
|
new Intl.NumberFormat('en-GB', {});
|
|
// Rounding
|
|
new Intl.NumberFormat('en-GB', { roundingPriority: 'lessPrecision', roundingIncrement: 100, roundingMode: 'trunc' });
|
|
// Changes to signDisplay
|
|
const { signDisplay } = new Intl.NumberFormat('en-GB', { signDisplay: 'negative' }).resolvedOptions();
|
|
// Changes to useGrouping
|
|
new Intl.NumberFormat('en-GB', { useGrouping: true });
|
|
new Intl.NumberFormat('en-GB', { useGrouping: 'true' });
|
|
new Intl.NumberFormat('en-GB', { useGrouping: 'always' });
|
|
// formatRange
|
|
new Intl.NumberFormat('en-GB').formatRange(10, 100);
|
|
new Intl.NumberFormat('en-GB').formatRange(10n, 1000n);
|
|
new Intl.NumberFormat('en-GB').formatRangeToParts(10, 1000)[0];
|
|
new Intl.NumberFormat('en-GB').formatRangeToParts(10n, 1000n)[0];
|
|
// Arbitrary-precision string arguments
|
|
new Intl.NumberFormat('en-GB').format('-12.3E-4');
|
|
new Intl.NumberFormat('en-GB').formatRange('123.4', '567.8');
|
|
new Intl.NumberFormat('en-GB').formatRangeToParts('123E-4', '567E8');
|
|
new Intl.NumberFormat('en-GB').format('Infinity');
|
|
new Intl.NumberFormat('en-GB').format('-Infinity');
|
|
new Intl.NumberFormat('en-GB').format('+Infinity');
|
|
// Test approximatelySign part type
|
|
const nf = new Intl.NumberFormat("en-US", {
|
|
style: "currency",
|
|
currency: "EUR",
|
|
maximumFractionDigits: 0,
|
|
});
|
|
const filtered = nf
|
|
.formatRangeToParts(100, 100)
|
|
.filter((part) => part.type !== "approximatelySign")
|
|
.map((part) => part.value)
|
|
.join("");
|