Socket
Socket
Sign inDemoInstall

mimoza

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mimoza

Simple mime-types tools library


Version published
Weekly downloads
2.8K
decreased by-12.12%
Maintainers
1
Install size
451 kB
Created
Weekly downloads
 

Readme

Source

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'

Keywords

FAQs

Last updated on 02 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc