Skip to content

Commit 8a08f17

Browse files
committed
allow indentation to be empty string
1 parent 7fc5dec commit 8a08f17

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

spec/format_spec.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
import XMLBuilder from "../src/fxb.js";
3+
import { Expression } from "path-expression-matcher";
4+
5+
describe("Format without indentation", function () {
6+
const expectedXml = `
7+
<root>
8+
<child1>hello</child1>
9+
<child2>world</child2>
10+
</root>`
11+
12+
it("when order is preserved", function () {
13+
const jObj = [
14+
{
15+
root: [
16+
{ child1: [{ "#text": "hello" }] },
17+
{ child2: [{ "#text": "world" }] }
18+
]
19+
}
20+
];
21+
22+
const builderOptions = {
23+
format: true,
24+
preserveOrder: true,
25+
indentBy: ""
26+
};
27+
28+
29+
const builder = new XMLBuilder(builderOptions);
30+
let output = builder.build(jObj);
31+
// console.log(output);
32+
expect(output).toEqual(expectedXml);
33+
34+
});
35+
xit("when order is not preserved", function () {
36+
// TODO: This test is failing due an extra line in the starting of the document
37+
// But not changing the behavior for backward compatibility.
38+
// Will be fixed in major release
39+
const jObj = {
40+
root: {
41+
child1: "hello",
42+
child2: "world",
43+
}
44+
}
45+
46+
const builderOptions = {
47+
format: true,
48+
indentBy: ""
49+
};
50+
51+
52+
const builder = new XMLBuilder(builderOptions);
53+
let output = builder.build(jObj);
54+
//console.log(output);
55+
expect(output).toEqual(expectedXml);
56+
57+
});
58+
});

src/orderedJs2Xml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const EOL = "\n";
1111
*/
1212
export default function toXml(jArray, options) {
1313
let indentation = "";
14-
if (options.format && options.indentBy.length > 0) {
14+
if (options.format) {
1515
indentation = EOL;
1616
}
1717

0 commit comments

Comments
 (0)