(data, opts = {})
| 2 | import { normalize_options } from "./api/normalize_options.js"; |
| 3 | |
| 4 | const 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 | |
| 22 | export { parse, CsvError, normalize_options }; |
no test coverage detected