MCPcopy Create free account
hub / github.com/Keyang/node-csvtojson / processDataWithHead

Method processDataWithHead

src/ProcessorLocal.ts:120–160  ·  view source on GitHub ↗
(lines: string[])

Source from the content-addressed store, hash-verified

118
119 }
120 private processDataWithHead(lines: string[]): ProcessLineResult[] {
121 if (this.params.noheader) {
122 if (this.params.headers) {
123 this.runtime.headers = this.params.headers;
124 } else {
125 this.runtime.headers = [];
126 }
127 } else {
128 let left = "";
129 let headerRow: string[] = [];
130 while (lines.length) {
131 const line = left + lines.shift();
132 const row = this.rowSplit.parse(line);
133 if (row.closed) {
134 headerRow = row.cells;
135 left = "";
136 break;
137 } else {
138 left = line + getEol(line, this.runtime);
139 }
140 }
141 this.prependLeftBuf(bufFromString(left));
142
143 if (headerRow.length === 0) {
144 return [];
145 }
146 if (this.params.headers) {
147 this.runtime.headers = this.params.headers;
148 } else {
149 this.runtime.headers = headerRow;
150 }
151 }
152 if (this.runtime.needProcessIgnoreColumn || this.runtime.needProcessIncludeColumn) {
153 this.filterHeader();
154 }
155 if (this.needEmitHead && !this.headEmitted) {
156 this.converter.emit("header", this.runtime.headers);
157 this.headEmitted = true;
158 }
159 return this.processCSVBody(lines);
160 }
161 private filterHeader() {
162 this.runtime.selectedColumns = [];
163 if (this.runtime.headers) {

Callers 4

processCSVMethod · 0.95
browser.jsFile · 0.80
csvtojson.min.jsFile · 0.80
ProcessorLocal.jsFile · 0.80

Calls 5

prependLeftBufMethod · 0.95
filterHeaderMethod · 0.95
processCSVBodyMethod · 0.95
bufFromStringFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected