Skip to content

Commit

Permalink
feat: BigInt support for useFormatter.format() (amannn#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tacomanator committed Mar 24, 2023
1 parent e2d688d commit 9b53395
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/use-intl/src/core/createFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default function createFormatter({
}

function number(
value: number,
value: number | bigint,
formatOrOptions?: string | NumberFormatOptions
) {
return getFormattedValue(
Expand Down
12 changes: 12 additions & 0 deletions packages/use-intl/test/core/createFormatter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ it('formats a date and time', () => {
});

it('formats a number', () => {
expect(intl.number(123456)).toBe(
'123,456'
);
});

it('formats a bigint', () => {
expect(intl.number(123456789123456n)).toBe(
'123,456,789,123,456'
);
});

it('formats a number as currency', () => {
expect(intl.number(123456.789, {style: 'currency', currency: 'USD'})).toBe(
'$123,456.79'
);
Expand Down
5 changes: 5 additions & 0 deletions packages/use-intl/test/react/useFormatter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ describe('number', () => {
screen.getByText('2,948,192,329.123');
});

it('formats a bigint', () => {
renderNumber(294819232912312);
screen.getByText('294,819,232,912,312');
});

it('accepts options', () => {
renderNumber(299.99, {currency: 'EUR', style: 'currency'});
screen.getByText('€299.99');
Expand Down

0 comments on commit 9b53395

Please sign in to comment.