Skip to content

API Reference


API Reference / @dasch-ng/web-utils / fileTypeOf

Function: fileTypeOf() ​

fileTypeOf(file): FileType | null

Defined in: file-type.ts:25

Classifies a file by the extension of its name (or a File), e.g. to pick an icon. Returns null for unknown extensions. The extension says nothing about the content; do not use it as a security check.

Parameters ​

file ​

string | { name: string; } | null | undefined

Returns ​

FileType | null

Example ​

typescript
fileTypeOf('Interview_Take3.MOV'); // 'video'
fileTypeOf(input.files[0]);        // 'image'
fileTypeOf('notes');               // null

Released under the MIT License.