stargaze-studio/utils/getAssetType.ts

15 lines
710 B
TypeScript
Raw Normal View History

/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
2023-11-22 20:23:51 +00:00
export type AssetType = 'image' | 'audio' | 'video' | 'html' | 'document' | 'unknown'
export const getAssetType = (assetFileName: string): AssetType => {
const assetType = assetFileName?.toLowerCase().split('.').pop() || 'unknown'
2022-09-27 08:31:33 +00:00
if (assetType === 'png' || assetType === 'jpg' || assetType === 'jpeg' || assetType === 'svg' || assetType === 'gif')
return 'image'
if (assetType === 'mp3' || assetType === 'wav') return 'audio'
if (assetType === 'mp4') return 'video'
2023-01-24 06:48:50 +00:00
if (assetType === 'html') return 'html'
2023-11-22 20:23:51 +00:00
if (assetType === 'pdf') return 'document'
return 'unknown'
}