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

compile-mime-match

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compile-mime-match

Compiles a function that matches a given MIME type.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

compile-mime-match

Build Status Coverage Status

Compiles a function that matches a given MIME type. A faster alternative to type-is for when the MIME type is known ahead of time.

Installation

// npm
npm install compile-mime-match --save

// yarn
yarn add compile-mime-match

Usage

const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('application/json');

mimeMatch('application/json'); // true
mimeMatch('application/json; charset=utf-8'); // true

mimeMatch('text/plain'); // false

Input Formats

type/subtype

Matches exactly the given MIME type (see the example above).

type/*

Matches any MIME type will the given type.

const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('text/*');

mimeMatch('text/plain'); // true
mimeMatch('text/html'); // true

mimeMatch('image/png'); // false
*/subtype

Matches any MIME type will the given subtype.

const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('*/xml');

mimeMatch('application/xml'); // true
mimeMatch('text/xml'); // true

mimeMatch('image/svg+xml'); // false
*/*

Matches any valid MIME type.

const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('*/*');

mimeMatch('image/png'); // true
mimeMatch('application/x-www-form-urlencoded'); // true

mimeMatch('invalid'); // false
mimeMatch('/'); // false
+suffix

Matches any valid MIME type that ends with +suffix.

const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('+json');

mimeMatch('application/calendar+json'); // true
mimeMatch('application/geo+json'); // true

mimeMatch('application/json'); // false
mimeMatch('invalid+json'); // false
Array

compile-mime-match also accepts an array of strings to match multiple types at the same time:

const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch(['application/json', 'text/*']);

mimeMatch('application/json'); // true
mimeMatch('application/json; charset=utf-8'); // true
mimeMatch('text/plain'); // true
mimeMatch('text/html'); // true

mimeMatch('image/png'); // false

Keywords

FAQs

Package last updated on 24 Mar 2018

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