@@ -7,7 +7,7 @@ import * as stream from "stream";
7
7
export type Callback < T = string [ ] > = (
8
8
err : CsvError | undefined ,
9
9
records : T [ ] ,
10
- info ?: Info ,
10
+ info ?: InfoCallback ,
11
11
) => void ;
12
12
13
13
export class Parser extends stream . Transform {
@@ -25,59 +25,66 @@ export class Parser extends stream.Transform {
25
25
26
26
export interface Info {
27
27
/**
28
- * Count the number of lines being fully commented.
28
+ * The number of processed bytes.
29
+ */
30
+ readonly bytes : number ;
31
+ /**
32
+ * The number of processed bytes until the last successfully parsed and emitted records.
33
+ */
34
+ readonly bytes_records : number ;
35
+ /**
36
+ * The number of lines being fully commented.
29
37
*/
30
38
readonly comment_lines : number ;
31
39
/**
32
- * Count the number of processed empty lines.
40
+ * The number of processed empty lines.
33
41
*/
34
42
readonly empty_lines : number ;
43
+ /**
44
+ * The number of non uniform records when `relax_column_count` is true.
45
+ */
46
+ readonly invalid_field_length : number ;
35
47
/**
36
48
* The number of lines encountered in the source dataset, start at 1 for the first line.
37
49
*/
38
50
readonly lines : number ;
39
51
/**
40
- * Count the number of processed records.
52
+ * The number of processed records.
41
53
*/
42
54
readonly records : number ;
43
- /**
44
- * Count of the number of processed bytes.
45
- */
46
- readonly bytes : number ;
47
- /**
48
- * Number of non uniform records when `relax_column_count` is true.
49
- */
50
- readonly invalid_field_length : number ;
55
+ }
56
+
57
+ export interface InfoCallback extends Info {
51
58
/**
52
59
* Normalized verion of `options.columns` when `options.columns` is true, boolean otherwise.
53
60
*/
54
61
readonly columns : boolean | { name : string } [ ] | { disabled : true } [ ] ;
55
62
}
56
63
57
- export interface CastingContext {
64
+ export interface InfoDataSet extends Info {
58
65
readonly column : number | string ;
59
- readonly bytes : number ;
60
- readonly bytes_records : number ;
61
- readonly empty_lines : number ;
66
+ }
67
+
68
+ export interface InfoRecord extends InfoDataSet {
62
69
readonly error : CsvError ;
63
70
readonly header : boolean ;
64
71
readonly index : number ;
65
- readonly quoting : boolean ;
66
- readonly lines : number ;
67
72
readonly raw : string | undefined ;
68
- readonly records : number ;
69
- readonly invalid_field_length : number ;
70
73
}
71
74
72
- export type CastingFunction = (
73
- value : string ,
74
- context : CastingContext ,
75
- ) => unknown ;
75
+ export interface InfoField extends InfoRecord {
76
+ readonly quoting : boolean ;
77
+ }
78
+
79
+ /**
80
+ * @deprecated Use the InfoField interface instead, the interface will disappear in future versions.
81
+ */
82
+ // eslint-disable-next-line
83
+ export interface CastingContext extends InfoField { }
84
+
85
+ export type CastingFunction = ( value : string , context : InfoField ) => unknown ;
76
86
77
- export type CastingDateFunction = (
78
- value : string ,
79
- context : CastingContext ,
80
- ) => Date ;
87
+ export type CastingDateFunction = ( value : string , context : InfoField ) => Date ;
81
88
82
89
export type ColumnOption < K = string > =
83
90
| K
@@ -183,7 +190,7 @@ export interface OptionsNormalized<T = string[]> {
183
190
/**
184
191
* Alter and filter records by executing a user defined function.
185
192
*/
186
- on_record ?: ( record : T , context : CastingContext ) => T | undefined ;
193
+ on_record ?: ( record : T , context : InfoRecord ) => T | undefined ;
187
194
/**
188
195
* Optional character surrounding a field, one character only, defaults to double quotes.
189
196
*/
@@ -359,8 +366,8 @@ export interface Options<T = string[]> {
359
366
/**
360
367
* Alter and filter records by executing a user defined function.
361
368
*/
362
- on_record ?: ( record : T , context : CastingContext ) => T | null | undefined ;
363
- onRecord ?: ( record : T , context : CastingContext ) => T | null | undefined ;
369
+ on_record ?: ( record : T , context : InfoRecord ) => T | null | undefined ;
370
+ onRecord ?: ( record : T , context : InfoRecord ) => T | null | undefined ;
364
371
/**
365
372
* Function called when an error occured if the `skip_records_with_error`
366
373
* option is activated.
0 commit comments