Motivation
MimeMatcher is very simple library for checking if mime type string is in allowed range.
You can also match mime types against wildcards, like */*
or 'application/*'
Instalation
You can install it from npm:
npm install mime-matcher --save
Or you can download mime-matcher.min.js
from the dist folder and then include it in html file:
Usage
const matcher = 'image/gif' matcher //truematcher //false
You can also use wildcards:
'image/*' //true'*/*' //true
You can also use multiple mime types to match against:
const matcher = 'image/*' 'text/*' matcher //truematcher //truematcher //false
Optional mime type parameter is ignored:
const matcher = 'text/xml' matcher //true
You can also use higher-order function matcher
, which accepts expected types and returns another function, which you can use for matching:
const m = //true "image/gif" //true
There is also function parse
which returns object containing data of parsed mime-type:
/*{ valid: true type: "application", subType: "json"}*/ /*{ valid: true type: "text", subType: "xml", parameter: "encoding=utf-8"}*/ /*{ valid: false}*/
You can also import function isValid
as shorthand for checking validity:
//true