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

mime-xdg

v1.2.4

Published

mimetypes, mimeheads and mimenotes from xdg/shared-mime-info

Downloads

9

Readme

mime-xdg

mimetypes, mimeheads and mimenotes from xdg/shared-mime-info

Note

This library contains mime types from two sources:

In addition to this, there are top-level types (mime heads) and mime descriptions (mime notes).

All mime types and their descriptions are contained in an optimized form. Therefore, the library does not weigh so much.

Library | Size** | Mimetypes | Extensions --- | --- | --- | --- mime-db (mime-types) | 136.8 KB | 2279 | 1180 mime | 36.6 KB | 956 | 1173 mime-xdg* | 48.7 KB | 1559 | 1619

* without mime-xdg/heads and mime-xdg/notes

** minified bundle size (current size, not .gz)

Usage

mimeType

Basic library with all mime types

// FUNCTIONS
import { ext, extname, mimeType, mimeList } from 'mime-xdg'

/**
  * 1. ext
  */
// returns the extname if it is in the EXTENSIONS or empty string
ext('src/test.js') // => 'js'
ext('app\\test.foobar') // => '' - empty string
ext('test.abw.CRASHED') // => 'abw.CRASHED' - because it exists exactly in this form
ext('test.abw.crashed') // => ''

/**
  * 2. extname
  */
// works the same way as 'extname' from 'node:path', but
// returns the extname if it is in the EXTENSIONS or find it herself
extname('/tm') // => ''
extname('/.tm/') // => ''
extname('/.tm/test.foobar') // => '.foobar'
extname('test.abw.CRASHED') // => '.abw.CRASHED'
extname('test.abw.crashed') // => '.crashed'

/**
  * 3. mimeType
  */
// returns the mime type or empty string
mimeType('test.foobar') // => ''
mimeType('/.js/js') // => ''
mimeType('src/test.js') // => 'text/javascript'
mimeType('src\\test.JS') // => 'text/javascript'
mimeType('foobar/.pdf') // => 'application/pdf'
// but, in the schema 'shared-mime-info', sometimes the register matters:
mimeType('test.c') // => text/x-c
mimeType('test.C') // => text/x-c++src
// I do not know if this is right or not,
// but I think the Linux developers know better

/**
  * 4. mimeList
  */
// returns an array of all mime types
mimeList('src/test.js') // => ↴
["text/javascript", "application/x-javascript", "application/javascript"]
// This is a copy from EXTENSIONS. It can be safely changed
mimeList('.jpg') // => ↴
mimeList('.jpeg') // => ↴
['image/jpeg', 'image/pjpeg']
mimeList('test.foobar') // => []

// OBJECTS
import { EXTENSIONS } from 'mime-xdg'
// You can change them yourself, add, delete, or reverse the order mimetypes

/**
  * 1. EXTENSIONS
  */
console.log(EXTENSIONS)
// EXTENSIONS equal to:
{
  "602": [
    "application/x-t602"
  ],
  "7z.001": [
    "application/x-7z-compressed"
  ],
  "svg.gz": [
    "image/svg+xml-compressed"
  ],
  "aw": [
    "application/applixware",
    "application/x-applix-word"
  ],
  /* etc... */
}

mimeHead

Many mime types have their own main mime type

// FUNCTION
import { mimeHead } from 'mime-xdg/heads'

/**
  * 1. mimeHead
  */
// returns main mime type or empty string
mimeHead('foobar') // => '' - empty string
mimeHead('text/javascript') // => 'application/ecmascript'
mimeHead(mimeType('.c')) // => 'text/plain'


// OBJECT
import {  MIME_HEADS } from 'mime-xdg/heads'

/**
  * 1. MIME_HEADS
  */
console.log(MIME_HEADS)
// MIME_HEADS equal to:
{
  "message/rfc822": "text/plain",
  "font/otf": "font/ttf",
  "video/x-theora+ogg": "video/ogg",
  "video/x-theora": "video/ogg",
  /* etc... */
}

mimeNote

some mime types have a short description

// FUNCTION
import { mimeNote } from 'mime-xdg/notes'
/**
  * 1. mimeNote
  */
// returns note or empty string
mimeNote('foobar') // => '' - empty string
mimeNote('text/javascript') // => 'JavaScript program'
mimeNote(mimeType('.pdf')) // => 'PDF document'


// OBJECT
import { MIME_NOTES } from 'mime-xdg/notes'
/**
  * 1. MIME_NOTES
  */
console.log(MIME_NOTES)
// MIME_NOTES equal to:
{
  "flv-application/octet-stream": "Flash video",
  "message/rfc822": "email message",
  "font/woff2": "WOFF2 font",
  "font/woff": "WOFF font",
  /* etc... */
}

License

MIT