1.0.1 • Published 3 years ago

mimetypes-wildcard v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

mimetypes-wildcard

mimetypes-wildcard is a library that checks if a subtype MIME exists in a main MIME type. For example, this library can be used if your server has a wildcard (*) for what mime-types it accepts.

Types and Subtypes

A MIME type is a string that shows what type of file the thing is. For example, an MP4 file would have the video/mp4 MIME type. The 'video' on the video/mp4 MIME type is the type. The type is the main thing that describes a file. An MP4 file is a video, so the main type is a video. A subtype describes what type of file it is. An MP4 file is a video with the mp4 file type; so the MIME type would be video/mp4.

API

Validator(type) contructor

The Validator constructor is a constructor that takes a type and has a function that returns true or false if a MIME exists.

new Validator(type)

Example

const video = new Validator('video')
// the video var has a validate() function on it

validate(subtype)

The validate() function returns a boolean type when you give it a subtype. You can use this function to check if the subtype MIME exists under the main type MIME.

Example

const video = new Validator('video')
const check = video.validate('mp4')
// The check var returns true since the mp4 subtype exists under the video type. That would be video/mp4.

Executable Example in Node.js

const { default: Validator } = require("mimetypes-wildcard");
// This stores the Validator object into the video var
const video = new Validator('video')
// This stores the boolean value from the validator
const validate = video.validate('mp4')
// This should print true since the mp4 subtype exists under the video type.
console.log(validate)