1.2.3 • Published 7 months ago

mime-xdg v1.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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.

LibrarySize**MimetypesExtensions
mime-db (mime-types)136.8 KB22791180
mime36.6 KB9561173
mime-xdg*48.7 KB15591619

* 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

1.2.3

7 months ago

1.2.2

7 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

2 years ago

1.1.4

1 year ago

1.1.3

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.0.0

2 years ago