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

Releasing version 2.5.4 with null support #84

Merged
merged 3 commits into from
Aug 24, 2023
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 packages/main-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-as-xlsx",
"version": "2.5.3",
"version": "2.5.4",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions packages/main-library/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,25 @@ describe("json-as-xlsx", () => {
expect(booksSheet.A3.v).toBe("Git")
expect(booksSheet.B3.v).toBe("Robert")
})

it("should allow null value in content", () => {
const sheets = [
{
sheet: "Users",
columns: [{ label: "IP", value: "metadata.ip" }],
content: [
{ name: "Martin", metadata: { ip: null } },
{ name: "Robert", metadata: { ip: null } },
],
},
]
const buffer = jsonxlsx(sheets, settings)
const workBook = readBufferWorkBook(buffer)
const workSheet = workBook.Sheets.Users

expect(workSheet.A1.v).toBe("IP")
expect(workSheet.A2.v).toBe("")
expect(workSheet.A3.v).toBe("")
})
})
})
8 changes: 4 additions & 4 deletions packages/main-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { utils, WorkBook, WorkSheet, write, writeFile, WritingOptions } from "xl

export interface IColumn {
label: string
value: string | ((value: IContent) => string | number | boolean | Date | IContent)
value: string | ((value: IContent) => string | number | boolean | Date | IContent | null)
format?: string
}

Expand All @@ -25,7 +25,7 @@ export interface ISettings {
}

export interface IJsonSheetRow {
[key: string]: string | number | boolean | Date | IContent
[key: string]: string | number | boolean | Date | IContent | null
}

export interface IWorksheetColumnWidth {
Expand All @@ -44,7 +44,7 @@ export const getContentProperty = (content: IContent, property: string): string
return value ?? ""
}

if (value === undefined || typeof value === "string" || typeof value === "boolean" || typeof value === "number" || value instanceof Date) {
if (value === undefined || value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" || value instanceof Date) {
return ""
}

Expand Down Expand Up @@ -213,4 +213,4 @@ module.exports = xlsx
module.exports.getContentProperty = getContentProperty
module.exports.getJsonSheetRow = getJsonSheetRow
module.exports.getWorksheetColumnWidths = getWorksheetColumnWidths
module.exports.utils = utils
module.exports.utils = utils
Loading