( window: Window & typeof globalThis, files: File[], )
| 1 | // FileList can not be created per constructor. |
| 2 | |
| 3 | export function createFileList( |
| 4 | window: Window & typeof globalThis, |
| 5 | files: File[], |
| 6 | ): FileList { |
| 7 | const list: FileList & Iterable<File> = { |
| 8 | ...files, |
| 9 | length: files.length, |
| 10 | item: (index: number) => list[index], |
| 11 | [Symbol.iterator]: function* nextFile() { |
| 12 | for (let i = 0; i < list.length; i++) { |
| 13 | yield list[i] |
| 14 | } |
| 15 | }, |
| 16 | } |
| 17 | list.constructor = window.FileList |
| 18 | |
| 19 | // guard for environments without FileList |
| 20 | /* istanbul ignore else */ |
| 21 | if (window.FileList) { |
| 22 | Object.setPrototypeOf(list, window.FileList.prototype) |
| 23 | } |
| 24 | |
| 25 | Object.freeze(list) |
| 26 | |
| 27 | return list |
| 28 | } |
no outgoing calls
no test coverage detected