inhaus-plugin-gruppen/resources/js/lib/format.js
Friederich Loheide 5bdfb8a082 Gruppen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 17:17:10 +00:00

22 lines
744 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** Text in Stücke zerlegen, Links erkennen – ohne v-html */
export function linkify(text) {
const parts = [];
const pattern = /(https?:\/\/[^\s<>"']+[^\s<>"'.,;:!?)\]])/g;
let last = 0;
for (const match of (text ?? '').matchAll(pattern)) {
if (match.index > last) parts.push({ text: text.slice(last, match.index) });
parts.push({ text: match[0], href: match[0] });
last = match.index + match[0].length;
}
if (last < (text ?? '').length) parts.push({ text: text.slice(last) });
return parts;
}
export function fileSize(bytes) {
if (bytes < 1024 * 1024) return `${Math.max(1, Math.round(bytes / 1024))} KB`;
return `${(bytes / 1024 / 1024).toFixed(1).replace('.', ',')} MB`;
}