isEqual does not work for FileList and File objects
If the FileList is different, but the length is the same, it will always say that the two FileList objects are equal.
There is this line var areArrays = className === '[object Array];', but the FileList is of type [object FileList].
Also the method Object.keys does not work on object File, which is in FileList. It always returns 0 keys. What works is this:
var keys = [];
for (var key in obj) keys.push(key);
The method obj.hasOwnProperty also does not work for the File object.
If the FileList is different, but the length is the same, it will always say that the two FileList objects are equal. There is this line
var areArrays = className === '[object Array];', but the FileList is of type [object FileList].
This is expected. Most Underscore functions expect only primitive values (plus their object wrappers), plain objects and plain arrays. We might extend this to also include Map and Set in some future update, but that's about as far as we will take it. _.isEqual already pushes this a bit by checking whether objects have the same constructor. Detecting and supporting each possible type of object is completely out of the scope of Underscore.
Assuming you mean the standard FileList and File, a value comparison cannot even be done synchronously. A single pair of Files could be compared like this:
async function isEqualFile(a, b) {
var [aBuf, bBuf] = await Promise.all(_.invoke([a, b], 'arrayBuffer'));
return _.isEqual(new Uint8Array(aBuf), new Uint8Array(bBuf));
}
Using the above as a base, you could then compare FileLists as follows:
async function isEqualFileList(a, b) {
if (a.length !== b.length) return false;
var pairwise = _.chain([a, b]).unzip().map(pair => isEqualFile(...pair));
return _.every(await Promise.all(pairwise.value()));
}
I hope you can see why we can't have specific code like this for every possible type of object. I also hope the above code can be a suitable alternative for you. Note that these functions return promises, so you can't do this:
if (!isEqualFileList(fileInput1.files, fileInput2.files)) { ... }
You have to do something like this instead:
isEqualFileList(fileInput1.files, fileInput2.files).then(areEqual => {
if (!areEqual) { ... }
});
Also the method Object.keys does not work on object File, which is in FileList. It always returns 0 keys. What works is this:
var keys = []; for (var key in obj) keys.push(key);The method obj.hasOwnProperty also does not work for the File object.
This is expected because File objects don't have any own enumerable properties.
As an aside, comparing inherited keys between File objects may seem to work, but it is a very superficial comparison. You are only assessing whether two files have the same name, size and modification date. They might still have different contents; to be sure about contents, you need the asynchronous code I showed above.
I'm closing this, but please feel free to comment or reopen if you feel the need.