MCPcopy Create free account
hub / github.com/denoland/std / parse

Function parse

csv/parse.ts:503–531  ·  view source on GitHub ↗
(
  input: string,
  options: T = { skipFirstRow: false } as T,
)

Source from the content-addressed store, hash-verified

501 options: T,
502): ParseResult<ParseOptions, T>;
503export function parse<const T extends ParseOptions>(
504 input: string,
505 options: T = { skipFirstRow: false } as T,
506): ParseResult<ParseOptions, T> {
507 const parser = new Parser(options);
508 const r = parser.parse(input);
509
510 if (options.skipFirstRow || options.columns) {
511 let headers: readonly string[] = [];
512
513 if (options.skipFirstRow) {
514 const head = r.shift();
515 if (head === undefined) {
516 throw new TypeError("Cannot parse input: headers must be defined");
517 }
518 headers = head;
519 }
520
521 if (options.columns) {
522 headers = options.columns;
523 }
524
525 const zeroBasedFirstLineIndex = options.skipFirstRow ? 1 : 0;
526 return r.map((row, i) => {
527 return convertRowToObject(row, headers, zeroBasedFirstLineIndex + i);
528 }) as ParseResult<ParseOptions, T>;
529 }
530 return r as ParseResult<ParseOptions, T>;
531}

Callers 1

fnFunction · 0.90

Calls 2

parseMethod · 0.95
convertRowToObjectFunction · 0.90

Tested by

no test coverage detected