Skip to content

Commit cfa1c0c

Browse files
committed
fix: missing lib files
1 parent e3c2e3f commit cfa1c0c

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ coverage/
88
.nyc_output
99

1010
# Production
11-
lib/
12-
dist/
13-
build/
11+
/lib/
12+
/dist/
13+
/build/
1414

1515
# Misc
1616
.DS_Store

example/src/lib/cn.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { clsx, type ClassValue } from 'clsx';
2+
import { twMerge } from 'tailwind-merge';
3+
4+
export function cn(...inputs: ClassValue[]): string {
5+
return twMerge(clsx(inputs));
6+
}

example/src/lib/formatTime.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function format(totalSeconds: number): string {
2+
if (!Number.isFinite(totalSeconds) || totalSeconds < 0) {
3+
return '0:00';
4+
}
5+
const seconds = Math.floor(totalSeconds % 60);
6+
const minutes = Math.floor((totalSeconds / 60) % 60);
7+
const hours = Math.floor(totalSeconds / 3600);
8+
const pad = (n: number) => n.toString().padStart(2, '0');
9+
if (hours > 0) {
10+
return `${hours}:${pad(minutes)}:${pad(seconds)}`;
11+
}
12+
return `${minutes}:${pad(seconds)}`;
13+
}
14+
15+
export function formatTime(seconds: number): string {
16+
return format(seconds);
17+
}
18+
19+
export function formatDuration(seconds: number): string {
20+
return format(seconds);
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// iTunes <itunes:duration> can be a raw seconds count ("3600"),
2+
// "MM:SS", or "HH:MM:SS". Returns total seconds, or 0 if unparseable.
3+
export function parseItunesDuration(value: string | undefined): number {
4+
if (!value) return 0;
5+
const trimmed = value.trim();
6+
if (!trimmed) return 0;
7+
8+
if (!trimmed.includes(':')) {
9+
const n = Number(trimmed);
10+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
11+
}
12+
13+
const parts = trimmed.split(':').map((p) => Number(p));
14+
if (parts.some((n) => !Number.isFinite(n) || n < 0)) return 0;
15+
16+
let total = 0;
17+
if (parts.length === 3) {
18+
const [h, m, s] = parts;
19+
total = h * 3600 + m * 60 + s;
20+
} else if (parts.length === 2) {
21+
const [m, s] = parts;
22+
total = m * 60 + s;
23+
} else {
24+
return 0;
25+
}
26+
return Math.floor(total);
27+
}

0 commit comments

Comments
 (0)