Update fnTools.ts

This commit is contained in:
Andros Fenollosa 2022-02-10 09:22:29 +01:00 committed by GitHub
parent 0bede8fce8
commit e9a9ab3ad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -179,3 +179,15 @@ export function getIndexOfFileList(name: string, list: Array<File>): number {
export function deleteArrayElementByIndex(list: Array<any>, index: number) {
return list.filter((item, itemIndex) => itemIndex !== index);
}
/**
* Returns a FileLists from an array containing Files.
* @param {Array<File>} filesList
* @return {FileList}
*/
export function arrayFilesToFileList(filesList) {
return filesList.reduce(function (dataTransfer, file) {
dataTransfer.items.add(file);
return dataTransfer;
}, new DataTransfer()).files;
}