Skip to content
openpeepsPublic

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

A large database of MIME types
for 👑 Nim language

nimble install mimedb

API reference
Github Actions Github Actions

Note

This is a large database of mime types and information about them. It consists of a single, public JSON file and does not include any logic, allowing it to remain as un-opinionated as possible with an API.

😍 Key Features

  • Large database of MIME types
  • Simple API to get MIME type information
  • Lightweight and easy to use

Examples

The database loads automatically on import, no setup needed.

import mimedb
import std/options

# Extension to MIME type.
# Extensions work with or without a leading dot (case-insensitive)
assert getMimeType("html") == some("text/html")
assert getMimeType(".html") == some("text/html")
assert getMimeType("PNG") == some("image/png")
assert getMimeType(".png") == some("image/png")
assert getMimeType("unknownext") == none(string)

# Check if an extension or MIME type exists
assert isExtension("html")
assert isExtension(".html")
assert hasMimeType("text/html")
import mimedb
import std/options

# Get full info for a MIME type
let info = getMimeInfo("text/html")
assert info.isSome
assert info.getSource() == mimeSourceIana
assert info.isCompressible() == true
assert info.getExtensions() == some(@["html", "htm", "shtml"])
assert info.hasExtension("html")
assert info.hasExtension(".html") # leading dot also works
import mimedb
import std/options

let zip = getMimeInfo("application/zip")
assert zip.isSome
assert zip.getSource() == mimeSourceIana
assert zip.isCompressible() == false
assert zip.getExtensions() == some(@["zip"])
assert zip.hasExtension(".zip")

let audio = getMimeInfo("audio/mp4")
assert audio.hasExtension("m4a")
assert audio.hasExtension(".m4a")

This package is using the mime-db database.

❤ Contributions & Support

🎩 License

MIT license. Made by Humans from OpenPeeps.
Copyright OpenPeeps & Contributors — All rights reserved.

Releases

Packages

Contributors

Languages

Generated from openpeeps/pistachio