commit
08a2d5f63c
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "front-end-template",
|
"name": "ods-xlsx",
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "front-end-template",
|
"name": "ods-xlsx",
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xmldom/xmldom": "^0.8.10",
|
"@xmldom/xmldom": "^0.8.10",
|
||||||
"unzipit": "^1.4.3"
|
"unzipit": "^1.4.3"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ods-xlsx",
|
"name": "ods-xlsx",
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./scripts/node.js",
|
"main": "./scripts/node.js",
|
||||||
"browser": "./scripts/browser.js",
|
"browser": "./scripts/browser.js",
|
||||||
|
|||||||
@ -8,7 +8,7 @@ Small lib to parse/understand .ods and .xsls files in the browser and node.js
|
|||||||
### Install
|
### Install
|
||||||
|
|
||||||
```sh
|
```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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -248,8 +248,14 @@ export function sheetRawContentToObjects(rawContent){
|
|||||||
let [firstRow, ...dataRows] = rawContent
|
let [firstRow, ...dataRows] = rawContent
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @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
|
return dataRows
|
||||||
.map(row => {
|
.map(row => {
|
||||||
|
|||||||
39
tests/sheetRawContentToObjects.js
Normal file
39
tests/sheetRawContentToObjects.js
Normal 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",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user