MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / writeOutput

Function writeOutput

js/botasaurus-js/src/decorators-common.ts:31–71  ·  view source on GitHub ↗
(
  output: string | ((data: any, result: any) => void) | null,
  outputFormats: string[] | null,
  data: any,
  result: any,
  fnName: string
)

Source from the content-addressed store, hash-verified

29}
30
31function writeOutput(
32 output: string | ((data: any, result: any) => void) | null,
33 outputFormats: string[] | null,
34 data: any,
35 result: any,
36 fnName: string
37) {
38 const writtenFilenames: string[] = [];
39
40 if (isNullish(output)) {
41 return result;
42 }
43 if (typeof output === 'function') {
44 output(data, result);
45 } else {
46 outputFormats = outputFormats || [Formats.JSON];
47
48 const defaultFilename = output === 'default' ? fnName : output;
49
50 for (const fm of outputFormats) {
51 if (fm === Formats.JSON) {
52 // @ts-ignore
53 const filename = fixJsonFilename(defaultFilename);
54 writtenFilenames.push(filename);
55 writeJson(result, filename, false);
56 } else if (fm === Formats.CSV) {
57 // @ts-ignore
58 const filename = fixCsvFilename(defaultFilename);
59 writtenFilenames.push(filename);
60 writeCsv(result, filename, false);
61 } else if (fm === Formats.EXCEL) {
62 // @ts-ignore
63 const filename = fixExcelFilename(defaultFilename);
64 writtenFilenames.push(filename);
65 writeExcel(result, filename, false);
66 }
67 }
68 }
69
70 printFilenames(writtenFilenames);
71}
72
73function cleanErrorLogs(errorLogsDir: string, sortKey: (folder: string) => Date) {
74 const folders = fs.readdirSync(errorLogsDir);

Callers 3

performTaskFunction · 0.90
drainQueueFunction · 0.90
performPlaywrightFunction · 0.90

Calls 9

isNullishFunction · 0.90
fixJsonFilenameFunction · 0.90
writeJsonFunction · 0.90
fixCsvFilenameFunction · 0.90
writeCsvFunction · 0.90
fixExcelFilenameFunction · 0.90
writeExcelFunction · 0.90
printFilenamesFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected