diff --git a/src/routes/economic-calendar/workers/filterWorker.ts b/src/routes/economic-calendar/workers/filterWorker.ts index 0efb135b..2c27b711 100644 --- a/src/routes/economic-calendar/workers/filterWorker.ts +++ b/src/routes/economic-calendar/workers/filterWorker.ts @@ -1,44 +1,44 @@ export const listOfRelevantCountries = [ - { USA: "United States" }, - { CHN: "China" }, - { CAN: "Canada" }, - { GBR: "United Kingdom" }, - { JPN: "Japan" }, - { ISR: "Israel" }, - { BRA: "Brazil" }, - { FRA: "France" }, - { IRL: "Ireland" }, - { DEU: "Germany" }, - { MEX: "Mexico" }, - { IND: "India" }, - { AUS: "Australia" }, - { KOR: "South Korea" }, - { SWE: "Sweden" }, - { NLD: "Netherlands" }, - { CHE: "Switzerland" }, - { TWN: "Taiwan" }, - { ZAF: "South Africa" }, - { HKG: "Hong Kong" }, - { SGP: "Singapore" }, - { ARG: "Argentina" }, - { CHL: "Chile" }, - { PHL: "Philippines" }, - { TUR: "Turkey" }, - { ITA: "Italy" }, - { IDN: "Indonesia" }, - { MYS: "Malaysia" }, - { LUX: "Luxembourg" }, - { VNM: "Vietnam" }, - { NZL: "New Zealand" }, - { DNK: "Denmark" }, - { NOR: "Norway" }, - { FIN: "Finland" }, - { RUS: "Russia" }, - { ARE: "United Arab Emirates" }, +{ US: "United States" }, +{ CN: "China" }, +{ CA: "Canada" }, +{ GB: "United Kingdom" }, +{ JP: "Japan" }, +{ IL: "Israel" }, +{ BR: "Brazil" }, +{ FR: "France" }, +{ IE: "Ireland" }, +{ DE: "Germany" }, +{ MX: "Mexico" }, +{ IN: "India" }, +{ AU: "Australia" }, +{ KR: "South Korea" }, +{ SE: "Sweden" }, +{ NL: "Netherlands" }, +{ CH: "Switzerland" }, +{ TW: "Taiwan" }, +{ ZA: "South Africa" }, +{ HK: "Hong Kong" }, +{ SG: "Singapore" }, +{ AR: "Argentina" }, +{ CL: "Chile" }, +{ PH: "Philippines" }, +{ TR: "Turkey" }, +{ IT: "Italy" }, +{ ID: "Indonesia" }, +{ MY: "Malaysia" }, +{ LU: "Luxembourg" }, +{ VN: "Vietnam" }, +{ NZ: "New Zealand" }, +{ DK: "Denmark" }, +{ NO: "Norway" }, +{ FI: "Finland" }, +{ RU: "Russia" }, +{ AE: "United Arab Emirates" }, ]; const countryMap = Object.fromEntries( - listOfRelevantCountries.map((entry) => { + listOfRelevantCountries?.map((entry) => { const [code, name] = Object.entries(entry)[0]; return [name, code]; }) @@ -50,14 +50,14 @@ onmessage = async (event: MessageEvent) => { // Separate importance filters and country filters const importanceFilters = filterList.filter( - (item) => typeof item === "number" && [1, 2, 3].includes(item as number) + (item) => typeof item === "number" && [1, 2, 3]?.includes(item as number) ) as number[]; - const countryFilters = filterList.filter( + const countryFilters = filterList?.filter( (item) => typeof item === "string" ) as string[]; // Map filterList country names to abbreviations - const filterCodes = countryFilters.map((name) => countryMap[name]) || []; + const filterCodes = countryFilters?.map((name) => countryMap[name]) || []; // Filter rawData based on the mapped country codes and importance const output = rawData?.map((subArray) => @@ -65,8 +65,8 @@ onmessage = async (event: MessageEvent) => { const countryMatch = filterCodes.length === 0 || filterCodes.includes(item?.country); const importanceMatch = - importanceFilters.length === 0 || - importanceFilters.includes(item?.importance); + importanceFilters?.length === 0 || + importanceFilters?.includes(item?.importance); return countryMatch && importanceMatch; }) );