@nxtedition/mime
v1.1.7
Published
MIME type lookup and extension resolution with built-in support for broadcast and professional media formats missing from the standard `mime` package.
Maintainers
Keywords
Readme
@nxtedition/mime
MIME type lookup and extension resolution with built-in support for broadcast and professional media formats missing from the standard mime package.
Install
npm install @nxtedition/mimeUsage
Lookup MIME type by filename
import { lookup } from '@nxtedition/mime'
lookup('video.mxf') // 'application/mxf'
lookup('video.mp4') // 'video/mp4'
lookup('video.nut') // 'video/x-nut'
lookup('audio.ac3') // 'audio/ac3'
lookup('subs.stl') // 'application/x-ebu-stl'
lookup('subs.scc') // 'text/x-scc'
// Bare extensions work too (like the standard mime package):
lookup('nut') // 'video/x-nut'
lookup('dnxhd') // 'video/x-dnxhd'Get extension from MIME type
import { extension } from '@nxtedition/mime'
extension('video/mp4') // 'mp4'
extension('video/x-dnxhd') // 'dnxhd'
extension('audio/ac3') // 'ac3'
extension('application/x-ebu-stl') // 'stl'
extension('video/quicktime') // 'mov'
// MIME types are case-insensitive and parameters are ignored:
extension('Video/X-DnxHD; profile=hd') // 'dnxhd'Broadcast & media types
Types handled beyond (or instead of) the standard mime package:
| Extension | MIME Type | Format |
| ---------------------- | ----------------------------- | ------------------------- |
| .nut | video/x-nut | NUT container |
| .aaf | application/x-aaf | Avid AAF |
| .lxf | application/x-lxf | Leitch LXF |
| .dnxhd .dnxhr | video/x-dnxhd | Avid DNxHD/DNxHR |
| .dv | video/x-dv | DV video |
| .h265 .265 .hevc | video/h265 | Raw HEVC stream |
| .264 .avc | video/h264 | Raw AVC stream |
| .h266 .266 .vvc | video/h266 | Raw VVC stream |
| .av1 | video/av1 | Raw AV1 stream |
| .ffv1 | video/ffv1 | FFV1 archival codec |
| .vc1 | video/vc1 | VC-1 video |
| .prores | video/x-prores | Apple ProRes |
| .r3d | video/x-red-r3d | RED REDCODE RAW |
| .braw | video/x-blackmagic-braw | Blackmagic RAW |
| .ari | image/x-arri-ari | ARRIRAW frame |
| .ac3 | audio/ac3 | Dolby Digital |
| .eac3 .ec3 | audio/eac3 | Dolby Digital Plus |
| .opus | audio/opus | Opus audio |
| .flac | audio/flac | FLAC lossless |
| .pcm-s16le | audio/x-pcm-s16le | Raw 16-bit PCM |
| .pcm-s24le | audio/x-pcm-s24le | Raw 24-bit PCM |
| .pcm-s32le | audio/x-pcm-s32le | Raw 32-bit PCM |
| .bwf | audio/wav | Broadcast Wave |
| .w64 | audio/x-w64 | Sony Wave64 |
| .rf64 | audio/x-rf64 | EBU RF64 |
| .stl | application/x-ebu-stl | EBU STL subtitles |
| .scc | text/x-scc | Scenarist Closed Captions |
| .cap | application/x-cap | Softel CAP captions |
| .890 | application/x-890 | Cavena 890 subtitles |
| .pac | application/x-pac | Screen Electronics PAC |
| .ass | text/x-ass | Advanced SubStation Alpha |
| .ssa | text/x-ssa | SubStation Alpha |
| .dfxp .itt | application/ttml+xml | TTML dialects |
| .exr | image/x-exr | OpenEXR |
| .cin | image/x-cin | Cineon |
| .ism | application/vnd.ms-sstr+xml | Smooth Streaming |
| .mp3 | audio/mp3 | MP3 (Chrome workaround) |
Camera RAW stills are also covered: cr2, cr3, nef, nrw, arw, srf, sr2, raf, rw2, orf, pef, ptx, x3f, 3fr, fff, iiq, mrw, mef, dng, raw, rwl, k25, kdc, bay, erf, srw, mos — each mapped to its vendor image/x-* type.
Deliberate differences from mime
Some mappings intentionally shadow standard ones for broadcast use. If you serve 3D models, pcap captures, or proxy autoconfig files, this package is not for you:
.stl→application/x-ebu-stl(notmodel/stl).cap→application/x-cap(notapplication/vnd.tcpdump.pcap).pac→application/x-pac(notapplication/x-ns-proxy-autoconfig).opus→audio/opus(notaudio/ogg).flac→audio/flac(notaudio/x-flac).exr→image/x-exr(notimage/aces).mp3→audio/mp3(notaudio/mpeg, see Chromium #227004)
In the reverse direction, common media extensions are preferred over mime-db's first entries:
video/quicktime→mov(notqt)audio/mpeg→mp3(notmpga)audio/aac→aac(notadts)
extension() also accepts common alias spellings that have no forward mapping: video/nut, video/dnxhd, video/dv, video/hevc (→ h265), video/x-m2ts, audio/pcm-s16le/-s24le/-s32le (without the x- prefix), and image/x-dpx.
API
lookup(name: string): string | null
Returns the MIME type for the given filename, path, or bare extension, or null if unknown. Matching is case-insensitive and follows the standard mime package's path semantics: the extension is what follows the last dot of the basename, provided that dot is not the basename's first character (a dotfile with a path, like /path/.nut, is extensionless). A name without such an extension is treated as a bare extension only when it has no path component (nut and .nut both resolve).
Also exported as getType.
extension(mimeType: string): string | null
Returns the file extension for the given MIME type, or null if unknown. Matching is case-insensitive and ignores parameters (e.g. ; charset=...).
Also exported as getExtension.
License
MIT
