diff options
| author | Petri Hienonen <petri.hienonen@gmail.com> | 2025-09-28 21:23:14 +0300 |
|---|---|---|
| committer | Petri Hienonen <petri.hienonen@gmail.com> | 2025-09-28 21:23:14 +0300 |
| commit | df83a2861130d4e07b0a720a3452f10cbc4bc84b (patch) | |
| tree | 901b84a33714d7b7057c294e0c1c91399cb6d3bf /static/utils.js | |
| parent | 01fa523251680e9708c0301ee09f83f472f03e06 (diff) | |
| download | network-df83a2861130d4e07b0a720a3452f10cbc4bc84b.tar.zst | |
Complex
Diffstat (limited to 'static/utils.js')
| -rw-r--r-- | static/utils.js | 37 |
1 files changed, 37 insertions, 0 deletions
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 }; |
