-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user can now choose between JSON and CSV output and customize the CSV separator closes: #75
- Loading branch information
Showing
39 changed files
with
2,852 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { csvSeparator } from '../settings'; | ||
import { Formatter } from "./formatter"; | ||
|
||
export class CsvFormatter implements Formatter { | ||
async* format(lines: AsyncGenerator<object>): AsyncGenerator<string> { | ||
const first = await lines.next(); | ||
if (first.value) { | ||
yield this.generateHeader(first.value); | ||
yield this.generateRow(first.value); | ||
} | ||
for await (const line of lines) { | ||
yield this.generateRow(line); | ||
} | ||
} | ||
|
||
format_error(message: string): string { | ||
return message; | ||
} | ||
|
||
private generateHeader(line: object) { | ||
return Object.keys(line).join(csvSeparator()); | ||
} | ||
|
||
private generateRow(line: object) { | ||
return Object.values(line).join(csvSeparator()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { format } from "../settings"; | ||
import { CsvFormatter } from "./csv-formatter"; | ||
import { Formatter } from "./formatter"; | ||
import { JsonFormatter } from "./json-formatter"; | ||
|
||
export function createFormatter(): Formatter { | ||
switch (format()) { | ||
case 'json': | ||
return new JsonFormatter; | ||
case 'csv': | ||
return new CsvFormatter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// https://stackoverflow.com/a/64174790/621176 | ||
export const FormatterNames = ['json', 'csv'] as const; | ||
export type FormatterName = typeof FormatterNames[number]; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.