@katsube/mimetypesjs
v1.1.2
Published
Return mimetype from filename extension
Downloads
4
Readme
MimeTypes.js
Get mime type from file name / file path. The list of MIME Types from Apache HTTP Server and I added.
A total of 985 types of MIME type are supported. The all list is here.
INDEX
Installation
$ npm install @katsube/mimetypesjs
Usage
const mimeTypes = require('@katsube/mimetypesjs')
const a = mimeTypes.get('a.txt') // "text/plain"
const b = mimeTypes.get('b.html') // "text/html"
const c = mimeTypes.get('/image/logo.jpg') // "image/jpeg"
API
get
Returns the MIME type according to the file extension.
const mimeTypes = require('@katsube/mimetypesjs')
const a = mimeTypes.get('a.txt') // text/plain
const b = mimeTypes.get('/var/www/html/b.html') // text/html
For undefined extensions, application/octet-stream
is returned. The default value can be changed with the second argument.
const a = mimeTypes.get('a.notdefined', 'text/plain') // text/plain
set
You can add or override the MIME Type yourself.
// Single
mimeTypes.set({ext:'foo', type:'application/foo'})
// Multiple
mimeTypes.set([
{ext:'foo', type:'application/foo'},
{ext:'bar', type:'application/bar'},
])
remove
Delete a predefined MIME Type.
// Single
mimeTypes.remove('txt')
// Multiple
mimeTypes.remove(['txt', 'html'])
listAll
Get the predefined MIME Type.
console.log(mimeTypes.listAll())
License
The MIT License.
The list of MIME Types is Apache licensed