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

Method processCSV

src/ProcessorLocal.ts:75–119  ·  view source on GitHub ↗
(csv: string, finalChunk: boolean)

Source from the content-addressed store, hash-verified

73 })
74 }
75 private processCSV(csv: string, finalChunk: boolean): Promise<ProcessLineResult[]> {
76 const params = this.params;
77 const runtime = this.runtime;
78 if (!runtime.eol) {
79 getEol(csv, runtime);
80 }
81 if (this.needEmitEol && !this.eolEmitted && runtime.eol) {
82 this.converter.emit("eol", runtime.eol);
83 this.eolEmitted = true;
84 }
85 // trim csv file has initial blank lines.
86 if (params.ignoreEmpty && !runtime.started) {
87 csv = trimLeft(csv);
88 }
89 const stringToLineResult = stringToLines(csv, runtime);
90 if (!finalChunk) {
91 this.prependLeftBuf(bufFromString(stringToLineResult.partial));
92 } else {
93 stringToLineResult.lines.push(stringToLineResult.partial);
94 stringToLineResult.partial = "";
95 }
96 if (stringToLineResult.lines.length > 0) {
97 let prom: Promise<string[]>;
98 if (runtime.preFileLineHook) {
99 prom = this.runPreLineHook(stringToLineResult.lines);
100 } else {
101 prom = Promise.resolve(stringToLineResult.lines);
102 }
103 return prom.then((lines) => {
104 if (!runtime.started
105 && !this.runtime.headers
106 ) {
107 return this.processDataWithHead(lines);
108 } else {
109 return this.processCSVBody(lines);
110 }
111
112 })
113
114 } else {
115
116 return Promise.resolve([]);
117 }
118
119 }
120 private processDataWithHead(lines: string[]): ProcessLineResult[] {
121 if (this.params.noheader) {
122 if (this.params.headers) {

Callers 4

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

Calls 8

prependLeftBufMethod · 0.95
runPreLineHookMethod · 0.95
processDataWithHeadMethod · 0.95
processCSVBodyMethod · 0.95
trimLeftFunction · 0.90
stringToLinesFunction · 0.90
bufFromStringFunction · 0.90
thenMethod · 0.80

Tested by

no test coverage detected