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.3547,877,106latest
3.0.0255,581next

Version History

VersionDownloads (Last 7 Days)Published
3.0.0255,581
2.1.3547,877,106
2.1.341,773,672
2.1.33225,155
2.1.32436,852
2.1.31342,805
2.1.30407,670
2.1.29247,284
2.1.28671,565
2.1.271,171,811
2.1.26546,231
2.1.25205,605
2.1.24528,398
2.1.235,554
2.1.22140,687
2.1.21145,074
2.1.2089,618
2.1.1939,263
2.1.181,960,632
2.1.17129,008
2.1.1619,000
2.1.1551,799
2.1.1426,295
2.1.1399,850
2.1.127,112
2.1.11168,220
2.1.105,315
2.1.9942
2.1.8540
2.1.7755
2.1.661
2.1.536
2.1.471
2.1.3396
2.1.218
2.1.124
2.1.016
2.0.14205,600
2.0.1322
2.0.1256
2.0.116
2.0.10256
2.0.9137
2.0.816
2.0.734
2.0.67
2.0.52
2.0.434
2.0.353
2.0.210
2.0.15
2.0.082
1.0.2157,692
1.0.11,070
1.0.04,040
0.1.012

Package Sidebar

Install

npm i mime-types

Weekly Downloads

46,545,871

Version

2.1.35

License

MIT

Unpacked Size

18.3 kB

Total Files

5

Last publish

Collaborators

  • blakeembrey
  • wesleytodd
  • ulisesgascon
  • dougwilson
  • jongleberry