npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mimisbrunnr

v1.0.1

Published

Highly tested means of resolving a file and extension to its respective MIME type.

Downloads

13

Readme

mimisbrunnr

This npm module is used to resolve files with extensions (or file extensions by themselves) into their respective MIME types. It solves the same problem as the following modules:

The thing that is different with this module from the previouslu mentioned ones is its implementation. Whilst we theoretically could go all day arguing as to which module is implemented in the best manner, it only ever comes down to which module you prefer to use.

Mímisbrunnr is the well associated with the being Mímir, whose name in Swedish is Mimer, which in turn contains the word mime. As such, you can clearly see, mimisbrunnr is the perfect most obvious name for a module managing MIME types.

Installation

npm install mimisbrunnr

Usage

First and foremost, you need to require mimisbrunnr:

const mime = require('mimisbrunnr').mime

mime is a function that, when called with a string representing a file with an extension (or a file extension without a file name), resolves to a MIME type:

console.log(mime('file.txt')) // Output: text/plain
console.log(mime('minecraft.jar')) // Output: application/java-archive
console.log(mime('hello.js')) // Output: application/javascript

console.log(mime('.txt')) // Output: text/plain
console.log(mime('.jar')) // Output: application/java-archive
console.log(mime('.js')) // Output: application/javascript

/* The following is viewed as a file without an extension, as such we might wish 
 * to handle it differently:
 */
console.log(mime('txt')) // Output: null

/* The following is an unrecognized file extension. As such, we might wish to 
 * handle that differently too:
 */
console.log(mime('.whitepowderandsnuffbecomesgrey')) // Output: null

As you can tell, anything that is unrecognized will similarly to the mime-types module, return something that we can handle further: in the case of this module, anything that is unrecognized returns null.

let mimeType = mime('.whitepowderandsnuffbecomesgrey') || 'text/plain'

License

This module, and the code therein, is licensed under MIT.