V0.1
This commit is contained in:
60
public/js/core/utils.js
Normal file
60
public/js/core/utils.js
Normal file
@@ -0,0 +1,60 @@
|
||||
export function esc(s) {
|
||||
return String(s ?? '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
/** Rufnummer für href="tel:…" (Ziffern, höchstens ein führendes +). */
|
||||
export function telHref(raw) {
|
||||
const t = String(raw ?? '').trim();
|
||||
if (!t) return '';
|
||||
const digitsPlus = t.replace(/[^\d+]/g, '');
|
||||
if (!digitsPlus) return '';
|
||||
const normalized = digitsPlus.startsWith('+')
|
||||
? '+' + digitsPlus.slice(1).replace(/\+/g, '')
|
||||
: digitsPlus.replace(/\+/g, '');
|
||||
return `tel:${normalized}`;
|
||||
}
|
||||
|
||||
export function formatDateTime(iso) {
|
||||
try {
|
||||
return new Date(iso).toLocaleString('de-DE');
|
||||
} catch {
|
||||
return '—';
|
||||
}
|
||||
}
|
||||
|
||||
export function formatDeSyncDateTime(iso) {
|
||||
if (!iso) return '—';
|
||||
try {
|
||||
return new Date(iso).toLocaleString('de-DE', {
|
||||
day: 'numeric',
|
||||
month: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
});
|
||||
} catch {
|
||||
return '—';
|
||||
}
|
||||
}
|
||||
|
||||
export function extrasName(m) {
|
||||
const x = m?.extras;
|
||||
if (!x || typeof x !== 'object') return '';
|
||||
return String(x.Name || '').trim();
|
||||
}
|
||||
|
||||
/** Anzeige Dauer aus gespeicherten Sekunden (TeamViewer start/end). */
|
||||
export function formatRemoteDurationDe(totalSec) {
|
||||
if (totalSec == null || totalSec < 0) return '';
|
||||
const n = Math.floor(Number(totalSec));
|
||||
const m = Math.floor(n / 60);
|
||||
const s = n % 60;
|
||||
if (m === 0) return `${s} Sek.`;
|
||||
if (s === 0) return `${m} Min.`;
|
||||
return `${m} Min. ${s} Sek.`;
|
||||
}
|
||||
Reference in New Issue
Block a user