Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for empty string handling #10

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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