Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers form one of the output records #8

Closed
ghost opened this issue Sep 12, 2019 · 1 comment
Closed

Headers form one of the output records #8

ghost opened this issue Sep 12, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 12, 2019

The code below logs [{NAME: "NAME", ADDRESS: "ADDRESS"},{NAME: "John", ADDRESS: "Main Street"}], rather than the expected [{NAME: "John", ADDRESS: "Main Street"}].

const csv = fs.readFileSync("data.csv"); // NAME;ADDRESS\John;Main Street

neatCsv(csv, {
  headers: [
    "NAME",
    "ADDRESS"
  ],
  separator: ";"
}).then(console.log);
@kevva
Copy link
Contributor

kevva commented Sep 13, 2019

You only have to provide the headers if the first row in the CSV file doesn't.

await neatCsv('NAME;ADDRESS\nJohn;Main Street', {
    separator: ';'
});
//=> [{ NAME: 'John', ADDRESS: 'Main Street' }];

@kevva kevva closed this as completed Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant