MCPcopy
hub / github.com/adaltas/node-csv / parse

Function parse

packages/csv-parse/lib/sync.js:4–20  ·  view source on GitHub ↗
(data, opts = {})

Source from the content-addressed store, hash-verified

2import { normalize_options } from "./api/normalize_options.js";
3
4const parse = function (data, opts = {}) {
5 if (typeof data === "string") {
6 data = Buffer.from(data);
7 }
8 const records = opts && opts.objname ? Object.create(null) : [];
9 const parser = transform(opts);
10 const push = (record) => {
11 if (parser.options.objname === undefined) records.push(record);
12 else {
13 records[record[0]] = record[1];
14 }
15 };
16 const close = () => {};
17 const error = parser.parse(data, true, push, close);
18 if (error !== undefined) throw error;
19 return records;
20};
21
22export { parse, CsvError, normalize_options };

Calls 1

transformFunction · 0.90

Tested by

no test coverage detected