getMIMEType
A function that retrieves the MIME type by integrating getMIMETypeFromFile, getMIMETypeFromResponse, and getMIMETypeFromUrl. 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 getMIMEType: (data: string | File | Response) => Promise<string>
Usage
typescript
import { getMIMEType, isMIMEType } from '@modern-kit/utils';
const mimeType1 = await getMIMEType(response); // Gets MIME type via getMIMETypeFromResponse
const mimeType2 = await getMIMEType(url); // Gets MIME type via getMIMETypeFromUrl
const mimeType3 = await getMIMEType(file); // Gets MIME type via getMIMETypeFromFile
if (isMIMEType(mimeType1)) {
mimeType1; // type: MIMEType
} else {
mimeType1; // type: string
}