diff --git a/package-lock.json b/package-lock.json index 96509de..011e342 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "front-end-template", - "version": "0.6.0", + "name": "ods-xlsx", + "version": "0.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "front-end-template", - "version": "0.6.0", + "name": "ods-xlsx", + "version": "0.7.0", "dependencies": { "@xmldom/xmldom": "^0.8.10", "unzipit": "^1.4.3" diff --git a/package.json b/package.json index f0c42da..995d911 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ods-xlsx", - "version": "0.6.0", + "version": "0.7.0", "type": "module", "main": "./scripts/node.js", "browser": "./scripts/browser.js", diff --git a/readme.md b/readme.md index e394573..c99243e 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ Small lib to parse/understand .ods and .xsls files in the browser and node.js ### Install ```sh -npm i https://github.com/DavidBruant/ods-xlsx.git#v0.6.0 +npm i https://github.com/DavidBruant/ods-xlsx.git#v0.7.0 ``` diff --git a/scripts/shared.js b/scripts/shared.js index 840695a..e996da6 100644 --- a/scripts/shared.js +++ b/scripts/shared.js @@ -248,8 +248,14 @@ export function sheetRawContentToObjects(rawContent){ let [firstRow, ...dataRows] = rawContent /** @type {string[]} */ - //@ts-expect-error this type is correct after the filter - const columns = firstRow.filter(({value}) => typeof value === 'string' && value.length >= 1).map(r => r.value) + + const columns = firstRow.map((r, i) => { + if (r.value === undefined || r.value === null || r.value === "") { + return `Column ${i+1}` + } + + return r.value + }) return dataRows .map(row => { diff --git a/tests/sheetRawContentToObjects.js b/tests/sheetRawContentToObjects.js new file mode 100644 index 0000000..377136c --- /dev/null +++ b/tests/sheetRawContentToObjects.js @@ -0,0 +1,39 @@ +import test from 'ava'; +import { sheetRawContentToObjects } from "../scripts/shared.js" + +test("Empty header value should be kept", t => { + const rawContent = [ + [ + { + type: "string", + value: "", + }, + { + type: "string", + value: "Pitchou", + }, + ], + [ + { + type: "string", + value: "1", + }, + { + type: "string", + value: "2", + }, + ] + ] + + const object = sheetRawContentToObjects(rawContent) + + t.deepEqual( + object, + [ + { + "Column 1": "1", + "Pitchou": "2", + } + ] + ) +}) \ No newline at end of file