isValidMime
Returns true if the string corresponds to a valid MIME type.
Summary
About
I created this package to have a straight forward way to check if a MIME type is valid in my code.
Note that if you do not want to pull a dependency, here is how you can do it without this package:
; ; if mimeType in mimeDb else
This package provides its own Typescript definition.
Features
- Returns true if the mime passed in parameter is valid, else returns false
Requirements
NPM or Yarn installed on your machine.
Installation
Using NPM
npm install is-valid-mime
Using Yarn
yarn add is-valid-mime
Examples
1. Getting started
In this example, you will see how to check if a variable is a valid mime type.
; const mimeType = "cats"; if console; else console;
2. Catch errors
In this example, you will see how to catch errors that are thrown by this function.
; const mimeType = 42;let valid = false; try valid = ; catch exception if exception instanceof TypeError console; else console; if valid console; else console;
API
Exceptions
TypeError
: if the first parameter is not a string.