Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Audit][Implementation] - Remove Intl Polyfills which are supported by Hermes by separating iOS and android implementation #38565

2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ const CONST = {
CURRENCY: 'XAF',
FORMAT: 'symbol',
SAMPLE_INPUT: '123456.789',
EXPECTED_OUTPUT: 'FCFA 123,457',
EXPECTED_OUTPUT: 'FCFA 123,457',
},

PATHS_TO_TREAT_AS_EXTERNAL: ['NewExpensify.dmg', 'docs/index.html'],
Expand Down
25 changes: 17 additions & 8 deletions src/libs/IntlPolyfill/polyfillNumberFormat.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import CONST from '@src/CONST';

const numberFormat = new Intl.NumberFormat(CONST.LOCALES.DEFAULT, {
style: CONST.POLYFILL_TEST.STYLE,
currency: CONST.POLYFILL_TEST.CURRENCY,
currencyDisplay: CONST.POLYFILL_TEST.FORMAT,
});

/**
* Check if the locale data is as expected on the device.
* Ensures that the currency data is consistent across devices.
*/
function hasOldCurrencyData(): boolean {
return (
new Intl.NumberFormat(CONST.LOCALES.DEFAULT, {
style: CONST.POLYFILL_TEST.STYLE,
currency: CONST.POLYFILL_TEST.CURRENCY,
currencyDisplay: CONST.POLYFILL_TEST.FORMAT,
}).format(Number(CONST.POLYFILL_TEST.SAMPLE_INPUT)) !== CONST.POLYFILL_TEST.EXPECTED_OUTPUT
);
return numberFormat.format(Number(CONST.POLYFILL_TEST.SAMPLE_INPUT)) !== CONST.POLYFILL_TEST.EXPECTED_OUTPUT;
}

/**
* Checks if the formatToParts function is available on the
* Intl.NumberFormat object.
* @returns boolean
hurali97 marked this conversation as resolved.
Show resolved Hide resolved
*/
function hasFormatToParts(): boolean {
return typeof numberFormat.formatToParts === 'function';
}

export default function () {
if (Intl && 'NumberFormat' in Intl && !hasOldCurrencyData()) {
if (Intl && 'NumberFormat' in Intl && !hasOldCurrencyData() && hasFormatToParts()) {
return;
}

Expand Down
Loading