CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mime

A comprehensive library for mime-type mapping

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

MIME

MIME is a comprehensive library for MIME type mapping that enables developers to determine file types based on extensions and vice versa. It offers a complete database of MIME types (800+ types, 1,000+ extensions) with both full and lite versions, supports TypeScript with built-in type definitions, and provides both programmatic API and command-line interface.

Package Information

  • Package Name: mime
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install mime

Core Imports

import mime from "mime";
import { Mime } from "mime";

For lite version (without unofficial types):

import mime from "mime/lite";
import { Mime } from "mime/lite";

CommonJS (not recommended, use ESM):

const mime = require("mime");
const { Mime } = require("mime");

Basic Usage

import mime from "mime";

// Get MIME type from file path or extension
const type = mime.getType("script.js");           // "text/javascript"
const type2 = mime.getType("data.json");          // "application/json"

// Get default extension from MIME type
const ext = mime.getExtension("text/plain");      // "txt"
const ext2 = mime.getExtension("image/jpeg");     // "jpeg"

// Get all extensions for a MIME type (new in v4)
const extensions = mime.getAllExtensions("image/jpeg"); // Set(3) { "jpeg", "jpg", "jpe" }

Architecture

MIME is built around several key components:

  • Immutable Default Instances: Pre-configured, frozen instances with comprehensive MIME type databases
  • Custom Mutable Instances: Mime class allowing custom type definitions and modifications
  • Type Database Variants: Full version (all types) and lite version (standard types only)
  • ESM-First Design: Modern ES module architecture with TypeScript support
  • Command-Line Interface: Built-in CLI for shell scripting and automation

Capabilities

MIME Type Resolution

Core functionality for resolving MIME types from file paths and extensions, with robust path handling and null-safe operations.

function getType(path: string): string | null;

MIME Type Operations

Custom MIME Instances

Create and configure custom MIME instances with your own type definitions, perfect for specialized applications or custom file types.

class Mime {
  constructor(...args: TypeMap[]);
  define(typeMap: TypeMap, force?: boolean): this;
  getType(path: string): string | null;
  getExtension(type: string): string | null;
  getAllExtensions(type: string): Set<string> | null;
}

type TypeMap = { [key: string]: string[] };

Custom MIME Instances

Command Line Interface

Shell interface for MIME type operations, supporting both type-to-extension and extension-to-type lookups.

mime script.js                    # Returns: text/javascript
mime -r image/jpeg               # Returns: jpeg

Command Line Interface

Type Definitions

type TypeMap = { [key: string]: string[] };

interface MimeInstance {
  getType(path: string): string | null;
  getExtension(type: string): string | null;
  getAllExtensions(type: string): Set<string> | null;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/mime@4.0.x
Publish Source
CLI
Badge
tessl/npm-mime badge