getMIMETypeFromUrl
An async function that takes a URL string, makes a fetch request to that URL, and extracts the MIME type from the response Response object. Returns an empty string ('') if it fails to retrieve the MIME type.
💡 You can narrow the type to MIMEType using the isMIMEType function.
💡 See the Note section below for all available MIME type values.
Code
Interface
typescript
const getMIMETypeFromUrl: (url: string) => Promise<string>
Usage
typescript
import { getMIMETypeFromUrl, isMIMEType } from '@modern-kit/utils';
const mimeType = await getMIMETypeFromUrl("URL");
if (isMIMEType(mimeType)) {
mimeType; // type: MIMEType
} else {
mimeType; // type: string
}