@@ -7,7 +7,7 @@ import * as stream from "stream";
77export type Callback < T = string [ ] > = (
88 err : CsvError | undefined ,
99 records : T [ ] ,
10- info ?: Info ,
10+ info ?: InfoCallback ,
1111) => void ;
1212
1313export class Parser extends stream . Transform {
@@ -25,59 +25,66 @@ export class Parser extends stream.Transform {
2525
2626export interface Info {
2727 /**
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.
2937 */
3038 readonly comment_lines : number ;
3139 /**
32- * Count the number of processed empty lines.
40+ * The number of processed empty lines.
3341 */
3442 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 ;
3547 /**
3648 * The number of lines encountered in the source dataset, start at 1 for the first line.
3749 */
3850 readonly lines : number ;
3951 /**
40- * Count the number of processed records.
52+ * The number of processed records.
4153 */
4254 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 {
5158 /**
5259 * Normalized verion of `options.columns` when `options.columns` is true, boolean otherwise.
5360 */
5461 readonly columns : boolean | { name : string } [ ] | { disabled : true } [ ] ;
5562}
5663
57- export interface CastingContext {
64+ export interface InfoDataSet extends Info {
5865 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 {
6269 readonly error : CsvError ;
6370 readonly header : boolean ;
6471 readonly index : number ;
65- readonly quoting : boolean ;
66- readonly lines : number ;
6772 readonly raw : string | undefined ;
68- readonly records : number ;
69- readonly invalid_field_length : number ;
7073}
7174
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 ;
7686
77- export type CastingDateFunction = (
78- value : string ,
79- context : CastingContext ,
80- ) => Date ;
87+ export type CastingDateFunction = ( value : string , context : InfoField ) => Date ;
8188
8289export type ColumnOption < K = string > =
8390 | K
@@ -183,7 +190,7 @@ export interface OptionsNormalized<T = string[]> {
183190 /**
184191 * Alter and filter records by executing a user defined function.
185192 */
186- on_record ?: ( record : T , context : CastingContext ) => T | undefined ;
193+ on_record ?: ( record : T , context : InfoRecord ) => T | undefined ;
187194 /**
188195 * Optional character surrounding a field, one character only, defaults to double quotes.
189196 */
@@ -359,8 +366,8 @@ export interface Options<T = string[]> {
359366 /**
360367 * Alter and filter records by executing a user defined function.
361368 */
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 ;
364371 /**
365372 * Function called when an error occured if the `skip_records_with_error`
366373 * option is activated.
0 commit comments