mime-types
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/mime-types package

2.1.35 • Public • Published

mime-types

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

The ultimate javascript content-type utility.

Similar to the mime@1.x module, except:

  • No fallbacks. Instead of naively returning the first available type, mime-types simply returns false, so do var type = mime.lookup('unrecognized') || 'application/octet-stream'.
  • No new Mime() business, so you could do var lookup = require('mime-types').lookup.
  • No .define() functionality
  • Bug fixes for .lookup(path)

Otherwise, the API is compatible with mime 1.x.

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install mime-types

Adding Types

All mime types are based on mime-db, so open a PR there if you'd like to add mime types.

API

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.

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.1.3581,385,013latest
3.0.0243,263next

Version History

VersionDownloads (Last 7 Days)Published
3.0.0243,263
2.1.3581,385,013
2.1.3411,391,694
2.1.332,548,935
2.1.323,188,127
2.1.312,335,092
2.1.302,412,396
2.1.291,591,272
2.1.281,682,396
2.1.275,568,128
2.1.262,242,959
2.1.25836,953
2.1.242,544,101
2.1.2314,930
2.1.22594,461
2.1.21917,366
2.1.20429,327
2.1.19244,515
2.1.184,999,484
2.1.17620,661
2.1.1692,874
2.1.15207,996
2.1.1484,656
2.1.13297,353
2.1.1225,370
2.1.11416,621
2.1.1011,724
2.1.92,635
2.1.818,325
2.1.72,076
2.1.6105
2.1.5171
2.1.43,713
2.1.3888
2.1.21,099
2.1.1206
2.1.020
2.0.14683,090
2.0.13630
2.0.129,530
2.0.1179
2.0.101,252
2.0.91,005
2.0.8140
2.0.7103
2.0.613
2.0.511
2.0.460
2.0.373
2.0.2103
2.0.161
2.0.067
1.0.2465,947
1.0.112,150
1.0.020,916
0.1.019

Package Sidebar

Install

npm i mime-types

Weekly Downloads

58,348,411

Version

2.1.35

License

MIT

Unpacked Size

18.3 kB

Total Files

5

Last publish

Collaborators

  • blakeembrey
  • wesleytodd
  • ulisesgascon
  • dougwilson
  • jongleberry