From d11d6bf5b18beaf7b4c96d0876c7e8fa9b32eede Mon Sep 17 00:00:00 2001 From: Darius Date: Mon, 17 Nov 2025 23:52:14 +0100 Subject: [PATCH] Generic Commit; Most likely a fix or small feature --- src/index.ts | 3 +-- src/logger.ts | 15 +++++++++++ src/{timespan.ts => timehelper.ts} | 24 ++++++++++++++++++ src/utility.ts | 40 ------------------------------ 4 files changed, 40 insertions(+), 42 deletions(-) rename src/{timespan.ts => timehelper.ts} (53%) delete mode 100644 src/utility.ts diff --git a/src/index.ts b/src/index.ts index 4ac3db9..7dbedd5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ export * from "./homeassistant"; export * as Logger from "./logger"; export * from "./tidal"; -export * as TimeSpan from "./timespan"; -export * as Utility from "./utility"; +export * as TimeHelper from "./timehelper"; diff --git a/src/logger.ts b/src/logger.ts index 37cf466..f873c08 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,3 +1,4 @@ +import axios from "axios"; import chalk from "chalk"; export function logError(...args: unknown[]) { @@ -15,3 +16,17 @@ export function logSuccess(...args: unknown[]) { export function logInfo(...args: unknown[]) { console.info(chalk.cyan("INFO:"), ...args); } + +export function printNetworkError(error: unknown) { + if (axios.isAxiosError(error)) { + logError("Axios error details:", { + message: error.message, + status: error.response?.status, + statusText: error.response?.statusText, + data: error.response?.data, + url: error.config?.url, + }); + } else { + logError("Unexpected error:", error); + } +} diff --git a/src/timespan.ts b/src/timehelper.ts similarity index 53% rename from src/timespan.ts rename to src/timehelper.ts index be4515e..e84c8d6 100644 --- a/src/timespan.ts +++ b/src/timehelper.ts @@ -30,3 +30,27 @@ export class TimeSpan { } } } + +export function secondsToReadable( + secs: number, + roundToMinutes: boolean = false, +): string { + const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs; + + var days = Math.floor(totalSeconds / (3600 * 24)); + var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600); + var minutes = Math.floor((totalSeconds % 3600) / 60); + var seconds = Math.floor(totalSeconds % 60); + + var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : ""; + var hourDisplay = + hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : ""; + var minuteDisplay = + minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : ""; + var secondDisplay = + seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : ""; + return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace( + /,\s*$/, + "", + ); +} diff --git a/src/utility.ts b/src/utility.ts deleted file mode 100644 index 5a18086..0000000 --- a/src/utility.ts +++ /dev/null @@ -1,40 +0,0 @@ -import axios from "axios"; -import { logError } from "./logger"; - -export function secondsToReadable( - secs: number, - roundToMinutes: boolean = false, -): string { - const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs; - - var days = Math.floor(totalSeconds / (3600 * 24)); - var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600); - var minutes = Math.floor((totalSeconds % 3600) / 60); - var seconds = Math.floor(totalSeconds % 60); - - var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : ""; - var hourDisplay = - hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : ""; - var minuteDisplay = - minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : ""; - var secondDisplay = - seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : ""; - return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace( - /,\s*$/, - "", - ); -} - -export function printNetworkError(error: unknown) { - if (axios.isAxiosError(error)) { - logError("Axios error details:", { - message: error.message, - status: error.response?.status, - statusText: error.response?.statusText, - data: error.response?.data, - url: error.config?.url, - }); - } else { - logError("Unexpected error:", error); - } -}