Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
mime-db | 1.52.0 | 26.36 kB | MIT | prod | |
mime-types | 2.1.35 | 5.46 kB | MIT | prod |
Mime-types is a content-type utility in JavaScript. It precisely offers its services due to its feature of not falling back naively to the first available type. Instead, when a file type is unrecognized, it returns 'false'. It is a node.js module available via npm registry and all its types are rooted in mime-db. It provides various API functionalities such as looking up the content-type associated with a file, creating a full content-type header given an extension or content-type, fetching the default extension for a content-type, checking the implied default charset of a content-type, and more.
Usage of mime-types is fairly straightforward after you've installed it using the npm install command npm install mime-types
. Post-installation, you can require it in your JavaScript file with the following command var mime = require('mime-types')
. The various functions provide different use cases:
mime.lookup('json'); //returns 'application/json'
mime.contentType('markdown'); //returns 'text/x-markdown; charset=utf-8'
mime.extension('application/octet-stream'); //returns 'bin'
mime.charset('text/markdown'); //returns 'UTF-8'
mime.types[extension]
and a map of extensions by content-type at mime.extensions[type]
.Mime-types documentation can be found on the project's GitHub page at https://github.com/jshttp/mime-types
. The readme file on the project's GitHub page offers detailed understanding of mime-types, covering different aspects like installation, usage and API. It should be your go-to guide for any queries regarding the usage of this package.