lighter-mime
The lighter-mime
module combines speed and support by immediately loading a
basic set of MIME types, and lazily loading a full set.
Installation
From your project directory, install and save as a dependency:
npm install --save lighter-mime
API
The lighter-mime
package exports an object whose keys are lowercase file
extensions and values are MIME types.
mime
The basic mapping is pretty simple:
var mime = console //> { css: 'text/css',// gif: 'image/gif',// html: 'text/html',// ico: 'image/x-icon',// jpg: 'image/jpg',// js: 'application/javascript',// json: 'application/json',// png: 'image/png',// svg: 'image/svg+xml',// txt: 'text/plain',// xml: 'application/xml' }
mime.set(extension, type)
Set or overwrite a MIME type mapping for a given extension.
var mime = console//> 'application/javascript' // Let's consider JavaScript to be text.mimeconsole//> 'text/javascript'
mime.load()
Load the comprehensive list immediately (and return the mapping).
var mime = console//> 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
mime.timeout(milliseconds)
Delay loading the comprehensive list for a specified number of milliseconds, rather than the default 1 millisecond.