How to use the fast-csv.fromString 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 open-apparel-registry / open-apparel-registry / src / restify / src / controllers / factoryController.js View on Github external
this.uploadFactory = (req, res) => {
    if (!req.body) {
      return res.send('No files were uploaded.');
    }

    const factoryFile = req.body;
    const factories = [];
    const { file_name, uid, name } = req.params;
    const newTimestamp = new Date().getTime();
    const fileName = `${file_name}_${newTimestamp}`;
    let sourceId;

    csv
    .fromString(factoryFile.toString(), {
      headers: true,
      ignoreEmpty: true
    })
    .on("data", data => {
      data['_id'] = new mongoose.Types.ObjectId();
      factories.push(data);
    })
    .on("end", () => {
      // Find if there is a source with this name and uid(firebase id), push fileName to file_name[], return source._id (mongo id)
      // If not, create a new source
      Source.findOneAndUpdate(
        { 'uid': uid, name },
        {
          $addToSet: { 'file_name': fileName },
          updated: new Date()
github open-apparel-registry / open-apparel-registry / src / restify / src / controllers / tempController.js View on Github external
const { user_name, file_description, user_type } = req.body;
    let { file_name } = req.body;

    // Remove special charactors other than a-z, 0-9, A-Z
    file_name = file_name.replace(/[^a-zA-Z0-9 ]/g, "");

    if (!uid || !file_description || !file_name || !user_name) {
      return res.send('Missing uid or user name or file name or file description');
    }

    const factoryFile = JSON.parse(req.body.file);
    const factories = [];
    const newTimestamp = new Date().getTime();
    file_name = `${file_name}_${newTimestamp}`

    csv
    .fromString(factoryFile.toString(), {
      headers: true,
      ignoreEmpty: true
    })
    .on("data", data => {
      let temp = {
        _id: new mongoose.Types.ObjectId(),
        data,
        file_name,
        uid,
        user_name,
        file_description,
        user_type
      };
      factories.push(temp);
    })
github antonycourtney / tad / src / csvimport.js View on Github external
return new Promise((resolve, reject) => {
    csv
      .fromString(headerLine, {headers: false, delimiter})
      .on('data', data => {
        resolve(data)
      })
  })
}
github bhushankumarl / amazon-mws / lib / AmazonMwsResource.js View on Github external
function parseCSVFile(res, responseString, delimiter, callback) {
            var data = [];

            var options = {
                delimiter: delimiter,
                headers: true,
                discardUnmappedColumns: true,
                quote: null,
                ignoreEmpty: true,
                trim: true
            };
            csv.fromString(responseString, options)
              .on('data', function (value) {
                  data.push(value);
              })
              .on('end', function () {
                  var items = {};
                  items.data = data;
                  return callback(null, items);
              })
              .on('error', function (error) {
                  debug('error ', error);
                  return callback(error);
              });
        }
github joshbalfour / node-cognitive-services / src / language / languageUnderstanding.js View on Github external
return new Promise((resolve, reject) => {
            let results = [];
            csv
            .fromString(csvString, {headers: true})
            .on("data", parsedObject => {
                results.push(parsedObject);
            })
            .on("end", () => {
                resolve(results);
            })
            .on("error", err => {
                reject(err);
            })
        })
    }
github fourdigit / gulpset / gulpset / tasks / generator.off / index.js View on Github external
imports: {
      nl2br: str => {
        return str.replace(/\n/gi, '<br>\n');
      },
      escapehtml: str =&gt; {
        return str
          .replace(/&amp;/g, '&amp;')
          .replace(//g, '&gt;')
          .replace(/"/g, '"')
          .replace(/'/g, ''');
      },
      escapeurl: encodeURIComponent
    }
  };
  csv
    .fromString(fileContent, { headers: true })
    .on('data', data =&gt; {
      var tmpl = data.template;
      var dest = data.destination;
      delete data.template;
      delete data.destination;
      gulp
        .src(tmpl)
        .pipe(plumber())
        .pipe(template(data, options))
        .pipe(rename(dest))
        .pipe(gulp.dest('./'));
    })
    .on('end', () =&gt; {
      cb();
    });