MCPcopy Create free account
hub / github.com/Inist-CNRS/node-csv-string / parse

Function parse

src/CSV.ts:101–131  ·  view source on GitHub ↗
(
  input: string,
  sepOrOpts?: Comma | Partial<ParseOptions>,
  quo?: Quote
)

Source from the content-addressed store, hash-verified

99 opts: Partial<ParseOptions> & { output: 'objects' }
100): { [k: string]: Value }[];
101function parse(
102 input: string,
103 sepOrOpts?: Comma | Partial<ParseOptions>,
104 quo?: Quote
105): Value[][] | { [k: string]: Value }[] {
106 // Create an options hash, using positional parameters or the passed in options hash for values
107 const opts: Partial<ParseOptions> = typeof sepOrOpts === "object" ? sepOrOpts : {};
108 if (typeof sepOrOpts === "string") {
109 opts.comma = sepOrOpts as Comma;
110 }
111 if (quo) {
112 opts.quote = quo as Quote;
113 }
114
115 // try to detect the separator if not provided
116 if (opts.comma === undefined) {
117 opts.comma = detect(input);
118 }
119
120 // Clean characters, if necessary
121 // TODO: We should probably throw an error here to signal bad input to the user
122 if (opts.comma) {
123 opts.comma = opts.comma[0] as Comma;
124 }
125 if (opts.quote) {
126 opts.quote = opts.quote[0] as Quote;
127 }
128
129 const csv = new Parser(input, opts.comma, opts.quote);
130 return csv.File(opts.output);
131};
132
133function read(input: string, callback: ReadCallback): number;
134function read(input: string, sep: Comma, callback: ReadCallback): number;

Callers

nothing calls this directly

Calls 2

FileMethod · 0.95
detectFunction · 0.85

Tested by

no test coverage detected