Skip to content

closeio/filevalidator.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

filevalidator.js

File signature validation in JavaScript

Useful for cases where looking at a filename extension only is not reliable enough.

Usage:

import { verifyFileType } from 'filevalidator';

const fileInput = document.getElementById('file-input');

fileInput.addEventListener('change', function(e) {
    const file = e.currentTarget.files[0];
    verifyFileType(file, ['mp3', 'wav'], function(valid) {
        alert('Valid mp3 or wave file: ' + !!valid);
    });
});