@arraypress/mime-types
v1.0.0
Published
Classify and label MIME types. Detect images, audio, video, documents, and archives.
Maintainers
Readme
@arraypress/mime-types
Classify and label MIME types. Detect images, audio, video, documents, and archives. Zero dependencies.
Installation
npm install @arraypress/mime-typesUsage
import { getCategory, getLabel, isImage, isDocument, isArchive, getExtension, isPreviewable } from '@arraypress/mime-types';
// Classification
getCategory('image/png') // 'image'
getCategory('application/pdf') // 'document'
getCategory('application/zip') // 'archive'
getCategory('application/json') // 'other'
// Human-readable labels
getLabel('image/png') // 'Image'
getLabel('application/pdf') // 'Document'
getLabel('application/json') // 'JSON'
getLabel(null) // 'Unknown'
// Type detection
isImage('image/webp') // true
isDocument('application/vnd.openxmlformats-officedocument.wordprocessingml.document') // true
isArchive('application/x-7z-compressed') // true
// File extensions
getExtension('image/jpeg') // 'jpg'
getExtension('audio/mpeg') // 'mp3'
getExtension('application/pdf') // 'pdf'
// Browser previewability
isPreviewable('image/png') // true
isPreviewable('application/pdf') // true
isPreviewable('application/zip') // falseAPI
Type detection
isImage(mime)—image/*isAudio(mime)—audio/*isVideo(mime)—video/*isDocument(mime)— PDF, Word, Excel, text, CSV, RTF, OpenDocumentisArchive(mime)— ZIP, RAR, 7z, gzip, tar, bzip2
Classification
getCategory(mime)— Returns'image','audio','video','document','archive', or'other'getLabel(mime)— Human-readable label ('Image','Document','JSON', etc.)getExtension(mime)— Common file extension without dot ('png','pdf','mp3', etc.)isPreviewable(mime)— Whether browsers can render it natively
All functions return false, 'other', 'Unknown', or '' for null/undefined/empty input.
License
MIT
