Files
AI/crawler_platform/app/web/frontend/src/legacy/utils.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-05-12 19:40:31 +09:00
import { t } from "./i18n.js";
export const $ = (id) => document.getElementById(id);
export function csv(value) {
return String(value || "").split(",").map((item) => item.trim()).filter(Boolean);
}
export function escapeHtml(value) {
return String(value ?? "")
.replaceAll("&", "&")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#039;");
}
export function chip(value) {
return `<span class="chip">${escapeHtml(value)}</span>`;
}
export function table(headers, rows) {
if (!rows.length) {
return `<table><tbody><tr><td>${escapeHtml(t("table.no_data"))}</td></tr></tbody></table>`;
}
return `
<table>
<thead><tr>${headers.map((header) => `<th>${escapeHtml(header)}</th>`).join("")}</tr></thead>
<tbody>${rows.map((row) => `<tr>${row.map((cell) => `<td>${String(cell ?? "")}</td>`).join("")}</tr>`).join("")}</tbody>
</table>
`;
}
let toastTimer = null;
export function toast(message) {
const node = document.getElementById("toast");
if (!node) return;
node.textContent = message;
node.classList.add("show");
if (toastTimer) window.clearTimeout(toastTimer);
toastTimer = window.setTimeout(() => node.classList.remove("show"), 2400);
}