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

Function generate

packages/csv-generate/lib/index.js:61–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59};
60
61const generate = function () {
62 let options;
63 let callback;
64 if (arguments.length === 2) {
65 options = arguments[0];
66 callback = arguments[1];
67 } else if (arguments.length === 1) {
68 if (typeof arguments[0] === "function") {
69 options = {};
70 callback = arguments[0];
71 } else {
72 options = arguments[0];
73 }
74 } else if (arguments.length === 0) {
75 options = {};
76 }
77 const generator = new Generator(options);
78 if (callback) {
79 const data = [];
80 generator.on("readable", function () {
81 let d;
82 while ((d = generator.read()) !== null) {
83 data.push(d);
84 }
85 });
86 generator.on("error", callback);
87 generator.on("end", function () {
88 if (generator.options.objectMode) {
89 callback(null, data);
90 } else {
91 if (generator.options.encoding) {
92 callback(null, data.join(""));
93 } else {
94 callback(null, Buffer.concat(data));
95 }
96 }
97 });
98 }
99 return generator;
100};
101
102export { generate, Generator };

Callers

nothing calls this directly

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected