determine-mediatype
v1.0.0
Published
By mimetype of the file to determine what type of media it is
Downloads
2
Readme
determine-mediatype
By mimetype of the file to determine what type of media it is
Installation
NPM
$ npm install determine-mediatype --save
Yarn
$ yarn add determine-mediatype
Usage
Node
const { DetermineMediatype, MediaType } = require("determine-mediatype");
let mediaType = DetermineMediatype.determine('image/png');
console.log(mediaType === MediaType.IMAGE);
// output: true
mediaType = DetermineMediatype.determine('video/mp4');
console.log(mediaType === MediaType.VIDEO);
// output: true
console.log(DetermineMediatype.isImage('image/png'));
// output: true
TypeScript
import { DetermineMediatype, MediaType } from 'determine-mediatype';
let mediaType: MediaType = DetermineMediatype.determine('image/png');
console.log(mediaType === MediaType.IMAGE);
// output: true
mediaType = DetermineMediatype.determine('video/mp4');
console.log(mediaType === MediaType.VIDEO);
// output: true
console.log(DetermineMediatype.isImage('image/png'));
// output: true
MediaType
export enum MediaType {
UNKNOWN = 0,
IMAGE,
AUDIO,
VIDEO,
TEXT,
FONT,
APPLICATION,
MESSAGE,
MODEL,
MULTIPART,
}
API
isImage(mimetype: string): boolean
isAudio(mimetype: string): boolean
isVideo(mimetype: string): boolean
isText(mimetype: string): boolean
isFont(mimetype: string): boolean
isApplication(mimetype: string): boolean
isMessage(mimetype: string): boolean
isModel(mimetype: string): boolean
isMultipart(mimetype: string): boolean
isBMP(mimetype: string): boolean
isPNG(mimetype: string): boolean
isGIF(mimetype: string): boolean
isJPG(mimetype: string): boolean
isSVG(mimetype: string): boolean
isExcel(mimetype: string): boolean
isPlainText(mimetype: string): boolean
isCSS(mimetype: string): boolean
isHTML(mimetype: string): boolean
isJS(mimetype: string): boolean
Benchmark
DetermineMediatype.determine('image/png');
DetermineMediatype#test x 139,655 ops/sec ±0.33% (92 runs sampled)