Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-mime-types

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mime-types

A Node.js and zero-dependencies MIME type utility

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-mime-types

A Node.js and zero-dependencies MIME type utility.

node-mime-types

Table of Contents

Presentation

This library is powered by mime-db data. It provides a very simple, lightweight, safe yet speed utility to deal with MIME types and file extensions.

Supports 1180 file extensions and 965 MIME types.

Installation

npm install node-mime-types

npm i -S node-mime-types

Technical information

Stack

  • NodeJS >= 8.17.0
  • NPM >=6.13.4

Code quality

Code style follows Airbnb JavaScript Best Practices using ESLint.

Tests

Uses Mocha and Chai for unit testing.

Security

  • Code security and most precisely module dependencies can be audited running npm audit.

Usage

Import module

const mime = require('node-mime-types');

// mime is an object of functions
const {
  getExtension,
  getMIMEType,
} = require('node-mime-types');

node-mime-types module exports an object of functions. You'll find the complete list of functions below.

  • mime <Object> with the following functions.

getExtension(mimeType)

Returns the file extension(s) based on the MIME type.

Note:

  • if a MIME type does not exist or is unknown, the empty string is returned;
  • if a MIME type has only one extension related to, a string is returned;
  • if a MIME type corresponds to multiple extensions, an array is returned;
  • supports MIME types in lower and upper case.
    • mimeType <String>
    • Returns: <String> | <Array> Default: ''

Examples:

getExtension(); // ''
getExtension(false); // ''
getExtension(''); // ''
getExtension('application/unknown'); // ''

getExtension('application/json5'); // '.json5'
getExtension('application/rtf'); // '.rtf'

getExtension('text/plain'); // ['.txt', '.text', '.conf', '.def', '.list', '.log', '.in', '.ini']
getExtension('application/json'); // ['.json', '.map']

getExtension('IMAGE/PNG'); // '.png'

getMIMEType(filenameOrPath)

Returns the MIME type based on the file name or path extension.

Note:

  • if a file name or path is not a string or is the empty string, the empty string is returned;
  • if a file name or path has no extension or an unknown extension, a default MIME type is returned;
  • supports extensions in lower and upper case.
    • filenameOrPath <String>
    • Returns: <String> Default: application/octet-stream

Examples:

getMIMEType(); // ''
getMIMEType([]); // ''
getMIMEType(''); // ''

getMIMEType('f'); // 'application/octet-stream'
getMIMEType('file.unknown'); // 'application/octet-stream'
getMIMEType('.js'); // 'application/octet-stream'

getMIMEType('file.html'); // 'text/html'
getMIMEType('file.css'); // 'text/css'
getMIMEType('/usr/file.json'); // 'application/json'
getMIMEType('/usr/file.json.txt'); // 'text/plain'
getMIMEType('C:\\file.JS'); // 'application/javascript'
getMIMEType('../../path/to/file-name.XML'); // 'text/xml'
getMIMEType('README.md'); // 'text/markdown'

Code of Conduct

This project has a Code of Conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

Contributing

If you find any MIME type or file extension missing, please directly contribute to mime-db.

Please take also a moment to read our Contributing Guidelines if you haven't yet done so.

Format

Uses prettier to format source code.

npm run format

Linting

npm run lint

Automatically fixing linting

npm run lint:fix

Test

npm test

Build

Extensions by MIME type and MIME types by extension files.

NOTE:

npm run build

Support

Please see our Support page if you have any questions or for any help needed.

Security

For any security concerns or issues, please visit our Security Policy page.

License

MIT.

Keywords

FAQs

Package last updated on 07 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc