Skip to content

Commit

Permalink
Merge pull request #10 from BrandwatchLtd/CCTQ-112-empty-string
Browse files Browse the repository at this point in the history
fix for empty string handling
  • Loading branch information
jaydanielsencision authored Aug 30, 2024
2 parents cac5a60 + 55f6f8b commit c27725d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = {
} else if (_.isBoolean(v)) {
t = 'b';
v = '<v>' + (v === true ? '1' : '0') + '</v>';
} else if (v) {
} else if (v !== undefined) {
v = '<is><t>' + escapeXML(v) + '</t></is>';
t = 'inlineStr';
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@brandwatch/xlsx-stream",
"description": "Creates SpreadsheetML (.xlsx) files in sequence with streaming interface.",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/BrandwatchLtd/node-xlsx-stream",
"author": {
"name": "Ryota Suzuki",
Expand Down
26 changes: 26 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ describe("xlsx-stream", () => {
});
});

describe("empty string", () => {
const filePath = path.join(dirPath, "emptyString.xlsx");
const expectedRows = [
['Place Holder', ''],
];

it("should create an xlsx file and preserve empty string", (done) => {
const x = xlsx_stream();
const out = fs.createWriteStream(filePath);
x.pipe(out);
expectedRows.forEach((row) => x.write(row));
x.end();
out.on("finish", () => {
const workSheetsFromFile = xlsx.parse(filePath);
const rows = workSheetsFromFile[0].data;

assert.deepStrictEqual(
rows,
expectedRows,
`Rows do not match. Expected ${JSON.stringify(expectedRows)}, but got ${JSON.stringify(rows)}`,
);
done();
});
});
});

describe("Large dataset", () => {
it("should handle large dataset", (done) => {
const randRows = 10000 + _.random(10000);
Expand Down

0 comments on commit c27725d

Please sign in to comment.