59 lines
1.5 KiB
JavaScript
Vendored
59 lines
1.5 KiB
JavaScript
Vendored
export function fullName(user) {
|
|
if (!user) return '';
|
|
if (user.full_name) {
|
|
return String(user.full_name).trim();
|
|
}
|
|
const parts = [user.surname, user.first_name, user.last_name].filter(Boolean);
|
|
const name = parts.join(' ').trim();
|
|
if (name) return name;
|
|
if (user.username) return user.username;
|
|
if (user.email) return user.email;
|
|
return '';
|
|
}
|
|
|
|
export function displayName(user, youLabel = 'You') {
|
|
if (!user) return '';
|
|
return fullName(user) || youLabel;
|
|
}
|
|
|
|
export function initials(name) {
|
|
const parts = (name || '?').trim().split(/\s+/);
|
|
return (parts[0]?.[0] || '?') + (parts[1]?.[0] || '');
|
|
}
|
|
|
|
export function escapeHtml(value) {
|
|
const div = document.createElement('div');
|
|
div.textContent = value || '';
|
|
return div.innerHTML;
|
|
}
|
|
|
|
export function formatTime(iso) {
|
|
if (!iso) return '';
|
|
if (window.CommDate?.formatTime) {
|
|
return window.CommDate.formatTime(iso);
|
|
}
|
|
try {
|
|
return new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit' }).format(new Date(iso));
|
|
} catch {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
export function formatDateTime(iso) {
|
|
if (!iso) return '-';
|
|
if (window.CommDate?.formatDateTime) {
|
|
return window.CommDate.formatDateTime(iso);
|
|
}
|
|
try {
|
|
return new Intl.DateTimeFormat(undefined, {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
}).format(new Date(iso));
|
|
} catch {
|
|
return '-';
|
|
}
|
|
}
|