gregoranders / ts-csv Goto Github PK
View Code? Open in Web Editor NEWSimple CSV parser in TypeScript
Home Page: https://gregoranders.github.io/ts-csv
License: MIT License
Simple CSV parser in TypeScript
Home Page: https://gregoranders.github.io/ts-csv
License: MIT License
Function parse
has 27 lines of code (exceeds 25 allowed). Consider refactoring.
https://codeclimate.com/github/gregoranders/ts-csv/src/index.ts#issue_5eedf5b0979d68000100001a
update SECURITY.md to include latest version
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:
commit initial code
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.