dl.emersa.it/src/lib/server/helpers.ts
0d0 6b8779f527
All checks were successful
Bump deps (only minor versions) / ci (push) Successful in 16s
better code
2025-02-23 05:22:37 +01:00

22 lines
No EOL
514 B
TypeScript

import formats from '$lib/common/supportedFormats.json';
const formatMime = new Map(Object.entries(formats))
export const isURLValid = (url: string) => {
try {
new URL(url)
} catch {
return false
}
return true;
}
export const mimeTypeMap = formatMime;
export const contentTypeFromFormat = (format: string): string => {
const toReturn: string | undefined = formatMime.get(format)
if (!toReturn) {
throw new Error("Unsupported format")
}
return toReturn;
}