Files
WeatherStar4000/server/scripts/modules/utils/string.mjs
2026-04-08 09:57:18 -05:00

25 lines
808 B
JavaScript

const locationCleanup = (input) => {
// regexes to run
const regexes = [
// "Chicago / West Chicago", removes before slash
/^[ A-Za-z]+ \/ /,
// "Chicago/Waukegan" removes before slash
/^[ A-Za-z]+\//,
// "Chicago, Chicago O'hare" removes before comma
/^[ A-Za-z]+, /,
];
// run all regexes
return regexes.reduce((value, regex) => value.replace(regex, ''), input);
};
// stations must be 4 alpha characters and not start with the provided list
const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J'];
const stationFilter = (station) => station.properties.stationIdentifier.match(/^[A-Z]{4}$/) && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1));
export {
locationCleanup,
stationFilter,
};