Human-friendly taxonomy for file types. Zero dependencies.
List of mime types sourced from MDN.
npm i human-filetypes
The module exports two functions fromMime()
and fromExtension()
.
const { fromMime, fromExtension } = require('human-filetypes')
fromMime()
converts a MIME type identifier to a human-redable file kind.
const assert = require('assert')
assert.equal(fromMime('image/png'), 'image')
assert.equal(fromMime('image/webp'), 'image')
assert.equal(fromMime('application/pdf'), 'document')
assert.equal(fromMime('application/msword'), 'document')
assert.equal(fromMime('image/jpeg'), 'image')
assert.equal(fromMime('video/mpeg'), 'video')
assert.equal(fromMime('video/webm'), 'video')
assert.equal(fromMime('text/javascript'), 'text')
assert.equal(fromMime('application/json'), 'text')
assert.equal(fromMime('text/csv'), 'spreadsheet')
assert.equal(fromMime('application/zip'), 'archive')
fromExtension()
converts a file extension or a filename to a human-redable file kind.
assert.equal(fromExtension('.png'), 'image')
assert.equal(fromExtension('.webp'), 'image')
assert.equal(fromExtension('.gif'), 'image')
assert.equal(fromExtension('.pdf'), 'document')
assert.equal(fromExtension('.docx'), 'document')
assert.equal(fromExtension('.mp4'), 'video')
assert.equal(fromExtension('.webm'), 'video')
assert.equal(fromExtension('.json'), 'text')
assert.equal(fromExtension('.exe'), 'application')
assert.equal(fromExtension('.zip'), 'archive')
The following taxonomy is used:
File Kind | Description | Examples |
---|---|---|
image |
Image file | .png , .gif , .webp |
video |
Video file | .mp4 , .webm |
audio |
Audio file | .mp3 , .wav |
archive |
Archive file | .zip , .tar , .tar.gz |
document |
Text Document | .pdf , .docx , .odt |
spreadsheet |
Spreadsheet | .xlsx , .csv , .tsv |
presentation |
Presentation | .ppt , .pptx , .odp |
font |
Font package | .ttf , .otf , .woff2 |
text |
Plain text file | .txt , .html , .json |
application |
Executable/application package | .exe , .jar , .swf |
unknown |
Unknown | - |
File kinds are also available to import as an enum
:
import { FileKind } from 'human-filetypes'
assert.equal(fromExtension('.zip'), FileKind.Archive)
human-filetypes is Free and Open Source Software. Issues and pull requests are more than welcome!