Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
catamphetamine committed Sep 14, 2022
1 parent fb4b8ce commit cd7ee4d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 82 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
5.5.0 / 20.07.2022
5.5.0 / 14.09.2022
==================

* [Moved](https://gitlab.com/catamphetamine/read-excel-file/-/issues/62) from `jszip` to `fflate`. Most likely not a "breaking change". See [browser support](https://github.com/101arrowz/fflate/#browser-support).

5.4.3 / 20.07.2022
==================

* [Added](https://gitlab.com/catamphetamine/read-excel-file/-/issues/7) `ignoreEmptyRows: false` option when parsing using a `schema`.
Expand Down
65 changes: 6 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "read-excel-file",
"version": "5.4.7",
"version": "5.5.0",
"description": "Read small to medium `*.xlsx` files in a browser or Node.js. Parse to JSON with a strict schema.",
"module": "index.js",
"main": "index.cjs",
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@xmldom/xmldom": "^0.8.2",
"jszip": "^3.9.1",
"fflate": "^0.7.3",
"unzipper": "^0.10.11"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion source/read/parseCellValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function parseCellValue(value, type, {
break
}
const parsedDate = new Date(value)
if (isNaN(parsedDate)) {
if (isNaN(parsedDate.valueOf())) {
throw new Error(`Unsupported "date" cell value: ${value}`)
}
value = parsedDate
Expand Down
4 changes: 2 additions & 2 deletions source/read/schema/convertToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function parseValueOfType(value, type, options) {
// Sometimes a date can be heuristically detected.
// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
if (value instanceof Date) {
if (isNaN(value)) {
if (isNaN(value.valueOf())) {
return { error: 'invalid', reason: 'out_of_bounds' }
}
return { value }
Expand All @@ -323,7 +323,7 @@ function parseValueOfType(value, type, options) {
return { error: 'invalid', reason: 'out_of_bounds' }
}
const date = parseDate(value, options.properties)
if (isNaN(date)) {
if (isNaN(date.valueOf())) {
return { error: 'invalid', reason: 'out_of_bounds' }
}
return { value: date }
Expand Down
40 changes: 23 additions & 17 deletions source/read/unpackXlsxFileBrowser.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import JSZip from 'jszip'
import { unzipSync, strFromU8 } from 'fflate'

/**
* Reads XLSX file in a browser.
* @param {file} file - A file being uploaded in the browser.
* @param {File} file - A `File` object being uploaded in the browser.
* @return {Promise} Resolves to an object holding XLSX file entries.
*/
export default function unpackXlsxFile(file) {
const files = {}

return JSZip.loadAsync(file).then((zip) => {
const files = []
zip.forEach((relativePath, zipEntry) => {
if (!zipEntry.dir) {
files.push(zipEntry.name)
}
})

const entries = {}
return Promise.all(files.map((file) => {
return zip.file(file).async('string').then(content => entries[file] = content)
}))
.then(() => entries)
const startedAt = Date.now()
return file.arrayBuffer().then((fileBuffer) => {
const archive = new Uint8Array(fileBuffer)
const contents = unzipSync(archive)
return getContents(contents)
// return new Promise((resolve, reject) => {
// unzip(archive, (error, contents) => {
// if (error) {
// return reject(error)
// }
// return resolve(getContents(contents))
// })
// })
})
}

function getContents(contents) {
const unzippedFiles = []
for (const key of Object.keys(contents)) {
unzippedFiles[key] = strFromU8(contents[key])
}
return unzippedFiles
}

0 comments on commit cd7ee4d

Please sign in to comment.