Git Product home page Git Product logo

mim's Introduction

MIM Build Status NPM version Code Climate

A simple MIME type recognition library that works in both browser and Node.js apps

Installation

Node.js

Install MIM with npm:

npm install mim

And then require it in your node app:

var MIM = require('mim');

Browser

Install MIM with bower:

bower install mim

Or download desired version from on the Releases page

Then add the HTML script tag to include MIM in your global Javascript namespace:

<script src="wherever/mim.js"></script>

Usage

MIME type lookup

var mimeType;

mimeType = MIM.getMIMEType('nonexistent');
console.log(mimeType); // displays null

mimeType = MIM.getMIMEType('mkv');
console.log(mimeType); // displays 'video/x-matroska'

mimeType = MIM.getMIMEType('.jpeg');
console.log(mimeType); // displays 'image/jpeg'

mimeType = MIM.getMIMEType('long_file-name.ecma');
console.log(mimeType); // displays 'application/ecmascript'

mimeType = MIM.getMIMEType('/etc/default/whatever.mif');
console.log(mimeType); // displays 'application/vnd.mif'

mimeType = MIM.getMIMEType('/folder with spaces/and file with space.xspf');
console.log(mimeType); // displays 'application/xspf+xml'

mimeType = MIM.getMIMEType('../../discobolos.xyz');
console.log(mimeType); // displays 'chemical/x-xyz'

mimeType = MIM.getMIMEType('https://mediapeers.com/products/12.json');
console.log(mimeType); // displays 'application/json'

mimeType = MIM.getMIMEType('https://s3.amazonaws.com/mpx-ah-ftp/archive_2.zip?token=hello-world');
console.log(mimeType); // displays 'application/zip'

MIME type lookup with default

var mimeType;

mimeType = MIM.getMIMEType('nonexistent', 'application/octet-stream');
console.log(mimeType); // displays 'application/octet-stream'

License

MIM is released under the MIT License.

mim's People

Contributors

mcontagious avatar stefanhorning avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mcontagious

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.