@oxyhq/services
Version:
53 lines (49 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getShortDisplayName = exports.getDisplayName = exports.formatDate = void 0;
/**
* User display name and date formatting utilities
*/
/**
* Formats a date string to a readable format (e.g., "Feb 21, 2025")
*/
const formatDate = dateString => {
if (!dateString) return '';
try {
const date = dateString instanceof Date ? dateString : new Date(dateString);
if (isNaN(date.getTime())) return '';
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric'
});
} catch {
return '';
}
};
/**
* Gets a display name from user data
*/
exports.formatDate = formatDate;
const getDisplayName = user => {
if (!user) return 'User';
const fullName = user.name?.full;
if (fullName) return fullName;
const firstLast = [user.name?.first, user.name?.last].filter(Boolean).join(' ').trim();
if (firstLast) return firstLast;
return user.username || 'User';
};
/**
* Gets a short display name (first name or username)
*/
exports.getDisplayName = getDisplayName;
const getShortDisplayName = user => {
if (!user) return 'User';
const firstName = user.name?.first || user.name?.full?.split(' ')[0];
if (firstName) return firstName;
return user.username || 'User';
};
exports.getShortDisplayName = getShortDisplayName;
//# sourceMappingURL=userUtils.js.map