file-type-js
v0.1.0
Published
A file type checking library
Downloads
7
Readme
file-type
A file type checking library
Detect the file type from Buffer, ArrayBuffer, File, Bolb
npm install file-type-js
const FileType = require('file-type-js')
const buf = fs.readFileSync(path.resolve(__dirname, 'files/test.jpg'))
console.log(await FileType.is(buf, 'jpg'))
browser
<script src="./file-type.js"></script>
<script>
fileInput.addEventListener('change', function () {
console.log(fileInput.files)
var file = fileInput.files[0]
if (!file) return
var extname = (file.name.match(/\.(\w*)$/)[1]).toLocaleLowerCase()
$FileType.is(file, extname).then(function (valid) {
console.log(extname, valid)
})
})
</script>