<commit_before>const csvWriter = require('csv-write-stream')
const faker = require('faker')
const from = require('from2-array')
const nes = require('never-ending-stream')
const through = require('through2')
const pumpify = require('pumpify')

module.exports = function randoCsv (headers, count) {
  const writer = csvWriter()
  const csvHeaders = []
  const types = {}
  const methods = {}

  headers.forEach((header) => {
    csvHeaders.push(header.name)
    types[header.name] = header.type
    methods[header.name] = header.method
  })

  let row = {}
  let headersCount = csvHeaders.length

  const ts = through.obj((chunk, enc, cb) => {
    const type = types[chunk]
    const method = methods[chunk]
    row[chunk] = faker[type][method]()
    headersCount -= 1
    if (headersCount === 0) {
      ts.push(row)
      headersCount = csvHeaders.length
    }
    cb()
  })

  const ss = nes.obj(() => {
    if (count === 0) return null
    count -= 1
    return from.obj(csvHeaders)
  })

  return pumpify.obj(ss, ts, writer)
}
<commit_msg>pass options to next lib<commit_after>const csvWriter = require('csv-write-stream')
const faker = require('faker')
const from = require('from2-array')
const nes = require('never-ending-stream')
const through = require('through2')
const pumpify = require('pumpify')

module.exports = function randoCsv (headers, count, options) {
  const writer = csvWriter(options)
  const csvHeaders = []
  const types = {}
  const methods = {}

  headers.forEach((header) => {
    csvHeaders.push(header.name)
    types[header.name] = header.type
    methods[header.name] = header.method
  })

  let row = {}
  let headersCount = csvHeaders.length

  const ts = through.obj((chunk, enc, cb) => {
    const type = types[chunk]
    const method = methods[chunk]
    row[chunk] = faker[type][method]()
    headersCount -= 1
    if (headersCount === 0) {
      ts.push(row)
      headersCount = csvHeaders.length
    }
    cb()
  })

  const ss = nes.obj(() => {
    if (count === 0) return null
    count -= 1
    return from.obj(csvHeaders)
  })

  return pumpify.obj(ss, ts, writer)
}

{'fraction_non_alphanumeric': 0.14542870677404074, 'fraction_numerical': 0.005684509711037423, 'mean_word_length': 3.3278688524590163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1900052', 'n_tokens_mistral': 703, 'n_tokens_neox': 672, 'n_words': 167}