Skip to content

Commit

Permalink
Allow string and bigints for number formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade committed Jun 9, 2024
1 parent 01945eb commit 05951a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-badgers-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@quilted/localize': patch
---

Allow string and bigints for number formatting
14 changes: 9 additions & 5 deletions packages/localize/source/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export interface LocalizedFormatting {
LocalizedDateTimeFormatOptions
>;
formatNumber(
number: number,
number: number | bigint | string,
options?: Omit<
LocalizedNumberFormatOptions,
'currencySign' | 'currencyDisplay'
>,
): string;
formatCurrency(
amount: number,
amount: number | bigint | string,
options: Omit<LocalizedNumberFormatOptions, 'currency' | 'style'> & {
currency: string;
},
Expand Down Expand Up @@ -59,12 +59,16 @@ export function createLocalizedFormatting(locale: string): LocalizedFormatting {
numberFormatter,
dateTimeFormatter,
formatNumber(number, options) {
// @ts-expect-error NumberFormat.format() should accept string
return numberFormatter.get(options).format(number);
},
formatCurrency(amount, options) {
return numberFormatter
.get({...options, style: 'currency'})
.format(amount);
return (
numberFormatter
.get({...options, style: 'currency'})
// @ts-expect-error NumberFormat.format() should accept string
.format(amount)
);
},
formatDate(date, options) {
return dateTimeFormatter.get(options).format(date);
Expand Down

0 comments on commit 05951a2

Please sign in to comment.