2.0.1 • Published 4 months ago

mrmime v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 months ago

Features

  • Lightweight – 2.8kB gzip Only includes standard mime types; all experimental and vendor-specific mimetypes removed.

  • Performant All lookups are O(1) with minimal processing.

  • Comprehensive Dictionary Generated from mime-db, which aggregates the IANA, NGINX, and Apache datasets.

  • Customizable Exposes the mimes dictionary for easy additions or overrides.

  • Supports Native ESM and Deno Ships with CommonJS and ESM support!

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

@infinitebrahmanuniverse/nolb-mr@reflame/cid@reflame/lib-resourcetesting-ci-ortsa-partytown@everything-registry/sub-chunk-2211vite-plugin-sirv@mediakular/svelte-data-gridkjistik-fixed-component-libraryphone-morkupsynchronizer-v2taleempresentationsync-cloud-storagesvelte-searchable-selectsvelvet-customworktopwrightplaywrenchnpm-ui-componentssveltejs-kit-rerouteteapackage-tatespoorman297svelte-component-libsvelte-crypt-textthreads-apivite-plugin-lib-emit-assetsvite-plugin-minissgvite-plugin-monkeyvite-plugin-unocss-bgimguwebsocket-serve@collected/github-fetch@collected/press-server@studiocms/coreip-designlanj-test-componentsnextjs-storieskjistik-component-libraryswagger-ui-clisveltekit-rewritezzzxxxyyy321123summerseatestlstudiocmstehmusimhujan@anaidenko/ngx-awesome-uploader@angular-architects/build-angular@angular-architects/module-federation-esbuild@angular-architects/native-federation@angular/build@astrojs/partytown@astrolicious/studiocms@alloc/html-bundle@charlypoirier/uwebsocket-serve@cloudcommerce/ssr@cloudcommerce/storefront@adfinitas.fr/adfinitas-ui@codesoup/floating-menu@codesoup/scroll-to-top@darkfisk/ngx-awesome-uploader@darwishdev/dash-devunocsscraft@dumlj/cloudfs@gratrockstar/native-dialog-component@hankts/shopify-cli-kit@haysquare/svelte-multi-select@haysquare/svelte-multiselect@htmelt/plugin@henrikvilhelmberglund/vite-plugin-monkey@icetee/react-recaptcha-v3@ice/app@eki-group/svelvet@egomobile/swagger-proxy@esmkit/web-fetch@eslint/config-inspector@fork-fork/native-federation@gradio/video@laynezh/vite-plugin-lib-assets@nibbs66/buttons-pkg@nger/sirv@nberlette/worktop@enirisdev/angular-google-charts@dylan/static@mjackson/lazy-file@montoulieu/threads-api@ipseity/histoire@imba/op@hyrious/telegraph@hyrious/w7@junvary/quasar-ui-qcascader@oki.gg/unode@quilted/rollup@samlfair/sveltekit@object-studio/react-native-web@origyn-sa/mintjs@origyn/mintjs@pennajs/static-copy@remix-run/web-fetchmynancenative-federation-httpsmypluginlololivejs-sandboxolivejs-testnuxtpaginationspatepangdeui
2.0.1

4 months ago

2.0.0

2 years ago

1.0.1

3 years ago

1.0.0

4 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago