adaltas / node-csv

Full featured CSV parser with simple api and tested against large datasets.
https://csv.js.org
MIT License
4.05k stars 267 forks source link

First value of the first row has a leading space. #432

Open tengotengo opened 5 months ago

tengotengo commented 5 months ago

const { parse } = require('csv-parse'); const fs = require('fs');

const parser = parse(fs.readFileSync('./data2.csv').toString(), { }, function (err, records) { console.log(111, 're111cords', records); });

data2.csv:

102,10790 WILSHIRE BLVD,Los Angelse,CA,90024 104,1005 N 4TH STREET,Montebello,CA,90640

output:

111 re111cords [ [ ' 102', '10790 WILSHIRE BLVD', 'Los Angelse', 'CA', '90024' ], [ '104', '1005 N 4TH STREET', 'Montebello', 'CA', '90640' ] ]

wdavidw commented 5 months ago

When copy/pasting your code above into vscode, I can see an invisible character in your sample:

image

It might be becase you are sourcing an utf-8 file with a leading BOM inside. Try adding the {bom: true} option.