Detect Intl.ListFormat availability and add fallback

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-11-22 09:47:18 +01:00
parent f9d21c5a38
commit 7f15f2bad1
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -8,10 +8,16 @@ const shortDisjunctionFormatter = new Intl.ListFormat(undefined, {
type: "disjunction",
});
const listFormatAvailable = typeof Intl?.ListFormat === "function";
export const listShortConjunctionFormatter = (list: Array<string>): string => {
return shortConjunctionFormatter.format(list);
return listFormatAvailable
? shortConjunctionFormatter.format(list)
: list.join(",");
};
export const listShortDisjunctionFormatter = (list: Array<string>): string => {
return shortDisjunctionFormatter.format(list);
return listFormatAvailable
? shortDisjunctionFormatter.format(list)
: list.join(",");
};