(data: any, filename: string)
| 88 | |
| 89 | |
| 90 | async function writeJson(data: any, filename: string): Promise<string> { |
| 91 | try { |
| 92 | filename = trimFilename(filename) |
| 93 | |
| 94 | if (!filename.endsWith('.json')) { |
| 95 | filename = filename + '.json' |
| 96 | } |
| 97 | |
| 98 | const writer = new JSONWriteStream(filename) |
| 99 | await writer.preStart() |
| 100 | |
| 101 | for (let index = 0; index < data.length; index++) { |
| 102 | const element = data[index]; |
| 103 | applyFunctionToResult(element, async (x)=>{ |
| 104 | await writer.push(x) |
| 105 | }) |
| 106 | |
| 107 | } |
| 108 | await writer.end() |
| 109 | |
| 110 | } catch (error: any) { |
| 111 | if (isFileOpenError(error)) { |
| 112 | const baseFilename = path.basename(filename) |
| 113 | throw new Error(`${baseFilename} is currently open in another application. Please close the application and try again.`) |
| 114 | } |
| 115 | throw error |
| 116 | } |
| 117 | return filename |
| 118 | } |
| 119 | |
| 120 | |
| 121 | function fixCsvFilename(filename: string): string { |
no test coverage detected