mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-11-28 18:28:04 -08:00
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
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));
|
|
|
|
// make text safe to place in innerHTML, used for text that comes from the url or the user
|
|
const escapeHtml = (text) => text
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll('\'', ''');
|
|
|
|
export {
|
|
escapeHtml,
|
|
locationCleanup,
|
|
stationFilter,
|
|
};
|