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

@goa/mime-types

v1.1.0

Published

[Fork] The Ultimate Javascript Content-Type utility Written In ES6 And Optimised With JavaScript Compiler.

Downloads

61

Readme

@goa/mime-types

npm version

@goa/mime-types is the Fork of The Ultimate Javascript Content-Type utility Written In ES6 And Optimised With JavaScript Compiler. Depends on the mime-db which was not bundled to allow direct upgrades of the database.

The original module has been updated to be used in @goa/koa: Koa web server compiled with Google Closure Compiler using Depack into a single file library (0 dependencies).

yarn add @goa/mime-types

Table Of Contents

API

The package is available by importing its default function:

import { lookup, contentType, extension, charset, types } from '@goa/mime-types'

All functions return false if input is invalid or not found.

lookup(  path: string,): string

Lookup the content-type associated with a file.

import { lookup } from '@goa/mime-types'

console.log(lookup('json'))
console.log(lookup('.md'))
console.log(lookup('file.html'))
console.log(lookup('folder/file.js'))
console.log(lookup('folder/.htaccess'))

console.log(lookup('cats'))
application/json
text/markdown
text/html
application/javascript
false
false

contentType(  type: string,): string

Create a full content-type header given a content-type or extension. When given an extension, mime.lookup is used to get the matching content-type, otherwise the given content-type is used. Then if the content-type does not already have a charset parameter, mime.charset is used to get the default charset and add to the returned content-type.

import { contentType } from '@goa/mime-types'
import { extname } from 'path'

console.log(contentType('markdown'))
console.log(contentType('file.json'))
console.log(contentType('text/html'))
console.log(contentType('text/html; charset=iso-8859-1'))

// from a full path
console.log(contentType(extname('/path/to/file.json')))
text/markdown; charset=utf-8
application/json; charset=utf-8
text/html; charset=utf-8
text/html; charset=iso-8859-1
application/json; charset=utf-8

extension(  type: string,): string

Get the default extension for a content-type.

import { extension } from '@goa/mime-types'

console.log(extension('application/octet-stream'))
bin

charset(  type: string,): string

Lookup the implied default charset of a content-type.

import { charset } from '@goa/mime-types'

console.log(charset('text/markdown'))
UTF-8

types

A map of content-types by extension.

import { types } from '@goa/mime-types'

console.log(types['json'])
application/json

extensions

A map of extensions by content-type.

import { extensions } from '@goa/mime-types'

console.log(extensions['application/mp4'])
[ 'mp4s', 'm4p' ]

Copyright

Original Work by Jonathan Ong, Douglas Christopher Wilson.