ParseRuntime.ts
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { CSVParseParam, CellParser } from "./Parameters";
import { Converter, PreRawDataCallback, PreFileLineCallback } from "./Converter";
import { ChildProcess } from "child_process";
import CSVError from "./CSVError";
export interface ParseRuntime {
/**
* If need convert ignoreColumn from column name(string) to column index (number). Parser needs column index.
*/
needProcessIgnoreColumn: boolean;
/**
* If need convert includeColumn from column name(string) to column index (number). Parser needs column index.
*/
needProcessIncludeColumn: boolean;
/**
* the indexes of columns to reserve, undefined means reserve all, [] means hide all
*/
selectedColumns?: number[];
ended: boolean;
hasError: boolean;
error?: Error;
/**
* Inferred delimiter
*/
delimiter: string | string[];
/**
* Inferred eol
*/
eol?: string;
/**
* Converter function for a column. Populated at runtime.
*/
columnConv: (CellParser | null)[],
headerType: any[],
headerTitle: string[],
headerFlag: any[],
/**
* Inferred headers
*/
headers?: any[],
csvLineBuffer?: Buffer,
/**
* after first chunk of data being processed and emitted, started will become true.
*/
started: boolean,
preRawDataHook?: PreRawDataCallback,
preFileLineHook?: PreFileLineCallback,
parsedLineNumber: number,
columnValueSetter: Function[];
subscribe?: {
onNext?: (data: any, lineNumber:number) => void | PromiseLike<void>;
onError?: (err: CSVError) => void;
onCompleted?: () => void;
};
then?: {
onfulfilled: (value: any[]) => any;
onrejected: (err: Error) => any;
}
}
export function initParseRuntime(converter: Converter): ParseRuntime {
const params = converter.parseParam;
const rtn: ParseRuntime = {
needProcessIgnoreColumn: false,
needProcessIncludeColumn: false,
selectedColumns: undefined,
ended: false,
hasError: false,
error: undefined,
delimiter: converter.parseParam.delimiter,
eol: converter.parseParam.eol,
columnConv: [],
headerType: [],
headerTitle: [],
headerFlag: [],
headers: undefined,
started: false,
parsedLineNumber: 0,
columnValueSetter: [],
}
if (params.ignoreColumns) {
rtn.needProcessIgnoreColumn = true;
}
if (params.includeColumns) {
rtn.needProcessIncludeColumn = true;
}
return rtn;
}