Detect Intl.ListFormat availability and add fallback
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
f9d21c5a38
commit
7f15f2bad1
@ -8,10 +8,16 @@ const shortDisjunctionFormatter = new Intl.ListFormat(undefined, {
|
|||||||
type: "disjunction",
|
type: "disjunction",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const listFormatAvailable = typeof Intl?.ListFormat === "function";
|
||||||
|
|
||||||
export const listShortConjunctionFormatter = (list: Array<string>): string => {
|
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 => {
|
export const listShortDisjunctionFormatter = (list: Array<string>): string => {
|
||||||
return shortDisjunctionFormatter.format(list);
|
return listFormatAvailable
|
||||||
|
? shortDisjunctionFormatter.format(list)
|
||||||
|
: list.join(",");
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user