Compare commits

...

4 Commits

Author SHA1 Message Date
Darius
7beb867bd5 1.0.6 2025-11-17 23:52:19 +01:00
Darius
d11d6bf5b1 Generic Commit; Most likely a fix or small feature 2025-11-17 23:52:14 +01:00
Darius
cfb45a03a2 1.0.5 2025-11-17 23:49:52 +01:00
Darius
49bb137388 Generic Commit; Most likely a fix or small feature 2025-11-17 23:49:48 +01:00
9 changed files with 47 additions and 46 deletions

1
dist/index.d.ts vendored
View File

@@ -1,5 +1,6 @@
export * from "./homeassistant"; export * from "./homeassistant";
export * as Logger from "./logger"; export * as Logger from "./logger";
export * from "./tidal"; export * from "./tidal";
export * as TimeSpan from "./timespan";
export * as Utility from "./utility"; export * as Utility from "./utility";
//# sourceMappingURL=index.d.ts.map //# sourceMappingURL=index.d.ts.map

2
dist/index.d.ts.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC"} {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC"}

3
dist/index.js vendored
View File

@@ -36,8 +36,9 @@ var __importStar = (this && this.__importStar) || (function () {
}; };
})(); })();
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.Utility = exports.Logger = void 0; exports.Utility = exports.TimeSpan = exports.Logger = void 0;
__exportStar(require("./homeassistant"), exports); __exportStar(require("./homeassistant"), exports);
exports.Logger = __importStar(require("./logger")); exports.Logger = __importStar(require("./logger"));
__exportStar(require("./tidal"), exports); __exportStar(require("./tidal"), exports);
exports.TimeSpan = __importStar(require("./timespan"));
exports.Utility = __importStar(require("./utility")); exports.Utility = __importStar(require("./utility"));

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@dpu/shared", "name": "@dpu/shared",
"version": "1.0.4", "version": "1.0.6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@dpu/shared", "name": "@dpu/shared",
"version": "1.0.4", "version": "1.0.6",
"dependencies": { "dependencies": {
"axios": "^1.7.9", "axios": "^1.7.9",
"chalk": "^5.6.2" "chalk": "^5.6.2"

View File

@@ -1,6 +1,6 @@
{ {
"name": "@dpu/shared", "name": "@dpu/shared",
"version": "1.0.4", "version": "1.0.6",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@@ -1,4 +1,4 @@
export * from "./homeassistant"; export * from "./homeassistant";
export * as Logger from "./logger"; export * as Logger from "./logger";
export * from "./tidal"; export * from "./tidal";
export * as Utility from "./utility"; export * as TimeHelper from "./timehelper";

View File

@@ -1,3 +1,4 @@
import axios from "axios";
import chalk from "chalk"; import chalk from "chalk";
export function logError(...args: unknown[]) { export function logError(...args: unknown[]) {
@@ -15,3 +16,17 @@ export function logSuccess(...args: unknown[]) {
export function logInfo(...args: unknown[]) { export function logInfo(...args: unknown[]) {
console.info(chalk.cyan("INFO:"), ...args); 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);
}
}

View File

@@ -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*$/,
"",
);
}

View File

@@ -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);
}
}