Move top-level functions to Signal.Util
This commit is contained in:
parent
5ec8b1c6e1
commit
c46e1a1519
7 changed files with 12 additions and 4 deletions
39
ts/util/GoogleChrome.ts
Normal file
39
ts/util/GoogleChrome.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import * as MIME from '../types/MIME';
|
||||
|
||||
interface MIMETypeSupportMap {
|
||||
[key: string]: boolean;
|
||||
}
|
||||
|
||||
// See: https://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support
|
||||
const SUPPORTED_IMAGE_MIME_TYPES: MIMETypeSupportMap = {
|
||||
'image/bmp': true,
|
||||
'image/gif': true,
|
||||
'image/jpeg': true,
|
||||
'image/svg+xml': true,
|
||||
'image/webp': true,
|
||||
'image/x-xbitmap': true,
|
||||
// ICO
|
||||
'image/vnd.microsoft.icon': true,
|
||||
'image/ico': true,
|
||||
'image/icon': true,
|
||||
'image/x-icon': true,
|
||||
// PNG
|
||||
'image/apng': true,
|
||||
'image/png': true,
|
||||
};
|
||||
|
||||
export const isImageTypeSupported = (mimeType: MIME.MIMEType): boolean =>
|
||||
SUPPORTED_IMAGE_MIME_TYPES[mimeType] === true;
|
||||
|
||||
const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = {
|
||||
'video/mp4': true,
|
||||
'video/ogg': true,
|
||||
'video/webm': true,
|
||||
};
|
||||
|
||||
// See: https://www.chromium.org/audio-video
|
||||
export const isVideoTypeSupported = (mimeType: MIME.MIMEType): boolean =>
|
||||
SUPPORTED_VIDEO_MIME_TYPES[mimeType] === true;
|
7
ts/util/index.ts
Normal file
7
ts/util/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import * as GoogleChrome from './GoogleChrome';
|
||||
import { missingCaseError } from './missingCaseError';
|
||||
|
||||
export { GoogleChrome, missingCaseError };
|
24
ts/util/missingCaseError.ts
Normal file
24
ts/util/missingCaseError.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* @prettier
|
||||
*/
|
||||
// `missingCaseError` is useful for compile-time checking that all `case`s in
|
||||
// a `switch` statement have been handled, e.g.
|
||||
//
|
||||
// type AttachmentType = 'media' | 'documents';
|
||||
//
|
||||
// const type: AttachmentType = selectedTab;
|
||||
// switch (type) {
|
||||
// case 'media':
|
||||
// return <ImageThumbnail/>;
|
||||
// case 'documents':
|
||||
// return <DocumentListEntry/>;
|
||||
// default:
|
||||
// return missingCaseError(type);
|
||||
// }
|
||||
//
|
||||
// If we extended `AttachmentType` to `'media' | 'documents' | 'links'` the code
|
||||
// above would trigger a compiler error stating that `'links'` has not been
|
||||
// handled by our `switch` / `case` statement which is useful for code
|
||||
// maintenance and system evolution.
|
||||
export const missingCaseError = (x: never): TypeError =>
|
||||
new TypeError(`Unhandled case: ${x}`);
|
Loading…
Add table
Add a link
Reference in a new issue