How to use the fast-csv.writeToString function in fast-csv

To help you get started, we’ve selected a few fast-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 DFEAGILEDEVOPS / MTC / admin / services / generate-error-csv.service.js View on Github external
service.generate = async (school, headers, csvData) => {
  const errorsCsv = []
  headers.push('Errors')
  errorsCsv.push(headers)
  csvData.forEach((p) => errorsCsv.push(p))
  const csvStr = await csv.writeToString(errorsCsv, { headers: true })
  // Upload csv to Azure
  let file
  try {
    const remoteFilename = `${school.id}_${uuidv4()}_${moment().format('YYYYMMDDHHmmss')}_error.csv`
    const streamLength = 512 * 1000
    file = await azureFileDataService.azureUploadFile('csvuploads', remoteFilename, csvStr, streamLength)
  } catch (error) {
    return { hasError: true, error }
  }
  return { file }
}
github antonycourtney / tad / src / components / GridPane.js View on Github external
copyManager.onCopyCells.subscribe((e, args) => {
      const range = args.ranges[0]
      let copyData = []
      const gridCols = this.grid.getColumns()
      const gridData = this.grid.getData()
      for (let row = range.fromRow; row <= range.toRow; row++) {
        const rowData = gridData.getItem(row)
        const copyRow = []
        for (let col = range.fromCell; col <= range.toCell; col++) {
          const cid = gridCols[col].id
          copyRow.push(rowData[cid])
        }
        copyData.push(copyRow)
      }
      csv.writeToString(copyData, {headers: false}, (err, data) => {
        if (err) {
          console.error('error converting copied data to CSV: ', err)
          return
        }
        clipboard.writeText(data)
      })
    })
github Bajdzis / vscode-database / src / extension / Manager.ts View on Github external
if(typeof data.message !== 'undefined'){
            this.outputMsg(data.message);
            asciiTable([{
                fieldCount: data.fieldCount,
                affectedRows: data.affectedRows,
                insertId: data.insertId,
                serverStatus: data.serverStatus,
                warningCount: data.warningCount,
                changedRows: data.changedRows
            }], this.outputMsg);
        }else if(typeof data === 'object'){
            const noResult = data.length === 0;
            if (noResult) {
                this.outputMsg('Query result 0 rows!');
            } else {
                csv.writeToString(
                    data,
                    {headers: true},
                    (err: Error, dataCSV: string) => {
                        vscode.workspace.openTextDocument().then(doc => {
                            vscode.window.showTextDocument(doc, 2, false).then(e => {
                                e.edit(edit => {
                                    edit.insert(new vscode.Position(0, 0), dataCSV);
                                });
                            });
                        }, (error) => {
                            vscode.window.showErrorMessage(error);
                        });
                    }
                );
            }
        }else{
github runnerty / runnerty / executors / runnerty-executor-mysql / index.js View on Github external
function evaluateResults(results, resolve, reject) {
      if (results instanceof Array) {

        csv.writeToString(results, {headers: true}, function (err, data) {
          if (err) {
            _this.logger.log('error', `Generating csv output for execute_db_results_csv: ${err}. Results: ${results}`);
          }
          endOptions.execute_db_results = JSON.stringify(results);
          endOptions.execute_db_results_object = results;
          endOptions.execute_db_results_csv = data;
          _this.end(endOptions, resolve, reject);
        });

      } else {

        if (results instanceof Object) {
          endOptions.execute_db_results = '';
          endOptions.execute_db_results_object = [];
          endOptions.execute_db_results_csv = '';
          endOptions.execute_db_fieldCount = results.fieldCount;
github DFEAGILEDEVOPS / MTC / admin / services / psychometrician-report.service.js View on Github external
return new Promise((resolve, reject) => {
    csv.writeToString(
      output,
      { headers: headers },
      function (err, data) {
        if (err) { reject(err) }
        resolve(data)
      }
    )
  })
}
github runnerty / runnerty / executors / runnerty-executor-postgres / index.js View on Github external
function evaluateResults(results, resolve, reject) {

      if (results.rows && results.rows.length > 0) {
        endOptions.end = 'end';
        endOptions.execute_db_results = JSON.stringify(results.rows);
        endOptions.execute_db_results_object = results.rows;
        csv.writeToString(results.rows, {headers: true}, function (err, data) {
          if (err) {
            _this.logger.log('error', `Generating csv output for execute_db_results_csv for ${_this.processId}(${_this.processUId}): ${err}. Results: ${results}`);
          } else {
            endOptions.execute_db_results_csv = data;
          }
          _this.end(endOptions, resolve, reject);
        });

      } else {

        if (results instanceof Object) {
          endOptions.execute_db_results = '';
          endOptions.execute_db_results_csv = '';
          endOptions.execute_db_results_object = [];
          endOptions.execute_db_fieldCount = results.rowCount;
          endOptions.execute_db_affectedRows = '';