Socket
Socket
Sign inDemoInstall

mrmime

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrmime

A tiny (2.8kB) and fast utility for getting a MIME type from an extension or filename


Version published
Maintainers
1
Weekly downloads
7,206,535
decreased by-7.34%

Weekly downloads

Readme

Source
mrmime
version CI downloads install size
A tiny (2.8kB) and fast utility for getting a MIME type from an extension or filename

Features

Install

$ npm install --save mrmime

Usage

import { lookup, mimes } from 'mrmime';

// Get a MIME type
// ---
lookup('txt'); //=> "text/plain"
lookup('.txt'); //=> "text/plain"
lookup('a.txt'); //=> "text/plain"

// Unknown extension
// ---
lookup('.xyz'); //=> undefined

// Add extension to dictionary
// ---
mimes['xyz'] = 'hello/world';
lookup('xyz'); //=> "hello/world"

API

lookup(input)

Returns: string or undefined

input

Type: string

The extension or filename to lookup.

Important:

  • Any input value is cast to string, lowercased, and trimmed.
  • If a filename or filepath is provided, only the extension will be used.

Benchmarks

Running on Node v16.8.0

Load times:
  mrmime     0.963ms
  mime/lite  3.281ms
  mime       6.751ms

Benchmark :: plain ("ext")
  mime          x 598,849 ops/sec ±0.28% (94 runs sampled)
  mime/lite     x 536,643 ops/sec ±0.11% (97 runs sampled)
  mrmime        x 835,885 ops/sec ±0.20% (97 runs sampled)

Benchmark :: leading (".ext")
  mime          x 368,656 ops/sec ±0.19% (99 runs sampled)
  mime/lite     x 368,318 ops/sec ±0.13% (97 runs sampled)
  mrmime        x 533,643 ops/sec ±0.10% (96 runs sampled)

Benchmark :: filename ("file.ext")
  mime          x 326,907 ops/sec ±0.17% (95 runs sampled)
  mime/lite     x 327,479 ops/sec ±0.12% (98 runs sampled)
  mrmime        x 512,823 ops/sec ±0.12% (99 runs sampled)

Credits

Of course, a thank-you to mime serving the community all these years & for being a all-encompassing MIME type library. I've only ever needed lookup/getType functionality – and now ESM support – so mrmime can only ever support 1/3 of what mime offers, at best.

This would not be possible without the team behind mime-db, who have painstakingly maintained an amazing database for 7+ years.

Artwork created by mintinol, which I found here.

Finally, thanks to Tim Branyen for donating the package name :)

License

MIT © Luke Edwards

Keywords

FAQs

Last updated on 20 Dec 2023

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