mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-17 01:19:40 +02:00
style: auto-format codebase with Prettier
Applied formatting to 1487+ files using pnpm format:write - TypeScript/JavaScript files - Svelte components - Astro pages - JSON configs - Markdown docs 13 files still need manual review (Astro JSX comments)
This commit is contained in:
parent
0241f5554c
commit
d36b321d9d
3952 changed files with 661498 additions and 739751 deletions
|
|
@ -6,149 +6,138 @@
|
|||
* Format duration from seconds to MM:SS or HH:MM:SS format
|
||||
*/
|
||||
export function formatDuration(seconds: number): string {
|
||||
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||
return '--:--';
|
||||
}
|
||||
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||
return '--:--';
|
||||
}
|
||||
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}:${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours}:${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format duration from milliseconds
|
||||
*/
|
||||
export function formatDurationFromMs(milliseconds: number): string {
|
||||
return formatDuration(milliseconds / 1000);
|
||||
return formatDuration(milliseconds / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format duration with units (e.g., "2 min 30 sec" or "1h 23m")
|
||||
*/
|
||||
export function formatDurationWithUnits(
|
||||
seconds: number,
|
||||
locale: 'en' | 'de' = 'en'
|
||||
): string {
|
||||
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||
return locale === 'de' ? 'keine Zeit' : 'no time';
|
||||
}
|
||||
export function formatDurationWithUnits(seconds: number, locale: 'en' | 'de' = 'en'): string {
|
||||
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||
return locale === 'de' ? 'keine Zeit' : 'no time';
|
||||
}
|
||||
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
|
||||
if (hours > 0) {
|
||||
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
||||
}
|
||||
|
||||
if (minutes > 0) {
|
||||
return remainingSeconds > 0 && minutes < 5
|
||||
? `${minutes}m ${remainingSeconds}s`
|
||||
: `${minutes}m`;
|
||||
}
|
||||
if (minutes > 0) {
|
||||
return remainingSeconds > 0 && minutes < 5 ? `${minutes}m ${remainingSeconds}s` : `${minutes}m`;
|
||||
}
|
||||
|
||||
return `${remainingSeconds}s`;
|
||||
return `${remainingSeconds}s`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format duration to human readable text
|
||||
*/
|
||||
export function formatDurationHumanReadable(
|
||||
seconds: number,
|
||||
locale: 'en' | 'de' = 'de'
|
||||
): string {
|
||||
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||
return locale === 'de' ? 'keine Zeit' : 'no time';
|
||||
}
|
||||
export function formatDurationHumanReadable(seconds: number, locale: 'en' | 'de' = 'de'): string {
|
||||
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||
return locale === 'de' ? 'keine Zeit' : 'no time';
|
||||
}
|
||||
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
|
||||
const parts: string[] = [];
|
||||
const parts: string[] = [];
|
||||
|
||||
if (locale === 'de') {
|
||||
if (hours > 0) {
|
||||
parts.push(`${hours} ${hours === 1 ? 'Stunde' : 'Stunden'}`);
|
||||
}
|
||||
if (minutes > 0) {
|
||||
parts.push(`${minutes} ${minutes === 1 ? 'Minute' : 'Minuten'}`);
|
||||
}
|
||||
if (remainingSeconds > 0 && hours === 0) {
|
||||
parts.push(`${remainingSeconds} ${remainingSeconds === 1 ? 'Sekunde' : 'Sekunden'}`);
|
||||
}
|
||||
return parts.length === 0 ? '0 Sekunden' : parts.join(' ');
|
||||
} else {
|
||||
if (hours > 0) {
|
||||
parts.push(`${hours} ${hours === 1 ? 'hour' : 'hours'}`);
|
||||
}
|
||||
if (minutes > 0) {
|
||||
parts.push(`${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`);
|
||||
}
|
||||
if (remainingSeconds > 0 && hours === 0) {
|
||||
parts.push(`${remainingSeconds} ${remainingSeconds === 1 ? 'second' : 'seconds'}`);
|
||||
}
|
||||
return parts.length === 0 ? '0 seconds' : parts.join(' ');
|
||||
}
|
||||
if (locale === 'de') {
|
||||
if (hours > 0) {
|
||||
parts.push(`${hours} ${hours === 1 ? 'Stunde' : 'Stunden'}`);
|
||||
}
|
||||
if (minutes > 0) {
|
||||
parts.push(`${minutes} ${minutes === 1 ? 'Minute' : 'Minuten'}`);
|
||||
}
|
||||
if (remainingSeconds > 0 && hours === 0) {
|
||||
parts.push(`${remainingSeconds} ${remainingSeconds === 1 ? 'Sekunde' : 'Sekunden'}`);
|
||||
}
|
||||
return parts.length === 0 ? '0 Sekunden' : parts.join(' ');
|
||||
} else {
|
||||
if (hours > 0) {
|
||||
parts.push(`${hours} ${hours === 1 ? 'hour' : 'hours'}`);
|
||||
}
|
||||
if (minutes > 0) {
|
||||
parts.push(`${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`);
|
||||
}
|
||||
if (remainingSeconds > 0 && hours === 0) {
|
||||
parts.push(`${remainingSeconds} ${remainingSeconds === 1 ? 'second' : 'seconds'}`);
|
||||
}
|
||||
return parts.length === 0 ? '0 seconds' : parts.join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format file size from bytes to human readable string
|
||||
*/
|
||||
export function formatFileSize(bytes: number, decimals: number = 1): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
if (!Number.isFinite(bytes) || bytes < 0) return '--';
|
||||
if (bytes === 0) return '0 B';
|
||||
if (!Number.isFinite(bytes) || bytes < 0) return '--';
|
||||
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format number with thousands separator
|
||||
*/
|
||||
export function formatNumber(
|
||||
num: number,
|
||||
locale: string = 'de-DE'
|
||||
): string {
|
||||
return num.toLocaleString(locale);
|
||||
export function formatNumber(num: number, locale: string = 'de-DE'): string {
|
||||
return num.toLocaleString(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format currency
|
||||
*/
|
||||
export function formatCurrency(
|
||||
amount: number,
|
||||
currency: string = 'EUR',
|
||||
locale: string = 'de-DE'
|
||||
amount: number,
|
||||
currency: string = 'EUR',
|
||||
locale: string = 'de-DE'
|
||||
): string {
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
}).format(amount);
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
}).format(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format percentage
|
||||
*/
|
||||
export function formatPercent(
|
||||
value: number,
|
||||
decimals: number = 0,
|
||||
locale: string = 'de-DE'
|
||||
value: number,
|
||||
decimals: number = 0,
|
||||
locale: string = 'de-DE'
|
||||
): string {
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'percent',
|
||||
minimumFractionDigits: decimals,
|
||||
maximumFractionDigits: decimals,
|
||||
}).format(value);
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'percent',
|
||||
minimumFractionDigits: decimals,
|
||||
maximumFractionDigits: decimals,
|
||||
}).format(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,15 +153,15 @@ export const formatDurationCompact = formatDuration;
|
|||
* @returns Duration in seconds
|
||||
*/
|
||||
export function parseDuration(duration: string): number {
|
||||
const parts = duration.split(':').map(Number);
|
||||
const parts = duration.split(':').map(Number);
|
||||
|
||||
if (parts.length === 3) {
|
||||
// Hours:Minutes:Seconds
|
||||
return parts[0] * 3600 + parts[1] * 60 + parts[2];
|
||||
} else if (parts.length === 2) {
|
||||
// Minutes:Seconds
|
||||
return parts[0] * 60 + parts[1];
|
||||
}
|
||||
if (parts.length === 3) {
|
||||
// Hours:Minutes:Seconds
|
||||
return parts[0] * 3600 + parts[1] * 60 + parts[2];
|
||||
} else if (parts.length === 2) {
|
||||
// Minutes:Seconds
|
||||
return parts[0] * 60 + parts[1];
|
||||
}
|
||||
|
||||
return parts[0] || 0;
|
||||
return parts[0] || 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue