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

mimetype

v0.0.8

Published

A mime type catalog driven by filename extensions.

Downloads

18,753

Readme

build status mimetype-js

Overview

I find keep making these file extension lookup tables for mime types. It's about time I put it in a module to save me the trouble.

Examples

general case

	var mimetype = require('mimetype');
	
	console.log(mimetype.lookup("myfile.txt")); // Should display text/plain
	mimetype.set('.exotic', 'x-application/experimental'); // Add/update a mime type in the catalog
	console.log(mimetype.lookup("myfile.exotic")); // Should display x-application/experimental
	mimetype.del('.exotic'); // Removes the mime type from the catalog
	console.log(mimetype.lookup("myfile.exitoc")); // Should display false
	mimetype.forEach(function (ext, mime_type_string) {
		console.log(ext, mime_type_string); // Display the extension and matching mimetype in catalog
	});

Special cases

Sometimes detecting by filename extensions isn't work and you want to default to a general purposes mime-type (e.g. text/plain, application/octet-stream).

	var mimetype = require('mimetype');
	
	// This should display 0 (false)
	console.log(mimetype.lookup("filename.unknownMimeType");
	// This should display the string text/plain
	console.log(mimetype.lookup("filename.unknownMimeType", false, "text/plain");
	// This should display the string text/plain; charset=UTF-8
	console.log(mimetype.lookup("filename.unknownMimeType", "UTF-8", "text/plain");

Using mimetype.js with MongoDB Shell

While this was implemented as a NodeJS module it also works under MongoDB's shell. Instead of including with a "require" you would load the JavaScript file load-mimetype.js.

	load("./extras/load-mimetype.js");
	print("Check the mime type of test.txt:" + MimeType.lookup("test.txt"));

This would display something like-

	MongoDB shell version: 2.2.0
	connecting to: test
	> load("./extras/load-mimetype.js");
	> print("Check the mime type of test.txt: " + MimeType.lookup("test.txt"));
	Check the mime type of test.txt: text/plain
	>