read-excel-file 5.8.0 → 5.8.2

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/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  ParseWithoutSchemaOptions,
5
5
  ParsedObjectsResult,
6
6
  Row
7
- } from './types.d';
7
+ } from './types.d.js';
8
8
 
9
9
  export {
10
10
  Schema,
@@ -13,7 +13,7 @@ export {
13
13
  Integer,
14
14
  Email,
15
15
  URL
16
- } from './types.d';
16
+ } from './types.d.js';
17
17
 
18
18
  export function parseExcelDate(excelSerialDate: number) : typeof Date;
19
19
 
package/map/index.d.ts CHANGED
@@ -8,4 +8,4 @@ export {
8
8
  MappingParameters
9
9
  } from '../types.d.js'
10
10
 
11
- export default function map(data: Row[], schema: Schema, options?: MappingParameters): object[];
11
+ export default function map<T>(data: Row[], schema: Schema<T>, options?: MappingParameters): T[];
package/node/index.d.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  ParseWithoutSchemaOptions,
11
11
  ParsedObjectsResult,
12
12
  Row
13
- } from '../types.d';
13
+ } from '../types.d.js';
14
14
 
15
15
  export {
16
16
  ParsedObjectsResult,
@@ -18,7 +18,7 @@ export {
18
18
  Integer,
19
19
  Email,
20
20
  URL
21
- } from '../types.d';
21
+ } from '../types.d.js';
22
22
 
23
23
  export function parseExcelDate(excelSerialDate: number) : typeof Date;
24
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "read-excel-file",
3
- "version": "5.8.0",
3
+ "version": "5.8.2",
4
4
  "description": "Read small to medium `*.xlsx` files in a browser or Node.js. Parse to JSON with a strict schema.",
5
5
  "module": "index.js",
6
6
  "main": "index.cjs",
package/schema/index.d.ts CHANGED
@@ -3,9 +3,9 @@ import {
3
3
  Schema
4
4
  } from '../types.d.js';
5
5
 
6
- export default function mapWithLegacyBehavior(data: Row[], schema: Schema, options?: {
6
+ export default function mapWithLegacyBehavior<T>(data: Row[], schema: Schema<T>, options?: {
7
7
  ignoreEmptyRows?: boolean,
8
8
  includeNullValues?: boolean,
9
9
  isColumnOriented?: boolean,
10
10
  rowMap?: Record<string, number>
11
- }): object[];
11
+ }): T[];
package/types.d.ts CHANGED
@@ -14,51 +14,55 @@ type BasicType =
14
14
  | typeof URL
15
15
  | typeof Email;
16
16
 
17
- export type Type<T> = (value: Cell) => T | undefined;
17
+ // A cell "type" is a function that receives a "raw" value and returns a "parsed" value or `undefined`.
18
+ export type Type<Value> = (value: Cell) => Value | undefined;
18
19
 
19
- type SchemaEntryRequired = boolean | ((row: Row) => boolean);
20
+ type SchemaEntryRequiredProperty<Object> = boolean | ((row: Object) => boolean);
20
21
 
21
- interface SchemaEntryBasic<T> {
22
- prop: string;
23
- type?: BasicType | Type<T>;
24
- oneOf?: T[];
25
- required?: SchemaEntryRequired;
26
- validate?(value: T): void;
22
+ interface SchemaEntryForValue<Key extends keyof Object, Object, TopLevelObject> {
23
+ prop: Key;
24
+ type?: BasicType | Type<Object[Key]>;
25
+ oneOf?: Object[Key][];
26
+ required?: SchemaEntryRequiredProperty<TopLevelObject>;
27
+ validate?(value: Object[Key]): void;
27
28
  }
28
29
 
29
30
  // Legacy versions of this library supported supplying a custom `parse()` function.
30
31
  // Since then, the `parse()` function has been renamed to `type()` function.
31
- interface SchemaEntryParsed<T> {
32
- prop: string;
33
- parse: (value: Cell) => T | undefined;
34
- oneOf?: T[];
35
- required?: SchemaEntryRequired;
36
- validate?(value: T): void;
32
+ interface SchemaEntryForValueLegacy<Key extends keyof Object, Object, TopLevelObject> {
33
+ prop: Key;
34
+ parse: (value: Cell) => Object[Key] | undefined;
35
+ oneOf?: Object[Key][];
36
+ required?: SchemaEntryRequiredProperty<TopLevelObject>;
37
+ validate?(value: Object[Key]): void;
37
38
  }
38
39
 
39
40
  // Implementing recursive types in TypeScript:
40
41
  // https://dev.to/busypeoples/notes-on-typescript-recursive-types-and-immutability-5ck1
41
- interface SchemaEntryRecursive {
42
- prop: string;
43
- type: Record<string, SchemaEntry>;
44
- required?: SchemaEntryRequired;
42
+ interface SchemaEntryRecursive<Key extends keyof Object, Object, TopLevelObject> {
43
+ prop: Key;
44
+ type: Record<keyof Object[Key], SchemaEntry<keyof Object[Key], Object[Key], TopLevelObject>>;
45
+ required?: SchemaEntryRequiredProperty<TopLevelObject>;
45
46
  }
46
47
 
47
- type SchemaEntry = SchemaEntryBasic<any> | SchemaEntryParsed<any> | SchemaEntryRecursive
48
+ type SchemaEntry<Key extends keyof Object, Object, TopLevelObject> =
49
+ SchemaEntryForValue<Key, Object, TopLevelObject> |
50
+ SchemaEntryForValueLegacy<Key, Object, TopLevelObject> |
51
+ SchemaEntryRecursive<Key, Object, TopLevelObject>
48
52
 
49
- export type Schema = Record<string, SchemaEntry>
53
+ export type Schema<Object = Record<string, any>> = Record<keyof Object, SchemaEntry<keyof Object, Object, Object>>
50
54
 
51
- export interface Error {
55
+ export interface Error<Value = any> {
52
56
  error: string;
53
57
  reason?: string;
54
58
  row: number;
55
59
  column: string;
56
- value?: any;
57
- type?: SchemaEntry;
60
+ value?: Value;
61
+ type?: Type<Value>;
58
62
  }
59
63
 
60
- export interface ParsedObjectsResult<T extends object> {
61
- rows: T[];
64
+ export interface ParsedObjectsResult<Object> {
65
+ rows: Object[];
62
66
  errors: Error[];
63
67
  }
64
68
 
@@ -68,8 +72,8 @@ interface ParseCommonOptions {
68
72
  parseNumber?: (string: string) => any;
69
73
  }
70
74
 
71
- export interface ParseWithSchemaOptions<T extends object> extends ParseCommonOptions, MappingParametersReadExcelFile {
72
- schema: Schema;
75
+ export interface ParseWithSchemaOptions<Object> extends ParseCommonOptions, MappingParametersReadExcelFile {
76
+ schema: Schema<Object>;
73
77
  transformData?: (rows: Row[]) => Row[];
74
78
  ignoreEmptyRows?: boolean;
75
79
  // `includeNullValues: true` parameter is deprecated.
@@ -4,7 +4,7 @@ import {
4
4
  ParseWithoutSchemaOptions,
5
5
  ParsedObjectsResult,
6
6
  Row
7
- } from '../types.d';
7
+ } from '../types.d.js';
8
8
 
9
9
  export {
10
10
  ParsedObjectsResult,
@@ -12,7 +12,7 @@ export {
12
12
  Integer,
13
13
  Email,
14
14
  URL
15
- } from '../types.d';
15
+ } from '../types.d.js';
16
16
 
17
17
  export function parseExcelDate(excelSerialDate: number) : typeof Date;
18
18