The file type is detected by checking the magic number of the buffer.
$ yarn add file-identity
$ npm install file-identity --save
FT.fromFile(file)
FT.fromBuffer(buffer)
Take Vue for example
html
<input type="file" @input="handleFileInput" />
js
import FT from 'file-identity'
async handleFileInput(event) {
const result = await FT.fromFile(event.target.files[0])
console.log(result)
}