JSPM

@remix-run/mime

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4572
  • Score
    100M100P100Q123109F
  • License MIT

Utilities for working with MIME types

Package Exports

  • @remix-run/mime
  • @remix-run/mime/package.json

Readme

@remix-run/mime

Utilities for working with MIME types.

Data used for these utilities is generated at build time from mime-db, but only includes standard MIME types, Experimental (x-) and vendor-specific (vnd.) MIME types have been excluded.

Installation

npm install @remix-run/mime

Usage

detectMimeType(extension)

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

import { detectMimeType } from '@remix-run/mime'

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

isCompressibleMimeType(mimeType)

Checks if a MIME type is known to be compressible.

import { isCompressibleMimeType } from '@remix-run/mime'

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

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

import { isCompressibleMimeType } from '@remix-run/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

License

MIT