Mimoza
Mimoza is a tiny but comprehensive MIME tools library. Features:
- Resolving mime type by file path/name/extention (with fallback
for unknown cases).
- Finding file extention by mime type.
- Checking if mime type (or file) can be compressed.
- Checking if mime type has text content (if you wish to force UTF-8 encoding)
- You can have multimple instances with different configs.
- Works in browser too (AMD module).
See detailed API docs.
Installation
for node.js:
npm install mimoza
for browser (AMD module):
bower install mimoza
Example
var Mimoza = require('mimoza');
Mimoza.getExtension('audio/ogg');
Mimoza.getMimeType('ogg');
Mimoza.getMimeType('.oga');
Mimoza.getMimeType('test.oga');
Mimoza.getMimeType('foo/bar.oga');
Mimoza.isCompressible('text/html');
Mimoza.isCompressible('application/octet-stream');
Mimoza.isText('text/html');
Mimoza.isText('application/javascript');
Mimoza.isText('application/json');
Mimoza.isText('application/octet-stream');
var mime = new Mimoza({
defaultType: 'hard/core',
preloaded: true
});
mime.register('foo/bar', ['baz', 'moo']);
mime.getExtension('foo/bar');
mime.getMimeType('baz');
mime.getMimeType('moo');
mime.getMimeType('tada');
mime.getMimeType('tada', 'soft/core');