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

mime-lookup

v0.0.2

Published

A utility library for dealing with mime-types

Downloads

136,534

Readme

mime-lookup

Comprehensive MIME type mapping API based on broofa/node-mime module.

License

Difference from node-mime

  1. This module does not include a mime type database. Either supply your own, as described below, or include mime-db.
  2. No command line tool. Since no mime types are included this is not possible using this API only module.
  3. Mime.prototype.load has been removed to avoid dependency on Node File System.
  4. Added 'glob' function to expand mime patterns by APIs-guru.

Install

Install with npm (mime-db is optional):

npm install mime-lookup mime-db

mine-db is optional and only needed it you wish to use the mime-db mime-type database.

Contributing / Testing

npm test

API

MimeLookup(db)

This module does not include the mime types database. Either supply your own or include the mime-db. Construct a new mime type lookup service by supplying a mime type database.

Using mime-db

var MimeLookup = require('mime-lookup');
var mime = new MimeLookup(require('mime-db'));

Using your own types

var MimeLookup = require('mime-lookup');
var mime = new MimeLookup(yourDb);

The mime-type database can be formatted two ways:

Simple

{
    "text/x-some-format": ["x-sf", "x-sft", "x-sfml"],
    "application/x-my-type": ["x-mt", "x-mtt"]
}

Like mime-db

{
  "text/x-some-format": {
    "source": "iana",
    "extensions": ["x-sf", "x-sft", "x-sfml"]
  },
  "application/x-my-type": {
    "source": "apache",
    "extensions": ["x-mt", "x-mtt"]
  }
}

Note in this case only the "extensions" property is used

mime.lookup(path)

Get the mime type associated with a file, if no mime type is found application/octet-stream is returned. Performs a case-insensitive lookup using the extension in path (the substring after the last '/' or '.'). E.g.

mime.lookup('file.txt');                  // => 'text/plain'
mime.lookup('.TXT');                      // => 'text/plain'
mime.lookup('htm');                       // => 'text/html'

mime.default_type

Sets the mime type returned when mime.lookup fails to find the extension searched for

mime.extension(type)

Get the default extension for type

mime.extension('text/html');                 // => 'html'
mime.extension('application/octet-stream');  // => 'bin'

mime.charsets.lookup()

Map mime-type to charset

mime.charsets.lookup('text/plain');        // => 'UTF-8'

mime.define()

Add additional custom mime/extension mappings

mime.define({
    'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
    'application/x-my-type': ['x-mt', 'x-mtt'],
    // etc ...
});

mime.lookup('x-sft');                 // => 'text/x-some-format'

The first entry in the extensions array is returned by mime.extension(). E.g.

mime.extension('text/x-some-format'); // => 'x-sf'

Acknowledgements

This code is based on broofa/node-mime with additions from APIs-guru.

License

Original work Copyright (c) 2010 Benjamin Thomas, Robert Kieffer Modified work Copyright 2015 Jayson Harshbarger

MIT License