Code Monkey home page Code Monkey logo

ts-csv's People

Contributors

dependabot[bot] avatar gregoranders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ts-csv's Issues

Fails to parse CSV header with quotes

Hi, I'm using ts-csv to process a CSV file where each entry is inside quotes, e.g:

"automatic_payout_id","automatic_payout_effective_at"....
"<id>","<date>",...

I get the error 'Invalid CSV at line 0:20' unless I unquote the first entry of the header like so:

parser.parse(fileContent.replace(/^"automatic_payout_id"/, "automatic_payout_id"));

To Reproduce
Steps to reproduce the behavior:

import Parser from '@gregoranders/csv';

// Works correctly:
//const fileContent = 'ROW1,ROW2\n"1","2"'
//const fileContent = 'ROW1,"ROW2"\n"1","2"'

// Doesn't work:
//const fileContent = '"ROW1",ROW2\n"1","2"'
const fileContent = '"ROW1","ROW2"\n"1","2"'
  
const result = parser.parse(fileContent);
// Error: Invalid CSV at 0:5
at new ParseError (/home/jq/projects/ts-csv-sample/node_modules/@gregoranders/csv/src/index.ts:101:5)
    at Parser.handleQuoteNotEscaped (/home/jq/projects/ts-csv-sample/node_modules/@gregoranders/csv/src/index.ts:253:13)
    at Parser.handleQuote (/home/jq/projects/ts-csv-sample/node_modules/@gregoranders/csv/src/index.ts:236:14)
    at Parser.handleNext (/home/jq/projects/ts-csv-sample/node_modules/@gregoranders/csv/src/index.ts:226:10)
    at Parser.parse (/home/jq/projects/ts-csv-sample/node_modules/@gregoranders/csv/src/index.ts:163:12)
    at /home/jq/projects/ts-csv-sample/index.ts:20:25
    at Object.<anonymous> (/home/jq/projects/ts-csv-sample/index.ts:23:3)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Module.m._compile (/home/jq/projects/ts-csv-sample/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)

Expected behavior
I assume that the CSV is valid since it parses correctly as long as the first entry in header remains un-quoted.

Desktop:

  • OS: Arch Linux
  • Browser: Brave 1.24, Chromium 90
  • Javascript V8 9.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.