carltonf / freedesktop-shared-mime

Nodejs package to use freedesktop shared MIME Info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

freedesktop-shared-mime

Node MIME library uses FreeDesktop shared-mime-info as database.

FreeDesktop Shared MIME Info

FreeDesktop shared mime info contains a large number of common MIME types, created by converting the existing KDE and GNOME databases to the new format and merging them together. This database is more suitable for nodejs desktop applications.

This package’s building process converts freedesktop.org.xml.in to a JSON data file.

Main Features/Differences

Many more file types are supported

FreeDesktop Shared MIME Info database seem to be larger than IANA standards, include script files like Ruby, Python and many others.

No =Charsets= info are available

The freedesktop spec doesn’t seem to have these information.

Directories and some other special file types are supported

Use lstat, the following special file types are also supported

  • “inode/directory”
  • “inode/blockdevice”
  • “inode/chardevice”
  • “inode/symlink”
  • “inode/fifo”
  • “inode/socket”

lookup is used for file names exclusively

mime-type works for extension without leading dot, like

mime_type.lookup("html");  // "text/html"

but

shared_mime.lookup("html"); // false

The idea is that lookup should mainly be used to determine the file type according to file’s extension. Under such considerations, “html” is a file without any extension, even though it has a name like some valid extension. This change avoids the following issue:

shared_mime.lookup("/home/me/Desktop");  // "inode/directory" not "application/x-desktop"

Two-part extensions are also supported.

shared_mime.lookup("some.pdf.gz")  // "application/x-gzpdf"

but only two-part extensions

shared_mime.lookup("some.vm.pdf.gz") // "application/x-gzpdf"

Install

npm install freedesktop-shared-mime

Usage

The library interface is similar to mime-types, with freedesktop-specific features like:

var shared_mime = require('freedesktop-shared-mime')

shared_mime.lookup(".")         // "inode/directory"
shared_mime.lookup("nonexistent_dir/") // "inode/directory"

shared_mime.aliases("text/x-gettext-translation") // ["text/x-po", "application/x-gettext"]

shared_mime.supertype("application/epub+zip")         // "application/zip"

shared_mime.comment("application/x-jbuilder-project") // "JBuilder project"

shared_mime.generic_icon("application/rss+xml") // "text-html"

Remainings

Better README

Do we have to use md format?

tests

use Istanbul or others for coverage tests.

About

Nodejs package to use freedesktop shared MIME Info

License:MIT License


Languages

Language:JavaScript 100.0%