How to use the csv.stringify function in csv

To help you get started, we’ve selected a few csv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dremio / dremio-oss / dac / ui / licenseCheck.js View on Github external
// check if there is any error
      let isError = false;

      data.forEach((module) => {
        if (module.isError) {
          isError = true;
          console.error(`module: '${module.name}@${module.version}'. ${module.errorMessage}`, module);
        }
      });

      if (isError) {
        process.exit(-1);
      }

      csv.stringify(data, {
        header: true,
        columns: {
          '_': '', // placeholder
          name: 'name',
          groupId: 'groupId', // not a field we have
          artifactId: 'artifactId', // not a field we have
          version: 'version',
          repository: 'url',
          licenses: 'license',
          'in distribution': 'in distribution', // not a field we have
          checked: 'checked', // not a field we have
          text: 'text', // not a field we have
          copyright: 'notice',
          comment: 'comment' // placeholder
        }
      }, (error, cvsText) => {
github adblockplus / adblockplusui / build / csv-export.js View on Github external
function arrayToCsv(csvArray)
{
  csv.stringify(csvArray, (err, output) =>
  {
    writeFile(outputFileName, output, "utf8").then(() =>
    {
      // eslint-disable-next-line no-console
      console.log(`${outputFileName} is created`);
    }).catch((error) =>
    {
      console.error(error);
    });
  });
}
github slifty / tvarchive-faceomatic / src / server / index.js View on Github external
const tsvFile = fs.createWriteStream(tsvPath)
  const columns = [
    'Label',
    'Name',
    'Network',
    'Program',
    'Air Date',
    'Air Time',
    'Duration',
    'Archive ID',
    'URL',
    'Model ID',
  ]

  // Set up the CSV Pipeline
  const csvStringifier = csv.stringify({
    header: true,
    columns,
  })
  csvStringifier.on('readable', () => {
    let data = null
    // eslint-disable-next-line no-cond-assign
    while (data = csvStringifier.read()) {
      csvFile.write(data)
    }
  })

  // Set up the TSV Pipeline
  const tsvStringifier = csv.stringify({
    header: true,
    columns,
    delimiter: '\t',
github CVCEeu-dh / histograph / scripts / tasks / helpers.js View on Github external
stringify: function(options, callback) {
      console.log(clc.yellowBright('\n   tasks.helpers.csv.stringify'));
      if(!options.filepath) {
        return callback(' Please specify the output csv file path with --filepath=path/to/source.tsv');
      }
      csv.stringify(options.records, {
        delimiter: options.delimiter || '\t',
        columns:   options.fields,
        header:    true
      }, function (err, data) {
        fs.writeFile(options.filepath,
           data, function (err) {
          if(err) {
            callback(err);
            return
          }
          console.log(clc.blackBright('   file created successfully:', clc.cyanBright(options.filepath), 'containing', clc.magentaBright(options.records.length),'records'));
        
          callback(null, options);
        })
      });
    },
github stanford-oval / thingtalk / tools / clean_paraphrase.js View on Github external
//const formatted = '/home/silei/Workspace/mturk/acl18/batch_3/paraphrase_out_formatted.csv'
    //const cleaned = '/home/silei/Workspace/mturk/acl18/batch_3/paraphrase_out_cleaned.tsv'
    const task = process.argv[2];
    const parser = csv.parse();
    if (task === 'clean') {
        const formatted = process.argv[3];
        const cleaned = process.argv[4]
        const input = fs.createReadStream(formatted).pipe(parser);
        const output = csv.stringify({ header: true, delimiter: '\t' });
        output.pipe(fs.createWriteStream(cleaned));
        clean_paraphrase(input, output);
    } else if (task === 'mark') {
        const raw = process.argv[3];
        const marked = process.argv[4];
        const input = fs.createReadStream(raw).pipe(parser);
        const output = csv.stringify({ header: true, delimiter: ','});
        output.pipe(fs.createWriteStream(marked));
        mark_paraphrase(input, output);
    }
}
github okfn / opendatasurvey / census / controllers / api.js View on Github external
var outputItemsAsCsv = function(response, items, mapper, columns) {
  var options = {
    delimiter: ',',
    quote: '"',
    quoted: true,
    rowDelimiter: 'unix'
  };
  if (_.isArray(columns)) {
    options.header = true;
    options.columns = columns;
  }
  if (_.isFunction(mapper)) {
    items = _.map(items, mapper);
  }
  var stringify = csv.stringify(items, options);
  response.header('Content-Type', 'text/csv');
  stringify.pipe(response);
};
github okfn / opendatasurvey / census / controllers / api.js View on Github external
let outputItemsAsCsv = function(response, items, mapper, columns) {
  let options = {
    delimiter: ',',
    quote: '"',
    quoted: true,
    rowDelimiter: 'unix'
  };
  if (_.isArray(columns)) {
    options.header = true;
    options.columns = columns;
  }
  if (_.isFunction(mapper)) {
    items = _.map(items, mapper);
  }
  let stringify = csv.stringify(items, options);
  response.header('Content-Type', 'text/csv');
  stringify.pipe(response);
};
github stanford-oval / almond-cloud / scripts / prepare_for_turking.js View on Github external
function main() {
    const input = byline(process.stdin);
    input.setEncoding('utf8');
    const output = csv.stringify({ header: true, delimiter: '\t' });
    const file = fs.createWriteStream(process.argv[2]);
    output.pipe(file);
    
    const by_signature = false;
    const compound_only = false;

    if (by_signature)
        prepare_sample_by_sig(input, output);
    else
        prepare_sample_by_code(input, output, compound_only);
   
}
main();
github polonel / trudesk / src / controllers / api / v1 / reports.js View on Github external
function processResponse (res, input) {
  var headers = {
    uid: 'uid',
    type: 'type',
    priority: 'priority',
    status: 'status',
    created: 'created',
    subject: 'subject',
    requester: 'requester',
    group: 'group',
    assignee: 'assignee',
    tags: 'tags'
  }

  csv.stringify(input, { header: true, columns: headers }, function (err, output) {
    if (err) return res.status(400).json({ success: false, error: err })

    res.setHeader('Content-disposition', 'attachment; filename=report_output.csv')
    res.set('Content-Type', 'text/csv')
    res.send(output)
  })
}

csv

A mature CSV toolset with simple api, full of options and tested against large datasets.

MIT
Latest version published 2 months ago

Package Health Score

93 / 100
Full package analysis