Fix header row (pull request #3)

Fix header row
This commit is contained in:
Fanny Cheung 2024-07-16 17:15:16 +02:00 committed by GitHub
commit 08a2d5f63c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 53 additions and 8 deletions

8
package-lock.json generated
View File

@ -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"

View File

@ -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",

View File

@ -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
```

View File

@ -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 => {

View File

@ -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",
}
]
)
})