Skip to content

Commit

Permalink
Remove spurious feature tests for Intl
Browse files Browse the repository at this point in the history
  • Loading branch information
steverep committed May 28, 2024
1 parent 362015f commit ce09949
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
13 changes: 6 additions & 7 deletions src/common/language/format_language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export const formatLanguageCode = (
}
};

const formatLanguageCodeMem = memoizeOne((locale: FrontendLocaleData) =>
Intl && "DisplayNames" in Intl
? new Intl.DisplayNames(locale.language, {
type: "language",
fallback: "code",
})
: undefined
const formatLanguageCodeMem = memoizeOne(
(locale: FrontendLocaleData) =>
new Intl.DisplayNames(locale.language, {
type: "language",
fallback: "code",
})
);
6 changes: 2 additions & 4 deletions src/common/number/format_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export const formatNumber = (

if (
localeOptions?.number_format !== NumberFormat.none &&
!Number.isNaN(Number(num)) &&
Intl
!Number.isNaN(Number(num))
) {
try {
return new Intl.NumberFormat(
Expand All @@ -85,8 +84,7 @@ export const formatNumber = (
if (
!Number.isNaN(Number(num)) &&
num !== "" &&
localeOptions?.number_format === NumberFormat.none &&
Intl
localeOptions?.number_format === NumberFormat.none
) {
// If NumberFormat is none, use en-US format without grouping.
return new Intl.NumberFormat(
Expand Down
12 changes: 4 additions & 8 deletions src/components/ha-country-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,10 @@ export class HaCountryPicker extends LitElement {
private _getOptions = memoizeOne(
(language?: string, countries?: string[]) => {
let options: { label: string; value: string }[] = [];
const countryDisplayNames =
Intl && "DisplayNames" in Intl
? new Intl.DisplayNames(language, {
type: "region",
fallback: "code",
})
: undefined;

const countryDisplayNames = new Intl.DisplayNames(language, {
type: "region",
fallback: "code",
});
if (countries) {
options = countries.map((country) => ({
value: country,
Expand Down
20 changes: 7 additions & 13 deletions src/components/ha-currency-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,9 @@ const CURRENCIES = [
];

const curSymbol = (currency: string, locale?: string) =>
Intl && "NumberFormat" in Intl
? new Intl.NumberFormat(locale, { style: "currency", currency })
.formatToParts(1)
.find((x) => x.type === "currency")?.value
: currency;

new Intl.NumberFormat(locale, { style: "currency", currency })
.formatToParts(1)
.find((x) => x.type === "currency")?.value;
@customElement("ha-currency-picker")
export class HaCurrencyPicker extends LitElement {
@property() public language = "en";
Expand All @@ -188,13 +185,10 @@ export class HaCurrencyPicker extends LitElement {
@property({ type: Boolean, reflect: true }) public disabled = false;

private _getOptions = memoizeOne((language?: string) => {
const currencyDisplayNames =
Intl && "DisplayNames" in Intl
? new Intl.DisplayNames(language, {
type: "currency",
fallback: "code",
})
: undefined;
const currencyDisplayNames = new Intl.DisplayNames(language, {
type: "currency",
fallback: "code",
});
const options = CURRENCIES.map((currency) => ({
value: currency,
label: `${
Expand Down

0 comments on commit ce09949

Please sign in to comment.