read-excel-file 9.0.6 → 9.0.8

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +31 -13
  3. package/browser/index.d.ts +53 -30
  4. package/bundle/read-excel-file.min.js.map +1 -1
  5. package/commonjs/export/parseSheet.js +14 -1
  6. package/commonjs/export/parseSheet.js.map +1 -1
  7. package/commonjs/export/readXlsxFileBrowser.js +1 -1
  8. package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
  9. package/commonjs/export/readXlsxFileNode.js +1 -1
  10. package/commonjs/export/readXlsxFileNode.js.map +1 -1
  11. package/commonjs/export/readXlsxFileUniversal.js +1 -1
  12. package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
  13. package/commonjs/export/readXlsxFileWebWorker.js +1 -1
  14. package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
  15. package/commonjs/parseSheetData/parseSheetData.js +4 -1
  16. package/commonjs/parseSheetData/parseSheetData.js.map +1 -1
  17. package/commonjs/parseSheetData/parseSheetData.test.js.map +1 -1
  18. package/commonjs/xlsx/parseSpreadsheetContents.js +1 -1
  19. package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -1
  20. package/modules/export/parseSheet.js +15 -1
  21. package/modules/export/parseSheet.js.map +1 -1
  22. package/modules/export/readXlsxFileBrowser.js +1 -1
  23. package/modules/export/readXlsxFileBrowser.js.map +1 -1
  24. package/modules/export/readXlsxFileNode.js +1 -1
  25. package/modules/export/readXlsxFileNode.js.map +1 -1
  26. package/modules/export/readXlsxFileUniversal.js +1 -1
  27. package/modules/export/readXlsxFileUniversal.js.map +1 -1
  28. package/modules/export/readXlsxFileWebWorker.js +1 -1
  29. package/modules/export/readXlsxFileWebWorker.js.map +1 -1
  30. package/modules/parseSheetData/parseSheetData.js +4 -1
  31. package/modules/parseSheetData/parseSheetData.js.map +1 -1
  32. package/modules/parseSheetData/parseSheetData.test.js.map +1 -1
  33. package/modules/xlsx/parseSpreadsheetContents.js +1 -1
  34. package/modules/xlsx/parseSpreadsheetContents.js.map +1 -1
  35. package/node/index.d.ts +53 -30
  36. package/node/input.d.ts +2 -2
  37. package/package.json +1 -1
  38. package/types/Options.d.ts +5 -0
  39. package/types/OptionsWithSchema.d.ts +10 -0
  40. package/types/Sheet.d.ts +6 -0
  41. package/types/SheetData.d.ts +9 -0
  42. package/types/parseSheetData/parseSheetData.d.ts +4 -3
  43. package/types/parseSheetData/parseSheetDataError.d.ts +2 -2
  44. package/types/parseSheetData/parseSheetDataSchema.d.ts +17 -16
  45. package/types/parseSheetData/parseSheetDataValueType.d.ts +1 -1
  46. package/universal/index.d.ts +53 -30
  47. package/web-worker/index.d.ts +53 -30
  48. package/types/types.d.ts +0 -22
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 9.0.7 / 28.04.2026
2
+ ==================
3
+
4
+ * Merged [Toni G](https://gitlab.com/infotoni91)'s fix for a [bug](https://gitlab.com/catamphetamine/read-excel-file/-/work_items/111) when `error.row` was always equal to `1`.
5
+ * Re-added `schema` parameter in `readSheet()` function.
6
+
1
7
  9.0.0 / 18.04.2026
2
8
  ==================
3
9
 
@@ -42,6 +48,7 @@
42
48
  * The `errors` don't have a `row` property anymore because it could be derived from "data row" number.
43
49
  * In version `9.x`, the `row` property has been re-added, so consider migrating straight to `9.x`.
44
50
  * 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`.
51
+ * In version `9.x`, the `schema` parameter was re-added to `readSheet()` function, so consider migrating straight to `9.x`.
45
52
  * Renamed some `schema`-related parameters:
46
53
  * `schemaPropertyValueForMissingColumn` → `propertyValueWhenColumnIsMissing`
47
54
  * `schemaPropertyValueForMissingValue` → `propertyValueWhenCellIsEmpty`
package/README.md CHANGED
@@ -47,6 +47,7 @@ Also check out [`write-excel-file`](https://www.npmjs.com/package/write-excel-fi
47
47
  * The `errors` don't have a `row` property anymore because it could be derived from "data row" number.
48
48
  * In version `9.x`, the `row` property has been re-added, so consider migrating straight to `9.x`.
49
49
  * 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`.
50
+ * In version `9.x`, the `schema` parameter was re-added to `readSheet()` function, so consider migrating straight to `9.x`.
50
51
  * Renamed some `schema`-related parameters:
51
52
  * `schemaPropertyValueForMissingColumn` → `propertyValueWhenColumnIsMissing`
52
53
  * `schemaPropertyValueForMissingValue` → `propertyValueWhenCellIsEmpty`
@@ -96,6 +97,8 @@ Also check out [`write-excel-file`](https://www.npmjs.com/package/write-excel-fi
96
97
  * `ParseDataValueRequiredError` → `ParseSheetDataValueRequiredError`
97
98
  * `ParseDataResult` → `ParseSheetDataResult`
98
99
  * In a `schema`, a nested object could be declared as: `{ required: true/false, schema: { ... } }`. This is still true but the `required` flag is now only allowed to be either `undefined` or `false`, so `true` value is not allowed. The reason is quite simple. If a nested object as a whole is marked as `required: true`, and then it happens to be empty, a `"required"` error should be returned for it. But that error would also have to include a `column` title, and a nested object simply can't be pinned down to a single column in a sheet because it is by definition spread over multiple columns. So instead of marking a nested object as a whole with `required: true`, mark the specific required properties of it.
100
+ * Re-added `schema` parameter to `readSheet()` function.
101
+ * `const { objects, errors } = readSheet(data, { schema })`
99
102
  </details>
100
103
 
101
104
  ## Install
@@ -161,6 +164,8 @@ The result is a non-empty array of "sheets". Each "sheet" is an object with prop
161
164
  * `data` — Sheet data. An array of rows. Each row is an array of values — `string`, `number`, `boolean` or `Date`.
162
165
  * Example: `[ ['Name','Age'], ['John Smith',30], ['Kate Brown',15] ]`
163
166
 
167
+ Also, a very common use case is to read a list of JSON objects from an `.xlsx` file. To do that, pass a [`schema`](#schema) parameter to `readSheet()` function.
168
+
164
169
  ## Import
165
170
 
166
171
  This package provides a separate `import` path for each different environment, as described below.
@@ -325,14 +330,15 @@ Here're the results of reading [sample `.xlsx` files](https://examplefile.com/do
325
330
 
326
331
  ## Schema
327
332
 
328
- Oftentimes, the task is not just to read the "raw" spreadsheet data but also to convert each row of that data to a JSON object having a certain structure. Because it's such a common task, this package exports a named function `parseSheetData(data, schema)` which does exactly that. It parses sheet data into an array of JSON objects according to a pre-defined `schema` which describes how should a row of data be converted to a JSON object.
333
+ Oftentimes, the task is not just to read the "raw" spreadsheet data but also to convert each row of that data to a JSON object having a certain structure. Because it's such a common task, this package provides an easy way to do that — just pass a `schema` parameter when calling `readSheet()` function and it will automatically parse sheet data into an array of JSON objects according to that `schema` (which basically describes all properties of the object and which column should be mapped to which property). The only requirement is that the sheet data 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.
329
334
 
330
335
  ```js
331
- import { readSheet, parseSheetData } from "read-excel-file/browser"
336
+ import { readSheet } from 'read-excel-file/node'
332
337
 
333
- const data = await readSheet(file)
334
338
  const schema = { ... }
335
- const { objects, errors } = parseSheetData(data, schema)
339
+
340
+ const { objects, errors } = await readSheet(file, { schema })
341
+
336
342
  if (errors) {
337
343
  console.error(errors)
338
344
  } else {
@@ -340,11 +346,11 @@ if (errors) {
340
346
  }
341
347
  ```
342
348
 
343
- The `parseSheetData()` 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`.
344
-
345
- 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.
349
+ The result is `{ objects, errors }`
350
+ * If there were any errors, `objects` will be `undefined` and `errors` will be a list of errors.
351
+ * If there were no errors, `errors` will be `undefined` and `objects` will be a list of objects.
346
352
 
347
- The `schema` argument should describe the structure of the resulting JSON objects. An example of a `schema` is provided at the end of this section.
353
+ `schema` should describe the structure of the resulting JSON objects. An example of a `schema` is provided at the end of this section.
348
354
 
349
355
  Specifically, a `schema` should be an object having the same keys as a resulting JSON object, with values being nested objects having the following properties:
350
356
 
@@ -465,11 +471,8 @@ const schema = {
465
471
  // If this code was written in TypeScript, `schema` would've been declared as:
466
472
  // const schema: Schema<Object, ColumnTitle> = { ... }
467
473
 
468
- // Read `data` from an `.xlsx` file
469
- const data = await readSheet(file)
470
-
471
- // Parse `data` using a `schema`
472
- const { objects, errors } = parseSheetData(data, schema)
474
+ // Read `data` from an `.xlsx` file and parse it using a `schema`.
475
+ const { objects, errors } = await readSheet(file, { schema })
473
476
 
474
477
  // There have been no errors when parsing the sheet data, so `errors` is `undefined`.
475
478
  // Should there have been any errors when parsing the sheet data, `errors` would've been
@@ -503,6 +506,21 @@ function PhoneNumber(value) {
503
506
  }
504
507
  ```
505
508
 
509
+ Also, for convenience, this package exports the same feature as a separate function — `parseSheetData(sheetData, schema)`.
510
+
511
+ ```js
512
+ import { readSheet, parseSheetData } from 'read-excel-file/node'
513
+
514
+ const schema = { ... }
515
+ const sheetData = await readSheet(file)
516
+ const { objects, errors } = parseSheetData(sheetData, schema)
517
+ if (errors) {
518
+ console.error(errors)
519
+ } else {
520
+ console.log(objects)
521
+ }
522
+ ```
523
+
506
524
  <details>
507
525
  <summary>An example of defining a <strong>custom <code>type</code></strong> in <strong>TypeScript</strong></summary>
508
526
 
@@ -1,35 +1,48 @@
1
1
  // The contents of this file is identical between the different exports:
2
2
  // `/node`, `/browser`, etc.
3
3
 
4
- import { Input } from './input.d.js'
4
+ import type { Input } from './input.d.js'
5
5
 
6
- import {
7
- SheetData,
8
- ReadOptions,
9
- ReadFileResult
10
- } from '../types/types.d.js';
6
+ import type {
7
+ SheetData
8
+ } from '../types/SheetData.d.js'
11
9
 
12
- import {
10
+ import type {
11
+ Sheet
12
+ } from '../types/Sheet.d.js'
13
+
14
+ import type {
15
+ Options
16
+ } from '../types/Options.d.js'
17
+
18
+ import type {
19
+ OptionsWithSchema
20
+ } from '../types/OptionsWithSchema.d.js'
21
+
22
+ import type {
13
23
  ParseSheetDataOptions,
14
24
  ParseSheetDataResult
15
- } from '../types/parseSheetData/parseSheetData.d.js';
25
+ } from '../types/parseSheetData/parseSheetData.d.js'
16
26
 
17
- import {
27
+ import type {
18
28
  Schema
19
- } from '../types/parseSheetData/parseSheetDataSchema.d.js';
29
+ } from '../types/parseSheetData/parseSheetDataSchema.d.js'
20
30
 
21
- import {
31
+ import type {
22
32
  ParseSheetDataError
23
- } from '../types/parseSheetData/parseSheetDataError.d.js';
33
+ } from '../types/parseSheetData/parseSheetDataError.d.js'
24
34
 
25
- export {
35
+ export type {
26
36
  CellValue,
27
37
  Row,
28
- SheetData,
38
+ SheetData
39
+ } from '../types/SheetData.d.js'
40
+
41
+ export type {
29
42
  Sheet
30
- } from '../types/types.d.js';
43
+ } from '../types/Sheet.d.js'
31
44
 
32
- export {
45
+ export type {
33
46
  ParseSheetDataCustomType,
34
47
  // Base `type`s when parsing data.
35
48
  StringType as String,
@@ -40,45 +53,55 @@ export {
40
53
  Integer,
41
54
  Email,
42
55
  URL
43
- } from '../types/parseSheetData/parseSheetDataValueType.d.js';
56
+ } from '../types/parseSheetData/parseSheetDataValueType.d.js'
44
57
 
45
- export {
58
+ export type {
46
59
  ParseSheetDataCustomTypeErrorMessage,
47
60
  ParseSheetDataCustomTypeErrorReason,
48
61
  ParseSheetDataError,
49
62
  ParseSheetDataValueRequiredError
50
- } from '../types/parseSheetData/parseSheetDataError.d.js';
63
+ } from '../types/parseSheetData/parseSheetDataError.d.js'
51
64
 
52
- export {
65
+ export type {
53
66
  ParseSheetDataResult
54
- } from '../types/parseSheetData/parseSheetData.d.js';
67
+ } from '../types/parseSheetData/parseSheetData.d.js'
55
68
 
56
- export {
69
+ export type {
57
70
  Schema
58
- } from '../types/parseSheetData/parseSheetDataSchema.d.js';
71
+ } from '../types/parseSheetData/parseSheetDataSchema.d.js'
59
72
 
60
73
  export default function readXlsxFile<ParsedNumber = number>(
61
74
  input: Input,
62
- options?: ReadOptions<ParsedNumber>
63
- ): Promise<ReadFileResult<ParsedNumber>>;
75
+ options?: Options<ParsedNumber>
76
+ ): Promise<Sheet<ParsedNumber>[]>;
64
77
 
65
78
  export function readSheet<ParsedNumber = number>(
66
79
  input: Input,
67
80
  sheet?: number | string,
68
- options?: ReadOptions<ParsedNumber>
81
+ options?: Options<ParsedNumber>
69
82
  ): Promise<SheetData<ParsedNumber>>;
70
83
 
71
84
  export function readSheet<ParsedNumber = number>(
72
85
  input: Input,
73
- options?: ReadOptions<ParsedNumber>
86
+ options?: Options<ParsedNumber>
74
87
  ): Promise<SheetData<ParsedNumber>>;
75
88
 
89
+ export function readSheet<
90
+ Object extends object,
91
+ ColumnTitle extends string = string,
92
+ Error extends ParseSheetDataError = ParseSheetDataError<ColumnTitle>,
93
+ ParsedNumber = number
94
+ >(
95
+ input: Input,
96
+ options: OptionsWithSchema<Object, ColumnTitle, ParsedNumber>
97
+ ): Promise<ParseSheetDataResult<Object, ColumnTitle, Error>>;
98
+
76
99
  export function parseSheetData<
77
100
  Object extends object,
78
- ColumnTitle extends string,
79
- Error extends ParseSheetDataError
101
+ ColumnTitle extends string = string,
102
+ Error extends ParseSheetDataError = ParseSheetDataError<ColumnTitle>
80
103
  >(
81
104
  data: SheetData,
82
105
  schema: Schema<Object, ColumnTitle>,
83
106
  options?: ParseSheetDataOptions
84
- ): ParseSheetDataResult<Object, Error>;
107
+ ): ParseSheetDataResult<Object, ColumnTitle, Error>;