From 7f15f2bad144a53f96a54e846ee04c9f7855330d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 22 Nov 2022 09:47:18 +0100 Subject: [PATCH] Detect Intl.ListFormat availability and add fallback Signed-off-by: Thomas Citharel --- js/src/utils/listFormat.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/src/utils/listFormat.ts b/js/src/utils/listFormat.ts index 47cb2078..c4cb3b50 100644 --- a/js/src/utils/listFormat.ts +++ b/js/src/utils/listFormat.ts @@ -8,10 +8,16 @@ const shortDisjunctionFormatter = new Intl.ListFormat(undefined, { type: "disjunction", }); +const listFormatAvailable = typeof Intl?.ListFormat === "function"; + export const listShortConjunctionFormatter = (list: Array): string => { - return shortConjunctionFormatter.format(list); + return listFormatAvailable + ? shortConjunctionFormatter.format(list) + : list.join(","); }; export const listShortDisjunctionFormatter = (list: Array): string => { - return shortDisjunctionFormatter.format(list); + return listFormatAvailable + ? shortDisjunctionFormatter.format(list) + : list.join(","); };