~timharek/d-yr

ceaba239305287d9917c1d7f3caa0313cde408ab — Tim Hårek Andreassen 6 months ago f135dbc
feat: Add conditional for showing details if they are equal to 0

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
1 files changed, 12 insertions(+), 3 deletions(-)

M src/cli_messages.ts
M src/cli_messages.ts => src/cli_messages.ts +12 -3
@@ 10,9 10,18 @@ import { WeatherSymbols } from './weather_symbols.ts';
import { Forecast, TimeseriesMinified } from './yr.ts';

function parseWeather(input: TimeseriesMinified): string {
  return `${
    WeatherSymbols[input.symbol]
  }   ${input.temperature} with ${input.wind_speed} wind and ${input.rain} rain.`;
  const details = [];

  if (parseFloat(input.wind_speed) > 0) {
    details.push(`${input.wind_speed} wind`);
  }
  if (parseFloat(input.rain) > 0) {
    details.push(`${input.rain} rain`);
  }

  return `${WeatherSymbols[input.symbol]}   ${input.temperature} with ${
    details.join(', ')
  }.`;
}

function messageHeader(heading: string): string {