Skip to content

Commit

Permalink
add xml formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Aug 1, 2024
1 parent ec28bfe commit 0f915f5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ export default [
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{ ignores: ["dist/"] }
{
rules: {
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
},
ignores: ["dist/"]
}
];
5 changes: 4 additions & 1 deletion lib/formatters/formatter_factory.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { CSVFormatter } from "./csv_formatter.js";
import { Formatter } from "./formatter.js";
import { CSVFormatter } from "./csv_formatter.js";
import { JSONFormatter } from "./json_formatter.js";
import { XMLFormatter } from "./xml_formatter.js";

export class FormatterFactory {
static getFormatter(name: string): Formatter {
if (name === "csv") {
return new CSVFormatter();
} else if (name === "json") {
return new JSONFormatter();
} else if (name === "xml") {
return new XMLFormatter();
}
return new CSVFormatter();
}
Expand Down
3 changes: 1 addition & 2 deletions lib/formatters/json_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Formatter } from "./formatter.js";

export class JSONFormatter extends Formatter {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
header(sampleData: { [key: string]: string }[], fastaMapper?: boolean | undefined): string {
header(_sampleData: { [key: string]: string }[], _fastaMapper?: boolean | undefined): string {
return "[";
}

Expand Down
17 changes: 17 additions & 0 deletions lib/formatters/xml_formatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Formatter } from "./formatter.js";
import { toXML } from "to-xml";

export class XMLFormatter extends Formatter {

header(_sampleData: { [key: string]: string }[], _fastaMapper?: boolean | undefined): string {
return "<results>";
}

footer(): string {
return "</results>\n";
}

convert(data: object[], _first: boolean): string {
return data.map(d => `<result>${toXML(d)}</result>`).join("");
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"dependencies": {
"commander": "^12.1.0",
"csv-stringify": "^6.5.0"
"csv-stringify": "^6.5.0",
"to-xml": "^0.1.11"
},
"devDependencies": {
"@eslint/js": "^9.5.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,11 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

to-xml@^0.1.11:
version "0.1.11"
resolved "https://registry.yarnpkg.com/to-xml/-/to-xml-0.1.11.tgz#fae4dafe89889e5013c86e4ea65933dca97d985b"
integrity sha512-deRSQy7vONsawpyrPdhuV0Lh0yXtKQEhAnvfSv3JMahCq3PF0MZJB/BdV1jJANVbuMdnx96zhqD/X0zMMXx0Pw==

ts-api-utils@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.3.0.tgz#4b490e27129f1e8e686b45cc4ab63714dc60eea1"
Expand Down

0 comments on commit 0f915f5

Please sign in to comment.