Skip to main content

mimetypes

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
3 months ago (1.0.3)

Mime Lookup

Example 1

fetch MIME informations about js

import * as Mime from 'jsr:@geacko/deno-mimetypes'

const {
    type,
    isCompressible,
    isUtf8
} = Mime.lookup(`js`)!

console.log(`Content-Type: ${type}${isUtf8 ? `; charset=UTF-8` : ``}`)

if (isCompressible) {
    console.log(`Content-Encoding: gzip`)
}

// output: 
// "Content-Type: text/javascript; charset=UTF-8"
// "Content-Encoding: gzip"

Example 2

fetch extensions associated with text/javascript

import * as Mime from 'jsr:@geacko/deno-mimetypes'

const extensions 
    = Mime.extensionsFromMimetype(`text/javascript`) ?? []

for (const ext of [`txt`, `js`, `css`]) {
    console.log(ext + ` > ` + extensions.includes(ext))
}

// output:
// "txt > false"
// "js > true"
// "css > false"

Add Package

deno add @geacko/mimes

Import symbol

import * as mod from "@geacko/mimes";

Add Package

npx jsr add @geacko/mimes

Import symbol

import * as mod from "@geacko/mimes";

Add Package

yarn dlx jsr add @geacko/mimes

Import symbol

import * as mod from "@geacko/mimes";

Add Package

pnpm dlx jsr add @geacko/mimes

Import symbol

import * as mod from "@geacko/mimes";

Add Package

bunx jsr add @geacko/mimes

Import symbol

import * as mod from "@geacko/mimes";