evanplaice / jquery-csv

A jQuery CSV parser plugin. Battle Tested | Optimized | 100% IETF RFC 4180 Complete
MIT License
764 stars 439 forks source link

TypeError: csv.replace is not a function #115

Closed NicholasZonenberg closed 5 years ago

NicholasZonenberg commented 6 years ago

Subject of the issue

TypeError: csv.replace is not a function

Environment

Steps to reproduce

install via NPM and use via: var jqueryCsv = require("jquery-csv")

Expected behaviour

Should work without error

Actual behaviour

The program does not compile as there is a non function function

evanplaice commented 5 years ago

I uploaded a better Example to the repo.

Assuming you have jquery-csv installed via npm (ie npm i jquery-csv) the following will work.

var fs = require('fs');
var csv = require('jquery-csv');

var sample = './data/sample.csv';
fs.readFile(sample, 'UTF-8', function (err, csv) {
  if (err) { console.log(err); }
  csv.toArrays(csv, {}, function (err, data) {
    if (err) { console.log(err); }
    for (var i = 0, len = data.length; i < len; i++) {
      console.log(data[i]);
    }
  });
});