36 lines
1008 B
TypeScript
36 lines
1008 B
TypeScript
export function formatDuration(seconds: number): string {
|
|
const total = Math.max(0, Math.floor(seconds))
|
|
const minutes = Math.floor(total / 60)
|
|
const remainingSeconds = total % 60
|
|
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
|
|
}
|
|
|
|
export function formatRemainingDuration(current: number, total: number): string {
|
|
const remaining = Math.max(0, Math.floor(total) - Math.floor(current))
|
|
return `-${formatDuration(remaining)}`
|
|
}
|
|
|
|
export function sumDurationSeconds(durations: number[]): number {
|
|
return durations.reduce((sum, value) => sum + value, 0)
|
|
}
|
|
|
|
export function formatMetadata(
|
|
genre: string | null,
|
|
year: number | null
|
|
): string | null {
|
|
const parts: string[] = []
|
|
if (genre) parts.push(genre)
|
|
if (year) parts.push(String(year))
|
|
return parts.length > 0 ? parts.join(" · ") : null
|
|
}
|
|
|
|
export function initialsFromName(name: string): string {
|
|
return (
|
|
name
|
|
.match(/\b(\w)/g)
|
|
?.join("")
|
|
.slice(0, 2)
|
|
.toUpperCase() ?? "NA"
|
|
)
|
|
}
|