compile-mime-match
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');
mimeMatch('application/json; charset=utf-8');
mimeMatch('text/plain');
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');
mimeMatch('text/html');
mimeMatch('image/png');
*/subtype
Matches any MIME type will the given subtype
.
const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('*/xml');
mimeMatch('application/xml');
mimeMatch('text/xml');
mimeMatch('image/svg+xml');
*/*
Matches any valid MIME type.
const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('*/*');
mimeMatch('image/png');
mimeMatch('application/x-www-form-urlencoded');
mimeMatch('invalid');
mimeMatch('/');
+suffix
Matches any valid MIME type that ends with +suffix
.
const compileMimeMatch = require('compile-mime-match');
const mimeMatch = compileMimeMatch('+json');
mimeMatch('application/calendar+json');
mimeMatch('application/geo+json');
mimeMatch('application/json');
mimeMatch('invalid+json');
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');
mimeMatch('application/json; charset=utf-8');
mimeMatch('text/plain');
mimeMatch('text/html');
mimeMatch('image/png');