@nxtedition/mime 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +126 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) nxtedition
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @nxtedition/mime
|
|
2
|
+
|
|
3
|
+
MIME type lookup and extension resolution with built-in support for broadcast and professional media formats missing from the standard `mime` package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @nxtedition/mime
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Lookup MIME type by filename
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { lookup } from '@nxtedition/mime'
|
|
17
|
+
|
|
18
|
+
lookup('video.mxf') // 'application/mxf'
|
|
19
|
+
lookup('video.mp4') // 'video/mp4'
|
|
20
|
+
lookup('video.nut') // 'video/x-nut'
|
|
21
|
+
lookup('audio.ac3') // 'audio/ac3'
|
|
22
|
+
lookup('subs.stl') // 'application/x-ebu-stl'
|
|
23
|
+
lookup('subs.scc') // 'text/x-scc'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Get extension from MIME type
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { extension } from '@nxtedition/mime'
|
|
30
|
+
|
|
31
|
+
extension('video/mp4') // 'mp4'
|
|
32
|
+
extension('video/x-dnxhd') // 'dnxhd'
|
|
33
|
+
extension('audio/ac3') // 'ac3'
|
|
34
|
+
extension('application/x-ebu-stl') // 'stl'
|
|
35
|
+
extension('video/quicktime', 'clip.mov') // 'mov'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Broadcast & media types
|
|
39
|
+
|
|
40
|
+
Types handled beyond the standard `mime` package:
|
|
41
|
+
|
|
42
|
+
| Extension | MIME Type | Format |
|
|
43
|
+
| ------------ | ----------------------------- | ------------------------- |
|
|
44
|
+
| `.nut` | `video/x-nut` | NUT container |
|
|
45
|
+
| `.dnxhd` | `video/x-dnxhd` | Avid DNxHD/DNxHR |
|
|
46
|
+
| `.dv` | `video/x-dv` | DV video |
|
|
47
|
+
| `.h265` | `video/h265` | Raw HEVC stream |
|
|
48
|
+
| `.av1` | `video/av1` | Raw AV1 stream |
|
|
49
|
+
| `.ffv1` | `video/ffv1` | FFV1 archival codec |
|
|
50
|
+
| `.vc1` | `video/vc1` | VC-1 video |
|
|
51
|
+
| `.ac3` | `audio/ac3` | Dolby Digital |
|
|
52
|
+
| `.eac3` | `audio/eac3` | Dolby Digital Plus |
|
|
53
|
+
| `.opus` | `audio/opus` | Opus audio |
|
|
54
|
+
| `.flac` | `audio/flac` | FLAC lossless |
|
|
55
|
+
| `.pcm-s16le` | `audio/x-pcm-s16le` | Raw 16-bit PCM |
|
|
56
|
+
| `.pcm-s24le` | `audio/x-pcm-s24le` | Raw 24-bit PCM |
|
|
57
|
+
| `.pcm-s32le` | `audio/x-pcm-s32le` | Raw 32-bit PCM |
|
|
58
|
+
| `.stl` | `application/x-ebu-stl` | EBU STL subtitles |
|
|
59
|
+
| `.scc` | `text/x-scc` | Scenarist Closed Captions |
|
|
60
|
+
| `.cap` | `application/x-cap` | Softel CAP captions |
|
|
61
|
+
| `.890` | `application/x-890` | Cavena 890 subtitles |
|
|
62
|
+
| `.pac` | `application/x-pac` | Screen Electronics PAC |
|
|
63
|
+
| `.ass` | `text/x-ass` | Advanced SubStation Alpha |
|
|
64
|
+
| `.ssa` | `text/x-ssa` | SubStation Alpha |
|
|
65
|
+
| `.exr` | `image/x-exr` | OpenEXR |
|
|
66
|
+
| `.cin` | `image/x-cin` | Cineon |
|
|
67
|
+
| `.ism` | `application/vnd.ms-sstr+xml` | Smooth Streaming |
|
|
68
|
+
|
|
69
|
+
## API
|
|
70
|
+
|
|
71
|
+
### `lookup(name: string): string | null`
|
|
72
|
+
|
|
73
|
+
Returns the MIME type for the given filename or path, or `null` if unknown.
|
|
74
|
+
|
|
75
|
+
### `extension(mimeType: string, fileName?: string): string | null`
|
|
76
|
+
|
|
77
|
+
Returns the file extension for the given MIME type, or `null` if unknown. The optional `fileName` parameter is used to disambiguate (e.g. `video/quicktime` → `mov` when the filename ends in `.mov`).
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import mime from 'mime'
|
|
2
|
+
|
|
3
|
+
const EXT_TO_MIME = {
|
|
4
|
+
// Broadcast containers
|
|
5
|
+
nut: 'video/x-nut',
|
|
6
|
+
aaf: 'application/octet-stream',
|
|
7
|
+
lxf: 'application/octet-stream',
|
|
8
|
+
|
|
9
|
+
// Raw codecs
|
|
10
|
+
dnxhd: 'video/x-dnxhd',
|
|
11
|
+
dnxhr: 'video/x-dnxhd',
|
|
12
|
+
dv: 'video/x-dv',
|
|
13
|
+
h265: 'video/h265',
|
|
14
|
+
265: 'video/h265',
|
|
15
|
+
av1: 'video/av1',
|
|
16
|
+
ffv1: 'video/ffv1',
|
|
17
|
+
vc1: 'video/vc1',
|
|
18
|
+
|
|
19
|
+
// Raw PCM
|
|
20
|
+
'pcm-s32le': 'audio/x-pcm-s32le',
|
|
21
|
+
'pcm-s24le': 'audio/x-pcm-s24le',
|
|
22
|
+
'pcm-s16le': 'audio/x-pcm-s16le',
|
|
23
|
+
|
|
24
|
+
// Audio codecs missing extensions in mime-db
|
|
25
|
+
ac3: 'audio/ac3',
|
|
26
|
+
eac3: 'audio/eac3',
|
|
27
|
+
ec3: 'audio/eac3',
|
|
28
|
+
opus: 'audio/opus',
|
|
29
|
+
flac: 'audio/flac',
|
|
30
|
+
|
|
31
|
+
// Broadcast subtitle/caption formats
|
|
32
|
+
stl: 'application/x-ebu-stl',
|
|
33
|
+
scc: 'text/x-scc',
|
|
34
|
+
cap: 'application/x-cap',
|
|
35
|
+
890: 'application/x-890',
|
|
36
|
+
pac: 'application/x-pac',
|
|
37
|
+
ass: 'text/x-ass',
|
|
38
|
+
ssa: 'text/x-ssa',
|
|
39
|
+
|
|
40
|
+
// Imaging
|
|
41
|
+
exr: 'image/x-exr',
|
|
42
|
+
cin: 'image/x-cin',
|
|
43
|
+
|
|
44
|
+
// Streaming
|
|
45
|
+
ism: 'application/vnd.ms-sstr+xml',
|
|
46
|
+
|
|
47
|
+
// NOTE: Workaround for Chrome.
|
|
48
|
+
// See, https://bugs.chromium.org/p/chromium/issues/detail?id=227004.
|
|
49
|
+
mp3: 'audio/mp3',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const MIME_TO_EXT = {
|
|
53
|
+
// Broadcast containers
|
|
54
|
+
'video/x-nut': 'nut',
|
|
55
|
+
'video/nut': 'nut',
|
|
56
|
+
|
|
57
|
+
// Raw codecs
|
|
58
|
+
'video/x-dnxhd': 'dnxhd',
|
|
59
|
+
'video/dnxhd': 'dnxhd',
|
|
60
|
+
'video/x-dv': 'dv',
|
|
61
|
+
'video/dv': 'dv',
|
|
62
|
+
'video/h265': 'h265',
|
|
63
|
+
'video/av1': 'av1',
|
|
64
|
+
'video/ffv1': 'ffv1',
|
|
65
|
+
'video/vc1': 'vc1',
|
|
66
|
+
|
|
67
|
+
// Raw PCM
|
|
68
|
+
'audio/x-pcm-s32le': 'pcm-s32le',
|
|
69
|
+
'audio/pcm-s32le': 'pcm-s32le',
|
|
70
|
+
'audio/x-pcm-s24le': 'pcm-s24le',
|
|
71
|
+
'audio/pcm-s24le': 'pcm-s24le',
|
|
72
|
+
'audio/x-pcm-s16le': 'pcm-s16le',
|
|
73
|
+
'audio/pcm-s16le': 'pcm-s16le',
|
|
74
|
+
|
|
75
|
+
// Audio codecs
|
|
76
|
+
'audio/ac3': 'ac3',
|
|
77
|
+
'audio/eac3': 'eac3',
|
|
78
|
+
'audio/opus': 'opus',
|
|
79
|
+
'audio/flac': 'flac',
|
|
80
|
+
|
|
81
|
+
// Broadcast subtitle/caption formats
|
|
82
|
+
'application/x-ebu-stl': 'stl',
|
|
83
|
+
'text/x-scc': 'scc',
|
|
84
|
+
'application/x-cap': 'cap',
|
|
85
|
+
'application/x-890': '890',
|
|
86
|
+
'application/x-pac': 'pac',
|
|
87
|
+
'text/x-ass': 'ass',
|
|
88
|
+
'text/x-ssa': 'ssa',
|
|
89
|
+
|
|
90
|
+
// Imaging
|
|
91
|
+
'image/x-exr': 'exr',
|
|
92
|
+
'image/x-cin': 'cin',
|
|
93
|
+
|
|
94
|
+
// Streaming
|
|
95
|
+
'application/vnd.ms-sstr+xml': 'ism',
|
|
96
|
+
|
|
97
|
+
// QuickTime — prefer .mov over .qt
|
|
98
|
+
'video/quicktime': 'mov',
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function lookup(name ) {
|
|
102
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const match = name.match(/\.([^.]+)$/)
|
|
107
|
+
const ext = match?.[1]?.toLowerCase()
|
|
108
|
+
|
|
109
|
+
if (ext && EXT_TO_MIME[ext]) {
|
|
110
|
+
return EXT_TO_MIME[ext]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return mime.getType(name)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function extension(mimeType ) {
|
|
117
|
+
if (typeof mimeType !== 'string' || mimeType.length === 0) {
|
|
118
|
+
return null
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (MIME_TO_EXT[mimeType]) {
|
|
122
|
+
return MIME_TO_EXT[mimeType]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return mime.getExtension(mimeType) || (mimeType || '').split('/').pop() || null
|
|
126
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nxtedition/mime",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rimraf lib && tsc && amaroc ./src/index.ts && mv src/index.js lib/",
|
|
18
|
+
"prepublishOnly": "yarn build",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "node --test",
|
|
21
|
+
"test:ci": "node --test"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"mime": "^4.0.7"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^25.2.3",
|
|
28
|
+
"amaroc": "^1.0.1",
|
|
29
|
+
"oxlint-tsgolint": "^0.13.0",
|
|
30
|
+
"rimraf": "^6.1.3",
|
|
31
|
+
"typescript": "^5.9.3"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "a54f10182ade3ca92e198dce10ff06d059d296b8"
|
|
34
|
+
}
|