Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mime-type

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mime-type

the custom content-type utility can work with meme-db.

  • 2.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.5K
decreased by-0.45%
Maintainers
1
Weekly downloads
 
Created
Source

mime-type

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

The custom mime-typs utility can work with mime-db.

fork from mime-types, except:

  • you can load mime-types via mime-db mime = new Mime(require('mime-db'))
    • or use mime = require('mime-type/with-db') directly, but first
    • you need npm install mime-db
  • mime = new Mime() business, so you could do lookup = mime.lookup.bind(mime).
  • you can add the mime-type via .define() functionality
  • you can search the mime-type via .glob() functionality
  • .exist(type) functionality to check whether a mime-type is exist.
  • .extensions will be deprecated, use mime[type].extensions instead.
  • All functions return undefined if input is invalid or not found.

Otherwise, the API is compatible.

Install

$ npm install mime-type

API

var mime = require('mime-type')()
//or create an instance and load mime-db. you need `npm install mime-db`
var mime = require('mime-type/with-db')

All functions return undefined 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('folder/.htaccess') // false

mime.lookup('cats') // false

mime.glob(pattern)

Return all MIME types which matching a pattern

mime.glob('*/*')             // 'application/json'
mime.lookup('.md')              // 'text/x-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.

mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json') // 'application/json; charset=utf-8'

// 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/x-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

Keywords

FAQs

Package last updated on 07 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc