read-excel-file 8.0.3 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +27 -10
- package/browser/index.d.ts +2 -1
- package/commonjs/parseData/parseData.js +430 -208
- package/commonjs/parseData/parseData.js.map +1 -1
- package/commonjs/parseData/parseData.test.js.map +1 -1
- package/commonjs/xml/xml.js +1 -1
- package/commonjs/xml/xml.js.map +1 -1
- package/modules/parseData/parseData.js +429 -208
- package/modules/parseData/parseData.js.map +1 -1
- package/modules/parseData/parseData.test.js.map +1 -1
- package/modules/xml/xml.js +1 -1
- package/modules/xml/xml.js.map +1 -1
- package/node/index.d.ts +2 -1
- package/package.json +2 -2
- package/types/parseData/parseDataError.d.ts +13 -2
- package/types/types.d.ts +4 -2
- package/universal/index.d.ts +2 -1
- package/web-worker/index.d.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
9.0.0 / 18.04.2026
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
* Refactored `parseData()` function.
|
|
5
|
+
* The result of `parseData()` function is now `{ errors, objects }`. If there're no errors, `errors` will be `undefined`. Otherwise, `errors` will be a non-empty array and `objects` will be `undefined`.
|
|
6
|
+
* Previously the result of `parseData()` function was `[{ errors, object }, ...]`, i.e. the `errors` were split between each particular data row. Now the `errors` are combined for all data rows. The rationale is that it's simpler to handle the result of the function this way.
|
|
7
|
+
* In a schema, a nested object is now not allowed to be `required: true`. Otherwise, if a nested object was allowed to be `required: true`, a corresponding `"required"` error would have to include a specific `column` title but a nested object simply doesn't have one.
|
|
8
|
+
|
|
1
9
|
8.0.0 / 11.03.2026
|
|
2
10
|
==================
|
|
3
11
|
|
|
@@ -14,6 +22,8 @@
|
|
|
14
22
|
* The `result` of the function is an array where each element represents a "data row" and has shape `{ object, errors }`.
|
|
15
23
|
* Depending on whether there were any errors when parsing a given "data row", either `object` or `errors` property will be `undefined`.
|
|
16
24
|
* The `errors` don't have a `row` property anymore because it could be derived from "data row" number.
|
|
25
|
+
* In version `9.x`, the `row` property has been re-added, so consider migrating straight to `9.x`.
|
|
26
|
+
* In version `9.x`, the returned result of `parseData()` has been changed back to `{ errors, objects }`, so consider migrating straight to `9.x`. In that case, if there're no errors, `errors` will be `undefined`; otherwise, `errors` will be a non-empty array and `objects` will be `undefined`.
|
|
17
27
|
* Removed `transformData` parameter because `schema` parameter was removed. A developer could transform the `data` themself and then pass it to `parseData()` function.
|
|
18
28
|
* Removed `isColumnOriented` parameter.
|
|
19
29
|
* Removed `ignoreEmptyRows` parameter. Empty rows somewhere in the middle are not ignored now.
|
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ Also check out [`write-excel-file`](https://www.npmjs.com/package/write-excel-fi
|
|
|
37
37
|
* The `result` of the function is an array where each element represents a "data row" and has shape `{ object, errors }`.
|
|
38
38
|
* Depending on whether there were any errors when parsing a given "data row", either `object` or `errors` property will be `undefined`.
|
|
39
39
|
* The `errors` don't have a `row` property anymore because it could be derived from "data row" number.
|
|
40
|
+
* In version `9.x`, the `row` property has been re-added, so consider migrating straight to `9.x`.
|
|
41
|
+
* In version `9.x`, the returned result of `parseData()` has been changed back to `{ errors, objects }`, so consider migrating straight to `9.x`. In that case, if there're no errors, `errors` will be `undefined`; otherwise, `errors` will be a non-empty array and `objects` will be `undefined`.
|
|
40
42
|
* Removed `transformData` parameter because `schema` parameter was removed. A developer could transform the `data` themself and then pass it to `parseData()` function.
|
|
41
43
|
* Removed `isColumnOriented` parameter.
|
|
42
44
|
* Removed `ignoreEmptyRows` parameter. Empty rows somewhere in the middle are not ignored now.
|
|
@@ -60,6 +62,17 @@ Also check out [`write-excel-file`](https://www.npmjs.com/package/write-excel-fi
|
|
|
60
62
|
* `ParsedObjectsResult` → `ParseDataResult`
|
|
61
63
|
</details>
|
|
62
64
|
|
|
65
|
+
<details>
|
|
66
|
+
<summary>Migrating from <code>8.x</code> to <code>9.x</code></summary>
|
|
67
|
+
|
|
68
|
+
######
|
|
69
|
+
|
|
70
|
+
* Refactored `parseData()` function.
|
|
71
|
+
* The result of `parseData()` function is now `{ errors, objects }`. If there're no errors, `errors` will be `undefined`. Otherwise, `errors` will be a non-empty array and `objects` will be `undefined`.
|
|
72
|
+
* Previously the result of `parseData()` function was `[{ errors, object }, ...]`, i.e. the `errors` were split between each particular data row. Now the `errors` are combined for all data rows. The rationale is that it's simpler to handle the result of the function this way.
|
|
73
|
+
* In a schema, a nested object is now not allowed to be `required: true`. Otherwise, if a nested object was allowed to be `required: true`, a corresponding `"required"` error would have to include a specific `column` title but a nested object simply doesn't have one.
|
|
74
|
+
</details>
|
|
75
|
+
|
|
63
76
|
## Install
|
|
64
77
|
|
|
65
78
|
```js
|
|
@@ -288,16 +301,15 @@ import { readSheet, parseData } from "read-excel-file/browser"
|
|
|
288
301
|
|
|
289
302
|
const data = await readSheet(file)
|
|
290
303
|
const schema = { ... }
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
304
|
+
const { objects, errors } = parseData(data, schema)
|
|
305
|
+
if (errors) {
|
|
306
|
+
console.error(errors)
|
|
307
|
+
} else {
|
|
308
|
+
console.log(objects)
|
|
297
309
|
}
|
|
298
310
|
```
|
|
299
311
|
|
|
300
|
-
The `parseData()` function returns an
|
|
312
|
+
The `parseData()` function returns an object — `{ objects, errors }`. Depending on whether there were any errors when parsing the data, either `objects` or `errors` property will be `undefined`.
|
|
301
313
|
|
|
302
314
|
The sheet data that is being parsed should adhere to a simple structure: the first row should be a header row with just column titles, and each following row should specify the values for those columns.
|
|
303
315
|
|
|
@@ -393,15 +405,20 @@ const schema = {
|
|
|
393
405
|
},
|
|
394
406
|
// Nested object example
|
|
395
407
|
course: {
|
|
396
|
-
// required:
|
|
408
|
+
// A nested object could be declared as completely optional by specifying `required: false`.
|
|
409
|
+
// In that case, when all of its properties are missing from the input data, it wouldn't throw any error
|
|
410
|
+
// regardless of whether some of its properties are declared as `required: true` or not.
|
|
411
|
+
required: false,
|
|
397
412
|
schema: {
|
|
398
413
|
title: {
|
|
399
414
|
column: 'COURSE TITLE',
|
|
400
|
-
type: String
|
|
415
|
+
type: String,
|
|
416
|
+
// When course data is present, the course title must be specified.
|
|
417
|
+
required: true
|
|
401
418
|
},
|
|
402
419
|
categories: {
|
|
403
420
|
column: 'COURSE CATEGORY',
|
|
404
|
-
// An example of parsing comma-separated values
|
|
421
|
+
// An example of parsing comma-separated values.
|
|
405
422
|
type: [String]
|
|
406
423
|
},
|
|
407
424
|
isFree: {
|