Skip to content

katsube/mimetypesjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Installation
  2. Usage
  3. API
    1. get
    2. set
    3. remove
    4. listAll
  4. License

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