mime-types
The ultimate javascript content-type utility.
Last updated 6 months ago by dougwilson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm 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.24                                ...           latest (6 months ago)

44 Versions

  • 2.1.24                                ...           6 months ago
  • 2.1.23                                ...           6 months ago
  • 2.1.22                                ...           8 months ago
  • 2.1.21                                ...           a year ago
  • 2.1.20                                ...           a year ago
  • 2.1.19                                ...           a year ago
  • 2.1.18                                ...           2 years ago
  • 2.1.17                                ...           2 years ago
  • 2.1.16                                ...           2 years ago
  • 2.1.15                                ...           3 years ago
  • 2.1.14                                ...           3 years ago
  • 2.1.13                                ...           3 years ago
  • 2.1.12                                ...           3 years ago
  • 2.1.11                                ...           3 years ago
  • 2.1.10                                ...           4 years ago
  • 2.1.9                                ...           4 years ago
  • 2.1.8                                ...           4 years ago
  • 2.1.7                                ...           4 years ago
  • 2.1.6                                ...           4 years ago
  • 2.1.5                                ...           4 years ago
  • 2.1.4                                ...           4 years ago
  • 2.1.3                                ...           4 years ago
  • 2.1.2                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.14                                ...           4 years ago
  • 2.0.13                                ...           4 years ago
  • 2.0.12                                ...           4 years ago
  • 2.0.11                                ...           4 years ago
  • 2.0.10                                ...           5 years ago
  • 2.0.9                                ...           5 years ago
  • 2.0.8                                ...           5 years ago
  • 2.0.7                                ...           5 years ago
  • 2.0.6                                ...           5 years ago
  • 2.0.5                                ...           5 years ago
  • 2.0.4                                ...           5 years ago
  • 2.0.3                                ...           5 years ago
  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Downloads
Today 926
This Week 926
This Month 508,481
Last Day 12,010
Last Week 222,823
Last Month 924,313
Dependencies (1)
Dev Dependencies (8)
Dependents (1918)

Copyright 2014 - 2017 © taobao.org |