Skip to content

robert8888/mime-file-extension

Repository files navigation

mime-file-extension

This library solving problem of file extension for concrete mime types and vice versa.

Install

npm install mime-file-extension

Methods

  • getFileExtensions(mimeType, full)

    mimeType - String representing mime type eg: "audio/ogg" full - Boolean - if true return value contains dot at the beginning[".jpeg", ".jpg", ".jpe"]

  • getMimeType(extension)

    extension - String representing file extension with or without dot at the beginning

Usage

const mfe = require("mime-file-extension");

console.log(mfe.getFileExtensions("text/csv")) // ["csv"]
console.log(mfe.getFileExtensions("audio/ogg")) // ["oga","ogg","spx"]
console.log(mfe.getFileExtensions("image/jpeg", true)) // [".jpeg", ".jpe", ".jpg"]

console.log(mfe.getMimeType("gif")) // "image/gif"
console.log(mfe.getMimeType("m2a")) // "audio/mpeg"
console.log(mfe.getMimeType("m3a")) // "audio/mpeg"
console.log(mfe.getMimeType(".mp3")) // "audio/mpeg"

Missing format ?

Post your request under Missing format

Changelog

  • 2.0
    • move to typescript implementation
    • adding typescript linting
    • redefine building types map json - prebuild scripts
    • adding new mimetypes

About

File extensions for mime type and vice versa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published