mime-xdg
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i mime-xdg

Weekly Downloads

2

Version

1.2.4

License

MIT

Unpacked Size

514 kB

Total Files

20

Last publish

Collaborators

  • nk12