# @remix-run/mime

> Utilities for working with MIME types

Latest version **1.0.0** (published 2026-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @remix-run/mime
pnpm add @remix-run/mime
yarn add @remix-run/mime
bun add @remix-run/mime
```

## Health

**Score 70/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-10-01 |
| First published | 2025-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 120.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 33455 |
| Author | Michael Jackson |
| Maintainers | mjackson |
| Keywords | mime, mime-type, media-type, content-type, compressible |

## Links

- npm: https://www.npmjs.com/package/@remix-run/mime
- Repository: https://github.com/remix-run/remix
- Homepage: https://github.com/remix-run/remix/tree/main/packages/mime#readme
- Issues: https://github.com/remix-run/remix/issues
- npm.io page: https://npm.io/package/@remix-run/mime

## Recent versions

- 1.0.0 (latest) — 2026-10-01
- 0.4.3 — 2026-09-28
- 0.4.2 — 2026-07-01
- 0.4.1 — 2026-04-29
- 0.4.0 — 2026-02-28
- 0.3.0 — 2026-01-20
- 0.2.0 — 2025-12-18
- 0.1.0 — 2025-11-25
- 0.0.0 — 2025-11-25

## README

# mime

MIME type detection and content-type helpers for Remix. This package maps extensions to MIME types and provides utilities for charset and compressibility checks.

## Features

- **MIME Detection** - Detect MIME types from extensions and filenames
- **Content-Type Helpers** - Build `Content-Type` values with charset handling
- **Compression Signals** - Check whether a media type is likely compressible
- **Generated Data** - Built from [mime-db](https://github.com/jshttp/mime-db)

## Installation

```sh
npm i remix
```

## Usage

### `detectMimeType(extension)`

Detects the MIME type for a given file extension or filename.

```ts
import { detectMimeType } from 'remix/mime'

detectMimeType('txt') // 'text/plain'
detectMimeType('.txt') // 'text/plain'
detectMimeType('file.txt') // 'text/plain'
detectMimeType('path/to/file.txt') // 'text/plain'
detectMimeType('unknown') // undefined
```

### `detectContentType(extension)`

Detects the Content-Type header value for a given file extension or filename, including `charset` for text-based types. See [`mimeTypeToContentType`](#mimetypetocontenttypemimetype) for charset logic.

```ts
import { detectContentType } from 'remix/mime'

detectContentType('css') // 'text/css; charset=utf-8'
detectContentType('.json') // 'application/json; charset=utf-8'
detectContentType('image.png') // 'image/png'
detectContentType('path/to/file.unknown') // undefined
```

### `isCompressibleMimeType(mimeType)`

Checks if a MIME type is known to be compressible.

```ts
import { isCompressibleMimeType } from 'remix/mime'

isCompressibleMimeType('text/html') // true
isCompressibleMimeType('application/json') // true
isCompressibleMimeType('image/png') // false
isCompressibleMimeType('video/mp4') // false
```

For convenience, the function also accepts a full Content-Type header value:

```ts
import { isCompressibleMimeType } from 'remix/mime'

isCompressibleMimeType('text/html; charset=utf-8') // true
isCompressibleMimeType('application/json; charset=utf-8') // true
isCompressibleMimeType('image/png; charset=utf-8') // false
isCompressibleMimeType('video/mp4; charset=utf-8') // false
```

### `mimeTypeToContentType(mimeType)`

Converts a MIME type to a Content-Type header value, adding `; charset=utf-8` to text-based MIME types: `text/*` (except `text/xml` which has built-in encoding declarations), `application/json`, `application/javascript`, and all `+json` suffixed types. All other types are returned unchanged.

```ts
import { mimeTypeToContentType } from 'remix/mime'

mimeTypeToContentType('text/css') // 'text/css; charset=utf-8'
mimeTypeToContentType('application/json') // 'application/json; charset=utf-8'
mimeTypeToContentType('application/ld+json') // 'application/ld+json; charset=utf-8'
mimeTypeToContentType('image/png') // 'image/png'
```

### `defineMimeType(definition)`

Registers or overrides a MIME type for one or more file extensions.

```ts
import { defineMimeType, detectMimeType } from 'remix/mime'

defineMimeType({
  extensions: ['myformat'],
  mimeType: 'application/x-myformat',
})

defineMimeType({
  extensions: ['be.pit'],
  mimeType: 'application/x-be-pit-document',
})

detectMimeType('filename.be.pit') // 'application/x-be-pit-document'
```

You can also optionally configure the charset and whether the MIME type is compressible:

```ts
defineMimeType({
  extensions: ['myformat'],
  mimeType: 'application/x-myformat',
  compressible: true,
  charset: 'utf-8',
})
```

## License

MIT

---
_Source: https://npm.io/package/@remix-run/mime · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
