mime-types
The ultimate javascript content-type utility.
Last updated 11 years ago by fishrock123 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install mime-types 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.1.35                                ...           latest (3 years ago)
  • 3.0.0                                ...           next (4 months ago)

56 Versions

  • 3.0.0                                ...           4 months ago
  • 2.1.35                                ...           3 years ago
  • 2.1.34                                ...           3 years ago
  • 2.1.33                                ...           3 years ago
  • 2.1.32                                ...           3 years ago
  • 2.1.31                                ...           4 years ago
  • 2.1.30                                ...           4 years ago
  • 2.1.29                                ...           4 years ago
  • 2.1.28                                ...           4 years ago
  • 2.1.27                                ...           5 years ago
  • 2.1.26                                ...           5 years ago
  • 2.1.25                                ...           5 years ago
  • 2.1.24                                ...           6 years ago
  • 2.1.23                                ...           6 years ago
  • 2.1.22                                ...           6 years ago
  • 2.1.21                                ...           6 years ago
  • 2.1.20                                ...           6 years ago
  • 2.1.19                                ...           6 years ago
  • 2.1.18                                ...           7 years ago
  • 2.1.17                                ...           7 years ago
  • 2.1.16                                ...           7 years ago
  • 2.1.15                                ...           8 years ago
  • 2.1.14                                ...           8 years ago
  • 2.1.13                                ...           8 years ago
  • 2.1.12                                ...           8 years ago
  • 2.1.11                                ...           9 years ago
  • 2.1.10                                ...           9 years ago
  • 2.1.9                                ...           9 years ago
  • 2.1.8                                ...           9 years ago
  • 2.1.7                                ...           9 years ago
  • 2.1.6                                ...           9 years ago
  • 2.1.5                                ...           9 years ago
  • 2.1.4                                ...           9 years ago
  • 2.1.3                                ...           9 years ago
  • 2.1.2                                ...           9 years ago
  • 2.1.1                                ...           10 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.14                                ...           10 years ago
  • 2.0.13                                ...           10 years ago
  • 2.0.12                                ...           10 years ago
  • 2.0.11                                ...           10 years ago
  • 2.0.10                                ...           10 years ago
  • 2.0.9                                ...           10 years ago
  • 2.0.8                                ...           10 years ago
  • 2.0.7                                ...           10 years ago
  • 2.0.6                                ...           10 years ago
  • 2.0.5                                ...           10 years ago
  • 2.0.4                                ...           10 years ago
  • 2.0.3                                ...           10 years ago
  • 2.0.2                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
  • 0.1.0                                ...           11 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE