包详细信息

mimoza

nodeca16.6kMIT1.0.0

Simple mime-types tools library

mime

自述文件

Mimoza

Build Status NPM version Coverage Status

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');

// Use builtin methods:

Mimoza.getExtension('audio/ogg');       // -> '.oga'

Mimoza.getMimeType('ogg');              // -> 'audio/ogg'
Mimoza.getMimeType('.oga');             // -> 'audio/ogg'
Mimoza.getMimeType('test.oga');         // -> 'audio/ogg'
Mimoza.getMimeType('foo/bar.oga');      // -> 'audio/ogg'

Mimoza.isCompressible('text/html');                // -> true
Mimoza.isCompressible('application/octet-stream'); // -> false

Mimoza.isText('text/html');                // -> true
Mimoza.isText('application/javascript');   // -> true
Mimoza.isText('application/json');         // -> true
Mimoza.isText('application/octet-stream'); // -> false


// Define your own instance

var mime = new Mimoza({
  defaultType: 'hard/core', // mime type for unknown extentions
  preloaded: true           // load default rules
});

// instances are customizeable
mime.register('foo/bar', ['baz', 'moo']);

mime.getExtension('foo/bar');           // -> '.baz'
mime.getMimeType('baz');                // -> 'foo/bar'
mime.getMimeType('moo');                // -> 'foo/bar'

// unknown file types, with default & custom fallback
mime.getMimeType('tada');               // -> 'hard/core'
mime.getMimeType('tada', 'soft/core');  // -> 'soft/core'

更新日志

1.0.0 / 2015-02-03

  • Use mime-db instead of local text files.
  • Removed methods:
    • loadMimes()
    • loadCompressibles()
    • define()
    • isCompressible() (use compressible package instead)
  • Added clone() method.
  • Massive code cleanup.
  • Improved tests coverage.

0.3.0 / 2013-12-24

  • Simplified API.
  • Removed is isCompressibleExtention().
  • Renamed isCompressibleMimeType() to isCompressible().
  • Added isText() method.

0.2.0 / 2013-12-24

  • API change.
  • Added preloaded option , to init instances with default mime rules.
  • Removed normalize option.
  • Changed loadFile(name) -> loadMimes(String|Array).
  • Added loadCompressibles(), isCompressibleMimeType() & isCompressibleExtention() methods.
  • getExtention() now case insensitive.
  • getMimeType() now accept typed mimes & mimes with charset.
  • Sync node.types with nodeca-mime.
  • Added tests.

0.1.1 / 2012-08-10

  • Added 'Mozilla App manifest' mime type

0.1.0 / 2012-05-15

  • First release