-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.d.ts
More file actions
166 lines (137 loc) · 4.71 KB
/
index.d.ts
File metadata and controls
166 lines (137 loc) · 4.71 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
declare module 'convert-csv-to-json' {
export class ConvertCsvToJson {
/**
* Prints a digit as Number type (for example 32 instead of '32')
*/
formatValueByType(active: boolean): this;
/**
* Removes any whitespaces in the header field
* @defaultValue `false`
*/
trimHeaderFieldWhiteSpace(active: boolean): this;
/**
* Makes parser aware of quoted fields
* @defaultValue `false`
*/
supportQuotedField(active: boolean): this;
/**
* Defines the field delimiter which will be used to split the fields
*/
fieldDelimiter(delimiter: string): this;
/**
* Defines the index where the header is defined
*/
indexHeader(index: number): this;
/**
* Defines how to match and parse a sub array
*/
parseSubArray(delimiter: string, separator: string): this;
/**
* Defines a custom encoding to decode a file
*/
customEncoding(encoding: string): this;
/**
* Defines a custom encoding to decode a file
*/
utf8Encoding(): this;
/**
* Defines ucs2 encoding to decode a file
*/
ucs2Encoding(): this;
/**
* Defines utf16le encoding to decode a file
*/
utf16leEncoding(): this;
/**
* Defines latin1 encoding to decode a file
*/
latin1Encoding(): this;
/**
* Defines ascii encoding to decode a file
*/
asciiEncoding(): this;
/**
* Defines base64 encoding to decode a file
*/
base64Encoding(): this;
/**
* Defines hex encoding to decode a file
*/
hexEncoding(): this;
/**
* Sets a mapper function to transform each row after conversion.
* The mapper function receives (row, index) where row is the JSON object
* and index is the 0-based row number. Return null/undefined to filter out rows.
* @param mapperFn Function that receives (row: any, index: number) => any | null
*/
mapRows(mapperFn: (row: any, index: number) => any | null): this;
/**
* Parses .csv file and put its content into a file in json format.
* @param {inputFileName} path/filename
* @param {outputFileName} path/filename
*
*/
generateJsonFileFromCsv(
inputFileName: string,
outputFileName: string,
): void;
/**
* Parses .csv file and put its content into an Array of Object in json format.
* @param {inputFileName} path/filename
* @return {Array} Array of Object in json format
*
*/
getJsonFromCsv(inputFileName: string): any[];
/**
* Async version of getJsonFromCsv. When options.raw is true the input is treated as a CSV string
*/
getJsonFromCsvAsync(inputFileNameOrCsv: string, options?: { raw?: boolean }): Promise<any[]>;
/**
* Parse CSV from a Readable stream and return parsed data as JSON array
* Processes data in chunks for memory-efficient handling of large files
*/
getJsonFromStreamAsync(stream: NodeJS.ReadableStream): Promise<any[]>;
/**
* Parse CSV from a file path using streaming for memory-efficient processing
*/
getJsonFromFileStreamingAsync(filePath: string): Promise<any[]>;
csvStringToJson(csvString: string): any[];
/**
* Parses a csv string and returns a JSON string (validated)
* @param {csvString} csvString CSV content as string
* @return {string} JSON stringified result
*/
csvStringToJsonStringified(csvString: string): string;
}
const converter: ConvertCsvToJson;
export default converter;
/**
* Browser API exposes parsing helpers for browser environments
*/
export interface BrowserApi {
formatValueByType(active: boolean): this;
trimHeaderFieldWhiteSpace(active: boolean): this;
supportQuotedField(active: boolean): this;
fieldDelimiter(delimiter: string): this;
indexHeader(index: number): this;
parseSubArray(delimiter: string, separator: string): this;
mapRows(mapperFn: (row: any, index: number) => any | null): this;
csvStringToJson(csvString: string): any[];
csvStringToJsonStringified(csvString: string): string;
csvStringToJsonAsync(csvString: string): Promise<any[]>;
csvStringToJsonStringifiedAsync(csvString: string): Promise<string>;
/**
* Parse a File or Blob and return a Promise that resolves to the JSON array
*/
parseFile(file: Blob | File, options?: { encoding?: string }): Promise<any[]>;
/**
* Parse CSV from a ReadableStream and return parsed data as JSON array
*/
getJsonFromStreamAsync(stream: any): Promise<any[]>;
/**
* Parse CSV from a File object using streaming for memory-efficient processing
*/
getJsonFromFileStreamingAsync(file: File): Promise<any[]>;
}
export const browser: BrowserApi;
}