JSPM

  • Created
  • Published
  • Downloads 92872748
  • Score
    100M100P100Q235571F
  • License MIT

ultimate mime type utility

Package Exports

  • mime-types

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mime-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mime-types Build Status NPM version

The ultimate javascript content-type utility.

Install

$ npm install mime-types

Similar to mime except:

  • No new Mime() business, so you could do var lookup = require('mime-types').lookup.
  • No fallbacks, so do var type = mime.lookup('unrecognized') || 'application/octet-stream'.
  • Additional mime types are added such as jade and stylus. Feel free to add more!
  • Browser support via Browserify and Component by converting lists to JSON files.

Otherwise, the API is compatible.

Adding Types

If you'd like to add additional types, simply create a PR adding the type to custom.json and a reference link to the sources.

Do NOT edit mime.json or node.json. Those are pulled using build.js. You should only touch custom.json.

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/x-markdown'
mime.lookup('file.html')      // 'text/html'
mime.lookup('folder/file.js') // 'application/javascript'

mime.lookup('cats') // false

mime.contentType(type)

Create a full content-type header given a content-type or extension.

mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
mime.contentType('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/x-markdown') // 'UTF-8'

mime.types[extension] = type

A map of content-types by extension.

mime.extensions[type] = [extensions]

A map of extensions by content-type.

mime.define(types)

Globally add definitions. types must be an object of the form:

{
  "<content-type>": [extensions...],
  "<content-type>": [extensions...]
}

See the .json files in lib/ for examples.

License

MIT