(filename: string)
| 113 | * @returns {string} The normalized extension (lowercase, without dot) or empty string |
| 114 | */ |
| 115 | const extractFileExtension = (filename: string): string => { |
| 116 | const filenameParts = filename.split('.') |
| 117 | if (filenameParts.length <= 1) { |
| 118 | return '' |
| 119 | } |
| 120 | let ext = filenameParts.pop()!.toLowerCase() |
| 121 | // Normalize common extension variations to match MIME type mappings |
| 122 | const extensionNormalizationMap: { [key: string]: string } = { |
| 123 | jpeg: 'jpg', // image/jpeg and image/jpg both map to 'jpg' |
| 124 | tif: 'tiff', // image/tiff and image/tif both map to 'tiff' |
| 125 | oga: 'ogg' // audio/ogg and audio/oga both map to 'ogg' |
| 126 | } |
| 127 | ext = extensionNormalizationMap[ext] ?? ext |
| 128 | return ext |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Validates that file extension matches the declared MIME type |
no outgoing calls
no test coverage detected