read-excel-file 8.0.3 → 9.0.0

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 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
 
package/README.md CHANGED
@@ -37,6 +37,7 @@ 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 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
41
  * Removed `transformData` parameter because `schema` parameter was removed. A developer could transform the `data` themself and then pass it to `parseData()` function.
41
42
  * Removed `isColumnOriented` parameter.
42
43
  * Removed `ignoreEmptyRows` parameter. Empty rows somewhere in the middle are not ignored now.
@@ -60,6 +61,17 @@ Also check out [`write-excel-file`](https://www.npmjs.com/package/write-excel-fi
60
61
  * `ParsedObjectsResult` → `ParseDataResult`
61
62
  </details>
62
63
 
64
+ <details>
65
+ <summary>Migrating from <code>8.x</code> to <code>9.x</code></summary>
66
+
67
+ ######
68
+
69
+ * Refactored `parseData()` function.
70
+ * 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`.
71
+ * 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.
72
+ * 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.
73
+ </details>
74
+
63
75
  ## Install
64
76
 
65
77
  ```js
@@ -288,16 +300,15 @@ import { readSheet, parseData } from "read-excel-file/browser"
288
300
 
289
301
  const data = await readSheet(file)
290
302
  const schema = { ... }
291
- for (const { object, errors } of parseData(data, schema)) {
292
- if (errors) {
293
- console.error(errors)
294
- } else {
295
- console.log(object)
296
- }
303
+ const { objects, errors } = parseData(data, schema)
304
+ if (errors) {
305
+ console.error(errors)
306
+ } else {
307
+ console.log(objects)
297
308
  }
298
309
  ```
299
310
 
300
- The `parseData()` function returns an array where each element represents a "data row" and has shape `{ object, errors }`. Depending on whether there were any errors when parsing a given "data row", either `object` or `errors` property will be `undefined`.
311
+ 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
312
 
302
313
  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
314
 
@@ -393,15 +404,20 @@ const schema = {
393
404
  },
394
405
  // Nested object example
395
406
  course: {
396
- // required: true/false,
407
+ // A nested object could be declared as completely optional by specifying `required: false`.
408
+ // In that case, when all of its properties are missing from the input data, it wouldn't throw any error
409
+ // regardless of whether some of its properties are declared as `required: true` or not.
410
+ required: false,
397
411
  schema: {
398
412
  title: {
399
413
  column: 'COURSE TITLE',
400
- type: String
414
+ type: String,
415
+ // When course data is present, the course title must be specified.
416
+ required: true
401
417
  },
402
418
  categories: {
403
419
  column: 'COURSE CATEGORY',
404
- // An example of parsing comma-separated values
420
+ // An example of parsing comma-separated values.
405
421
  type: [String]
406
422
  },
407
423
  isFree: {
@@ -25,7 +25,8 @@ import {
25
25
  export {
26
26
  CellValue,
27
27
  Row,
28
- SheetData
28
+ SheetData,
29
+ Sheet
29
30
  } from '../types/types.d.js';
30
31
 
31
32
  export {