Skip to content

Commit

Permalink
Merge pull request #28306 from kubabutkiewicz/ts-migration/IntlPolyfi…
Browse files Browse the repository at this point in the history
…ll-lib

[No QA] [TS migration] Migrate 'IntlPolyfill' lib to TypeScript
  • Loading branch information
Li357 authored Oct 6, 2023
2 parents 3e4731d + 7f0121f commit edea48c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import polyfillNumberFormat from './polyfillNumberFormat';
import polyfillListFormat from './polyfillListFormat';
import IntlPolyfill from './types';

/**
* Polyfill the Intl API, always performed for native devices.
*/
export default function polyfill() {
const intlPolyfill: IntlPolyfill = () => {
// Native devices require extra polyfills
require('@formatjs/intl-getcanonicallocales/polyfill');
require('@formatjs/intl-locale/polyfill');
require('@formatjs/intl-pluralrules/polyfill');
require('@formatjs/intl-datetimeformat');
polyfillNumberFormat();
polyfillListFormat();
}
};

export default intlPolyfill;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import polyfillNumberFormat from './polyfillNumberFormat';
import IntlPolyfill from './types';

/**
* Polyfill the Intl API if the ICU version is old.
* This ensures that the currency data is consistent across platforms and browsers.
*/
export default function intlPolyfill() {
const intlPolyfill: IntlPolyfill = () => {
// Just need to polyfill Intl.NumberFormat for web based platforms
polyfillNumberFormat();
require('@formatjs/intl-datetimeformat');
}
};
export default intlPolyfill;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import CONST from '../../CONST';
/**
* Check if the locale data is as expected on the device.
* Ensures that the currency data is consistent across devices.
* @returns {Boolean}
*/
function hasOldCurrencyData() {
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(CONST.POLYFILL_TEST.SAMPLE_INPUT) !== CONST.POLYFILL_TEST.EXPECTED_OUTPUT
}).format(Number(CONST.POLYFILL_TEST.SAMPLE_INPUT)) !== CONST.POLYFILL_TEST.EXPECTED_OUTPUT
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/libs/IntlPolyfill/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type IntlPolyfill = () => void;

export default IntlPolyfill;

0 comments on commit edea48c

Please sign in to comment.