From df83a2861130d4e07b0a720a3452f10cbc4bc84b Mon Sep 17 00:00:00 2001 From: Petri Hienonen Date: Sun, 28 Sep 2025 21:23:14 +0300 Subject: Complex --- static/utils.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'static/utils.js') diff --git a/static/utils.js b/static/utils.js index 32b10be..931653f 100644 --- a/static/utils.js +++ b/static/utils.js @@ -168,6 +168,43 @@ class Utils { timeout = setTimeout(later, wait); }; } + /** + * Safely convert any value to display string + * @static + * @param {*} value - Any value + * @returns {string} Safe display string + */ + static safeToString(value) { + if (value === null || value === undefined) return ""; + if (typeof value === "string") return value; + if (typeof value === "number" || typeof value === "boolean") + return String(value); + if (Array.isArray(value)) { + return value.map((item) => Utils.safeToString(item)).join(", "); + } + if (typeof value === "object") { + // Handle IP address objects + if (value.Address && Array.isArray(value.Address)) { + return Utils.ipFromArray(value); + } + // Try to stringify simple objects + try { + const simpleObj = {}; + for (const [key, val] of Object.entries(value)) { + if (val !== null && val !== undefined && typeof val !== "object") { + simpleObj[key] = val; + } + } + if (Object.keys(simpleObj).length > 0) { + return JSON.stringify(simpleObj); + } + } catch (e) { + // Fall through + } + return String(value); + } + return String(value); + } } export { Utils }; -- cgit v1.2.3-70-g09d2