wzp
2021-05-13 7d694a9113118daec5be7ac224dab46a3b20f106
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
 
// Generated by CoffeeScript 2.3.2
// # CSV Generator Sync
// Provides a synchronous alternative to the CSV generator.
// ## Usage 
// `const csv = generate(options)`  
// ## Source Code
var generate;
generate = require('.');
 
module.exports = function (options) {
  var chunks, generator, work;
 
  if (typeof options === 'string' && /\d+/.test(options)) {
    options = parseInt(options);
  }
 
  if (Number.isInteger(options)) {
    options = {
      length: options
    };
  }
 
  if (!Number.isInteger(options != null ? options.length : void 0)) {
    throw Error('Invalid Argument: length is not defined');
  }
 
  chunks = [];
  work = true; // See https://nodejs.org/api/stream.html#stream_new_stream_readable_options
 
  options.highWaterMark = options.objectMode ? 16 : 16384;
  generator = new generate.Generator(options);
 
  generator.push = function (chunk) {
    if (chunk === null) {
      return work = false;
    }
 
    if (options.objectMode) {
      return chunks.push(chunk);
    } else {
      return chunks.push(chunk);
    }
  };
 
  while (work) {
    generator._read(options.highWaterMark);
  }
 
  if (!options.objectMode) {
    chunks = chunks.join('');
  }
 
  return chunks;
};