browser-mime

1.0.1 • Public • Published

browser-mime Build Status

MIME types that can be parsed/rendered in most browsers. The list is automatically generated from mime-db. Manual types and extension information is also included in src/initial-db.json.

To rebuild the JS library in dist/:

npm build

To regenerate the database:

npm run build-db

This will reproduce browser-mime-db.json by attempting to load an empty file of every type in mime-db, and keep track of which ones Chrome was able to download and use vs. prompting the user with a Download popup.

The mime-types project is included as a squashed subtree in mime-types/. To update the subtree code use npm run update-mime-types.

API

The API is identical too, and shares the same code as, mime-types. From their README:

var mime = require('mime-types')

All functions return false if input is invalid or not found.

mime.lookup(path)

Lookup the content-type associated with a file.

mime.lookup('json')             // 'application/json'
mime.lookup('.md')              // 'text/markdown'
mime.lookup('file.html')        // 'text/html'
mime.lookup('folder/file.js')   // 'application/javascript'
mime.lookup('folder/.htaccess') // false
 
mime.lookup('cats') // false

mime.contentType(type)

Create a full content-type header given a content-type or extension. When given an extension, mime.lookup is used to get the matching content-type, otherwise the given content-type is used. Then if the content-type does not already have a charset parameter, mime.charset is used to get the default charset and add to the returned content-type.

mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json') // 'application/json; charset=utf-8'
mime.contentType('text/html') // 'text/html; charset=utf-8'
mime.contentType('text/html; charset=iso-8859-1') // 'text/html; charset=iso-8859-1'
 
// from a full path
mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'

mime.extension(type)

Get the default extension for a content-type.

mime.extension('application/octet-stream') // 'bin'

mime.charset(type)

Lookup the implied default charset of a content-type.

mime.charset('text/markdown') // 'UTF-8'

var type = mime.types[extension]

A map of content-types by extension.

[extensions...] = mime.extensions[type]

A map of extensions by content-type.

Readme

Keywords

none

Package Sidebar

Install

npm i browser-mime

Weekly Downloads

45

Version

1.0.1

License

MIT

Unpacked Size

53.6 kB

Total Files

6

Last publish

Collaborators

  • humphd