jedluk / use-exportable-csv Goto Github PK
View Code? Open in Web Editor NEWReact hook for convenient way of downloading csv data
License: MIT License
React hook for convenient way of downloading csv data
License: MIT License
`const data = {
field: 'some text\nmore text',
};
const csvLink = useExportableCSV(data);
`
This example does not encapsulate the field in quotes, which it should if there is a delimiter (,) or a newline (\n or \r or \r\n). This causes the resulting CSV to incorrectly setup a new record at the newline versus storing the data in a single text field with an inline newline character.
`const data = {
field: '"some text\nmore text"',
};
const csvLink = useExportableCSV(data);
`
This works, because it forces quote delimiters on a text field that contains a newline. The record stays intact and renders in most spreadsheet apps with a single column with newline characters.
`const data = {
field: 'some, text\nmore text',
};
const csvLink = useExportableCSV(data);
`
This example DOES encapsulate in quotes because the data has a comma. This is correct.
`const data = {
field: '"some,text\nmore text"',
};
const csvLink = useExportableCSV(data);
`
This breaks the standard CSV output. The comma inside the forced quotes put in place to retain the newlines causes sanitize() to quote the already-quoted data. This results in an errant newline being rendered and breaking the record to a new entry.
Possible fixes --
Update sanitize() to not only quote on delim (,) but quote if string includes delim(,) or newline characters.
Update sanitize to NOT quote if the data is wrapped in quotes already , regex match ^".*?"$ then do NOT quote.
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.