-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add file system utility to parse XML files * Add test for file system utility to parse XML files * Added separate module for XmlParser * Add docs for the XML parser * Set @scomans as codeowner of the XmlParser --------- Co-authored-by: Oliver Schwendener <[email protected]>
- Loading branch information
1 parent
71bef4b
commit a6bba02
Showing
12 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Offers a method to parse XML content. | ||
*/ | ||
export interface XmlParser { | ||
/** | ||
* Parses the given XML string and returns the result as an object. | ||
* @param xml - The XML string to be parsed. | ||
* @param [options] - Optional settings for parsing. | ||
* @param options.preserveOrder - Whether to preserve the order of elements. | ||
* @param options.ignoreAttributes - Whether to ignore attributes in the XML. | ||
* @returns {T} - The parsed result. | ||
*/ | ||
parse<T>(xml: string, options?: { preserveOrder: boolean; ignoreAttributes: boolean }): T; | ||
} |
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 @@ | ||
export * from "./XmlParser"; |
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,14 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { XmlParser } from "./XmlParser"; | ||
|
||
describe(XmlParser, () => { | ||
describe(XmlParser.prototype.parse, () => { | ||
it("should read and parse XML file content", async () => { | ||
const xml = "<root><test>test</test></root>"; | ||
const actual = new XmlParser().parse(xml, { ignoreAttributes: true, preserveOrder: true }); | ||
const expected = [{ root: [{ test: [{ "#text": "test" }] }] }]; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
import { XMLParser } from "fast-xml-parser"; | ||
import type { XmlParser as XmlParserInterface } from "./Contract"; | ||
|
||
export class XmlParser implements XmlParserInterface { | ||
public parse<T>(xml: string, options?: { preserveOrder: boolean; ignoreAttributes: boolean }): T { | ||
return new XMLParser(options).parse(xml); | ||
} | ||
} |
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,9 @@ | ||
import type { Dependencies } from "@Core/Dependencies"; | ||
import type { DependencyRegistry } from "@Core/DependencyRegistry"; | ||
import { XmlParser } from "./XmlParser"; | ||
|
||
export class XmlParserModule { | ||
public static bootstrap(dependencyRegistry: DependencyRegistry<Dependencies>) { | ||
dependencyRegistry.register("XmlParser", new XmlParser()); | ||
} | ||
} |
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,2 @@ | ||
export * from "./Contract"; | ||
export * from "./XmlParserModule"; |
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