planet-webapp
planet-webapp copied to clipboard
Implement an alternative for Intl.NumberFormat(...).formatToParts
Describe the feature you'd like to see included in Plant-for-the-Planet Web App.
Currently Intl.NumberFormat(...).formatToParts
is used at
- https://github.com/Plant-for-the-Planet-org/planet-webapp/blob/c2a0a6a004976d13327e796c898d3da7f1b49a9a/src/utils/stripe/stripeHelpers.tsx#L21-L46 to find out if the currency support decimals (e.g. JPY does not and currently fails, compare #696). Just omitting this check and returning a formatted number like for EUR or USD would probably result into charging our customers with e.g. JPY x100 more money than expected! So before doing this we would need to make an backend adaption to be able to add a special treatment for currencies like JPY.
- https://github.com/Plant-for-the-Planet-org/planet-webapp/blob/c2a0a6a004976d13327e796c898d3da7f1b49a9a/src/utils/getFormattedNumber.ts#L1-L19 to parse numbers in all kind of languages. There is no replacement for that currently available, just using different regex for parsing numbers manually for all of our supported languages.
Until now I have found no polyfill for Intl.NumberFormat(...).formatToParts
.
What are the use cases for this feature?
The usage of Intl.NumberFormat(...).formatToParts
does not allow to support older browser than Safari 13 or Samsung 9 - see https://caniuse.com/?search=Intl.NumberFormat().%20formatToParts or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts