From dc139e01d60b50145d2b6c6ad8a56b2c5809628e Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Sun, 27 Sep 2026 18:21:41 -0500 Subject: [PATCH] consolidate shortening condition strings --- server/scripts/modules/currentweather.mjs | 21 +----------------- server/scripts/modules/latestobservations.mjs | 22 ++----------------- server/scripts/modules/utils/string.mjs | 18 +++++++++++++++ 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/server/scripts/modules/currentweather.mjs b/server/scripts/modules/currentweather.mjs index c49701a..38b492e 100644 --- a/server/scripts/modules/currentweather.mjs +++ b/server/scripts/modules/currentweather.mjs @@ -3,7 +3,7 @@ import STATUS from './status.mjs'; import preloadImg from './utils/preload-image.mjs'; import { safeJson } from './utils/fetch.mjs'; import { directionToNSEW } from './utils/calc.mjs'; -import { locationCleanup } from './utils/string.mjs'; +import { locationCleanup, shortConditions } from './utils/string.mjs'; import largeIcon from './icons/large.mjs'; import WeatherDisplay from './weatherdisplay.mjs'; import { registerDisplay } from './navigation.mjs'; @@ -258,25 +258,6 @@ class CurrentWeather extends WeatherDisplay { } } -const shortConditions = (_condition) => { - let condition = _condition; - condition = condition.replace(/Light/g, 'L'); - condition = condition.replace(/Heavy/g, 'H'); - condition = condition.replace(/Partly/g, 'P'); - condition = condition.replace(/Mostly/g, 'M'); - condition = condition.replace(/Few/g, 'F'); - condition = condition.replace(/Thunderstorm/g, 'T\'storm'); - condition = condition.replace(/ in /g, ''); - condition = condition.replace(/Vicinity/g, ''); - condition = condition.replace(/ and /g, ' '); - condition = condition.replace(/Freezing Rain/g, 'Frz Rn'); - condition = condition.replace(/Freezing/g, 'Frz'); - condition = condition.replace(/Unknown Precip/g, ''); - condition = condition.replace(/L Snow Fog/g, 'L Snw/Fog'); - condition = condition.replace(/ with /g, '/'); - return condition; -}; - // format the received data const parseData = (data) => { // get the unit converter diff --git a/server/scripts/modules/latestobservations.mjs b/server/scripts/modules/latestobservations.mjs index 56e97a3..0662c7e 100644 --- a/server/scripts/modules/latestobservations.mjs +++ b/server/scripts/modules/latestobservations.mjs @@ -2,7 +2,7 @@ import { distance as calcDistance, directionToNSEW } from './utils/calc.mjs'; import { safeJson, safePromiseAll } from './utils/fetch.mjs'; import STATUS from './status.mjs'; -import { locationCleanup } from './utils/string.mjs'; +import { locationCleanup, shortConditions } from './utils/string.mjs'; import { temperature, windSpeed } from './utils/units.mjs'; import WeatherDisplay from './weatherdisplay.mjs'; import { registerDisplay } from './navigation.mjs'; @@ -172,7 +172,7 @@ class LatestObservations extends WeatherDisplay { location: locationCleanup(condition.city).substring(0, locationLimit), temp: Temperature, like: Like.value, - weather: shortenCurrentConditions(condition.textDescription).substring(0, weatherLimit), + weather: shortConditions(condition.textDescription).substring(0, weatherLimit), }; if (WindSpeed > 0) { @@ -235,23 +235,5 @@ const metarFields = [ { name: 'windDirection', check: (orig, metar) => orig.windDirection.value === null && metar.windDirection.value !== null }, ]; -const shortenCurrentConditions = (_condition) => { - let condition = _condition; - condition = condition.replace(/Light/g, 'L'); - condition = condition.replace(/Heavy/g, 'H'); - condition = condition.replace(/Partly/g, 'P'); - condition = condition.replace(/Mostly/g, 'M'); - condition = condition.replace(/Few/g, 'F'); - condition = condition.replace(/Thunderstorm/g, 'T\'storm'); - condition = condition.replace(/ in /g, ''); - condition = condition.replace(/Vicinity/g, ''); - condition = condition.replace(/ and /g, ' '); - condition = condition.replace(/Freezing Rain/g, 'Frz Rn'); - condition = condition.replace(/Freezing/g, 'Frz'); - condition = condition.replace(/Unknown Precip/g, ''); - condition = condition.replace(/L Snow Fog/g, 'L Snw/Fog'); - condition = condition.replace(/ with /g, '/'); - return condition; -}; // register display registerDisplay(new LatestObservations(2, 'latest-observations')); diff --git a/server/scripts/modules/utils/string.mjs b/server/scripts/modules/utils/string.mjs index 2a180c5..286706a 100644 --- a/server/scripts/modules/utils/string.mjs +++ b/server/scripts/modules/utils/string.mjs @@ -30,3 +30,21 @@ export { locationCleanup, stationFilter, }; +export const shortConditions = (_condition) => { + let condition = _condition; + condition = condition.replace(/Light/g, 'L'); + condition = condition.replace(/Heavy/g, 'H'); + condition = condition.replace(/Partly/g, 'P'); + condition = condition.replace(/Mostly/g, 'M'); + condition = condition.replace(/Few/g, 'F'); + condition = condition.replace(/Thunderstorm/g, 'T\'storm'); + condition = condition.replace(/ in /g, ''); + condition = condition.replace(/Vicinity/g, ''); + condition = condition.replace(/ and /g, ' '); + condition = condition.replace(/Freezing Rain/g, 'Frz Rn'); + condition = condition.replace(/Freezing/g, 'Frz'); + condition = condition.replace(/Unknown Precip/g, ''); + condition = condition.replace(/L Snow Fog/g, 'L Snw/Fog'); + condition = condition.replace(/ with /g, '/'); + return condition; +};