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

Function stringify

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

Source from the content-addressed store, hash-verified

2import { normalize_options } from "./api/normalize_options.js";
3
4const stringify = function (records, opts = {}) {
5 const data = [];
6 const [err, options] = normalize_options(opts);
7 if (err !== undefined) throw err;
8 const state = {
9 stop: false,
10 };
11 // Information
12 const info = {
13 records: 0,
14 };
15 const api = stringifier(options, state, info);
16 for (const record of records) {
17 const err = api.__transform(record, function (record) {
18 data.push(record);
19 });
20 if (err !== undefined) throw err;
21 }
22 if (data.length === 0) {
23 api.bom((d) => {
24 data.push(d);
25 });
26 const err = api.headers((headers) => {
27 data.push(headers);
28 });
29 if (err !== undefined) throw err;
30 }
31 return data.join("");
32};
33
34export { stringify };

Calls 2

normalize_optionsFunction · 0.90
stringifierFunction · 0.90

Tested by

no test coverage detected