1.0.1 • Published 6 years ago

mimisbrunnr v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

mimisbrunnr

This npm module is used to resolve files with extensions (or file extensions by themselves) into their respective MIME types. It solves the same problem as the following modules:

The thing that is different with this module from the previouslu mentioned ones is its implementation. Whilst we theoretically could go all day arguing as to which module is implemented in the best manner, it only ever comes down to which module you prefer to use.

Mímisbrunnr is the well associated with the being Mímir, whose name in Swedish is Mimer, which in turn contains the word mime. As such, you can clearly see, mimisbrunnr is the perfect most obvious name for a module managing MIME types.

Installation

npm install mimisbrunnr

Usage

First and foremost, you need to require mimisbrunnr:

const mime = require('mimisbrunnr').mime

mime is a function that, when called with a string representing a file with an extension (or a file extension without a file name), resolves to a MIME type:

console.log(mime('file.txt')) // Output: text/plain
console.log(mime('minecraft.jar')) // Output: application/java-archive
console.log(mime('hello.js')) // Output: application/javascript

console.log(mime('.txt')) // Output: text/plain
console.log(mime('.jar')) // Output: application/java-archive
console.log(mime('.js')) // Output: application/javascript

/* The following is viewed as a file without an extension, as such we might wish 
 * to handle it differently:
 */
console.log(mime('txt')) // Output: null

/* The following is an unrecognized file extension. As such, we might wish to 
 * handle that differently too:
 */
console.log(mime('.whitepowderandsnuffbecomesgrey')) // Output: null

As you can tell, anything that is unrecognized will similarly to the mime-types module, return something that we can handle further: in the case of this module, anything that is unrecognized returns null.

let mimeType = mime('.whitepowderandsnuffbecomesgrey') || 'text/plain'

License

This module, and the code therein, is licensed under MIT.