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

Function generate

packages/csv-generate/lib/sync.js:10–39  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

8import { Generator } from "./index.js";
9
10const generate = function (options) {
11 if (typeof options === "string" && /\d+/.test(options)) {
12 options = parseInt(options);
13 }
14 if (Number.isInteger(options)) {
15 options = { length: options };
16 } else if (typeof options !== "object" || options === null) {
17 throw Error("Invalid Argument: options must be an object or an integer");
18 }
19 if (!Number.isInteger(options.length)) {
20 throw Error("Invalid Argument: length is not defined");
21 }
22 const chunks = [];
23 let work = true;
24 const generator = new Generator(options);
25 generator.push = function (chunk) {
26 if (chunk === null) {
27 return (work = false);
28 }
29 chunks.push(chunk);
30 };
31 while (work) {
32 generator.__read(options.highWaterMark);
33 }
34 if (!options.objectMode) {
35 return chunks.join("");
36 } else {
37 return chunks;
38 }
39};
40
41export { generate };

Callers 15

async.iterator.jsFile · 0.90
recipe.pipe.jsFile · 0.90
info.bytes.tsFile · 0.90
api.arguments.tsFile · 0.90
api.stream.pipe.tsFile · 0.90
writeFunction · 0.90
api.pipe.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected