1.1.2 • Published 9 months ago

@katsube/mimetypesjs v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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

1.1.2

9 months ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago