Socket
Socket
Sign inDemoInstall

node-mime-types

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

src/extensionsByMIMEType.js

7

CHANGELOG.md
# CHANGELOG
## 1.1.0 - delivery @20/05/2022
- update with the latest known MIME types
- update lib structure base and documentation
- change extensions and MIME types build
- add prettier
## 1.0.0 - delivery @15/10/2020
- first delivery

2

LICENSE.md
*node-mime-types* is released under the MIT license.
Copyright (C) 2020 Adrien Valcke
Copyright (C) 2022 Adrien Valcke

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "node-mime-types",
"version": "1.0.0",
"version": "1.1.0",
"author": "Adrien Valcke <adrienvalcke@icloud.com> (https://github.com/adrienv1520)",
"description": "A Node.js and zero-dependencies MIME type utility",
"bin": {},
"main": "lib/index.js",
"main": "src/index.js",
"scripts": {
"lint": "eslint lib/",
"pretest": "npm run lint",
"build": "node build/index.js",
"postbuild": "npm run format && npm run lint:fix",
"format": "prettier --write \"src/**/*.js\"",
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix",
"test": "mocha test/* --exit"

@@ -30,12 +33,14 @@ },

"files": [
"lib"
"src"
],
"dependencies": {},
"devDependencies": {
"chai": "~4.2.0",
"eslint": "~7.9.0",
"eslint-config-airbnb-base": "~14.2.0",
"eslint-plugin-import": "~2.22.0",
"mime-db": "~1.45.0",
"mocha": "~8.1.3"
"chai": "4.3.6",
"eslint": "8.15.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
"lodash": "4.17.21",
"mime-db": "1.52.0",
"mocha": "10.0.0",
"prettier": "2.6.2"
},

@@ -42,0 +47,0 @@ "private": false,

@@ -9,27 +9,35 @@ <p align="center">

# Table of Contents
# node-mime-types <!-- omit in toc -->
## Table of Contents <!-- omit in toc -->
- [Presentation](#presentation)
- [Installation](#installation)
- [Technical information](#technical-information)
- [Node.js](#nodejs)
- [Stack](#stack)
- [Code quality](#code-quality)
- [Tests](#tests)
- [Linting](#linting)
- [Unit](#unit)
- [Security](#security)
- [Usage](#usage)
- [Import module](#import-module)
- [getExtension(mimeType)](#getextensionmimetype)
- [getMIMEType(filenameOrPath)](#getmimetypefilenameorpath)
- [getExtension(mimeType)](#getextensionmimetype)
- [Code of Conduct](#code-of-conduct)
- [Contributing](#contributing)
- [Format](#format)
- [Linting](#linting)
- [Automatically fixing linting](#automatically-fixing-linting)
- [Test](#test)
- [Build](#build)
- [Support](#support)
- [Security](#security)
- [Licence](#licence)
- [Security](#security-1)
- [License](#license)
# Presentation
## Presentation
This library is powered by [mime-db](https://github.com/jshttp/mime-db) data. It provides a very simple, lightweight, safe yet speed utility to deal with MIME types and file extensions.
Supports **[1163 extensions](lib/mimetypesByExtension.js)** and **[947 MIME types](lib/extensionsByMIMEType.js)**.
Supports **[1180 file extensions](src/mimetypesByExtension.js)** and **[965 MIME types](src/extensionsByMIMEType.js)**.
# Installation
## Installation

@@ -40,33 +48,25 @@ `npm install node-mime-types`

# Technical information
## Technical information
## Node.js
### Stack
- Language: JavaScript ES6/ES7
- VM: Node.js >= Carbon (8.17.0)
- NodeJS >= 8.17.0
- NPM >=6.13.4
## Tests
### Code quality
Node.js >= Dubnium (10.22.1) could be required for some testing modules.
Code style follows [Airbnb JavaScript Best Practices](https://github.com/airbnb/javascript) using ESLint.
Command to run all tests:
### Tests
`npm test`
Uses Mocha and Chai for unit testing.
### Linting
### Security
ESLint with Airbnb base rules. See __<a href="https://github.com/airbnb/javascript" target="_blank">Airbnb JavaScript Style Guide</a>__.
- [Code security](https://docs.npmjs.com/packages-and-modules/securing-your-code) and most precisely module dependencies can be audited running `npm audit`.
`npm run test:lint`
## Usage
### Unit
### Import module
Mocha and Chai.
`npm run test:unit`
# Usage
## Import module
```javascript

@@ -77,4 +77,4 @@ const mime = require('node-mime-types');

const {
getExtension,
getMIMEType,
getExtension,
} = require('node-mime-types');

@@ -87,6 +87,40 @@ ```

## getMIMEType(filenameOrPath)
### 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*: `''`
<br/>
**Examples**:
```javascript
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;

@@ -101,2 +135,3 @@ - if a file name or path has no extension or an unknown extension, a default MIME type is returned;

**Examples**:
```javascript

@@ -120,46 +155,50 @@ getMIMEType(); // ''

## getExtension(mimeType)
Returns the file extension(s) based on the MIME type.
## Code of Conduct
**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*: `''`
This project has a [Code of Conduct](.github/CODE_OF_CONDUCT.md). By interacting with this repository, organization, or community you agree to abide by its terms.
<br/>
## Contributing
**Examples**:
```javascript
getExtension(); // ''
getExtension(false); // ''
getExtension(''); // ''
getExtension('application/unknown'); // ''
If you find any MIME type or file extension missing, please directly contribute to [mime-db](https://github.com/jshttp/mime-db).
getExtension('application/json5'); // '.json5'
getExtension('application/rtf'); // '.rtf'
Please take also a moment to read our [Contributing Guidelines](.github/CONTRIBUTING.md) if you haven't yet done so.
getExtension('text/plain'); // ['.txt', '.text', '.conf', '.def', '.list', '.log', '.in', '.ini']
getExtension('application/json'); // ['.json', '.map']
### Format
getExtension('IMAGE/PNG'); // '.png'
```
Uses `prettier` to format source code.
# Code of Conduct
This project has a [Code of Conduct](.github/CODE_OF_CONDUCT.md). By interacting with this repository, organization, or community you agree to abide by its terms.
`npm run format`
# Contributing
If you find any MIME type or file extension missing, please directly contribute to [mime-db](https://github.com/jshttp/mime-db).
### Linting
Please take also a moment to read our [Contributing Guidelines](.github/CONTRIBUTING.md) if you haven't yet done so.
`npm run lint`
# Support
### Automatically fixing linting
`npm run lint:fix`
### Test
`npm test`
### Build
Extensions by MIME type and MIME types by extension files.
NOTE:
- will [format](#format) `src` right after building files;
- will [automatically fix linting](#automatically-fixing-linting).
`npm run build`
## Support
Please see our [Support](.github/SUPPORT.md) page if you have any questions or for any help needed.
# Security
## Security
For any security concerns or issues, please visit our [Security Policy](.github/SECURITY.md) page.
# Licence
## License
[MIT](LICENSE.md).
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc