Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

filePreview.ts

29 lines928 Bytes

1export const WORKSPACE_BROWSER_PREVIEW_EXTENSIONS = [".htm", ".html", ".pdf"] as const;
2​
3export const WORKSPACE_IMAGE_PREVIEW_EXTENSIONS = [
4 ".avif",
5 ".gif",
6 ".ico",
7 ".jpeg",
8 ".jpg",
9 ".png",
10 ".svg",
11 ".webp",
12] as const;
13​
14function hasPreviewExtension(path: string, extensions: ReadonlyArray<string>): boolean {
15 const pathWithoutQuery = path.split(/[?#]/, 1)[0]?.toLowerCase() ?? "";
16 return extensions.some((extension) => pathWithoutQuery.endsWith(extension));
18​
19export function isWorkspaceBrowserPreviewPath(path: string): boolean {
20 return hasPreviewExtension(path, WORKSPACE_BROWSER_PREVIEW_EXTENSIONS);
22​
23export function isWorkspaceImagePreviewPath(path: string): boolean {
24 return hasPreviewExtension(path, WORKSPACE_IMAGE_PREVIEW_EXTENSIONS);
26​
27export function isWorkspacePreviewEntryPath(path: string): boolean {
28 return isWorkspaceBrowserPreviewPath(path) || isWorkspaceImagePreviewPath(path);