summaryrefslogtreecommitdiff
path: root/web/js/utils.js
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-07 00:23:45 +0300
committerPaul Buetow <paul@buetow.org>2026-05-07 00:23:45 +0300
commita0603095a35473a6479beb612bc2ed7b33298260 (patch)
treea4fe50996e1007f74290ff8cb922dc1daa7b77b0 /web/js/utils.js
parentd87bcee585883f22b2ca0b42db67bf815cc7c1fc (diff)
Task 61 extract frontend utilities
Diffstat (limited to 'web/js/utils.js')
-rw-r--r--web/js/utils.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/web/js/utils.js b/web/js/utils.js
new file mode 100644
index 0000000..2851211
--- /dev/null
+++ b/web/js/utils.js
@@ -0,0 +1,21 @@
+export function fmtDur(s) {
+ if (!s || s < 0) return '0:00';
+ const h = Math.floor(s / 3600);
+ const m = Math.floor((s % 3600) / 60);
+ const sec = Math.floor(s % 60);
+ const mm = String(m).padStart(2, '0');
+ const ss = String(sec).padStart(2, '0');
+ return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
+}
+
+export function escapeHtml(s) {
+ return (s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
+}
+
+export function toast(msg, type = 'info') {
+ const t = document.getElementById('toast');
+ if (!t) return;
+ t.textContent = msg;
+ t.className = 'toast show ' + type;
+ setTimeout(() => t.classList.remove('show'), 2800);
+}