From fc12353bb838789a014f42cee70458c63dfe8955 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Mon, 9 Apr 2018 19:29:38 -0400 Subject: [PATCH] Add `Attachment.isVisualMedia` --- ts/types/Attachment.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 1e3d14e65..4f384d1c3 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -1,3 +1,6 @@ +import is from '@sindresorhus/is'; + +import * as GoogleChrome from '../GoogleChrome'; import { MIMEType } from './MIME'; @@ -16,4 +19,16 @@ export interface Attachment { // key?: ArrayBuffer; // digest?: ArrayBuffer; // flags?: number; -} +}; + +export const isVisualMedia = (attachment: Attachment): boolean => { + const { contentType } = attachment; + + if (is.undefined(contentType)) { + return false; + } + + const isSupportedImageType = GoogleChrome.isImageTypeSupported(contentType); + const isSupportedVideoType = GoogleChrome.isVideoTypeSupported(contentType); + return isSupportedImageType || isSupportedVideoType; +};