forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.ts
More file actions
36 lines (34 loc) · 840 Bytes
/
Copy pathstring.ts
File metadata and controls
36 lines (34 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export function camelToDataKebab(str: string): string {
return "data-" + str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
}
export function filenameFromURL(url: string): string {
const parts = url.split("/");
if (
!parts.length || // invalid?
parts[parts.length - 1] === "" // for example, URL ends in a directory-like trailing slash
) {
// in this case just return the original url
return url;
}
return parts[parts.length - 1];
}
export function isVideoUrl(url: string) {
const videoExtensions = [
"mp4",
"webm",
"ogg",
"mov",
"mkv",
"flv",
"avi",
"wmv",
"m4v",
];
try {
const pathname = new URL(url).pathname;
const ext = pathname.split(".").pop()?.toLowerCase() || "";
return videoExtensions.includes(ext);
} catch (_) {
return false;
}
}