-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NumberFormatUtils ios platform variant
- Loading branch information
1 parent
baf7a5f
commit 50b98d8
Showing
2 changed files
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type {ValueOf} from 'type-fest'; | ||
import intlPolyfill from '@libs/IntlPolyfill'; | ||
import memoize from '@libs/memoize'; | ||
import type CONST from '@src/CONST'; | ||
|
||
// On iOS, polyfills from `additionalSetup` are applied after memoization, which results in incorrect cache entry of `Intl.NumberFormat` (e.g. lacking `formatToParts` method). | ||
// To fix this, we need to apply the polyfill manually before memoization. | ||
// For further information, see: https://github.com/Expensify/App/pull/43868#issuecomment-2217637217 | ||
intlPolyfill(); | ||
|
||
const MemoizedNumberFormat = memoize(Intl.NumberFormat, {maxSize: 10}); | ||
|
||
function format(locale: ValueOf<typeof CONST.LOCALES>, number: number, options?: Intl.NumberFormatOptions): string { | ||
return new MemoizedNumberFormat(locale, options).format(number); | ||
} | ||
|
||
function formatToParts(locale: ValueOf<typeof CONST.LOCALES>, number: number, options?: Intl.NumberFormatOptions): Intl.NumberFormatPart[] { | ||
return new MemoizedNumberFormat(locale, options).formatToParts(number); | ||
} | ||
|
||
export {format, formatToParts}; |
5 changes: 1 addition & 4 deletions
5
src/libs/NumberFormatUtils.ts → src/libs/NumberFormatUtils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters