Git Product home page Git Product logo

use-exportable-csv's People

Contributors

jedluk avatar

Stargazers

 avatar

Watchers

 avatar  avatar

use-exportable-csv's Issues

Sanitize is not working properly in newlines are present.

`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 --

  1. Update sanitize() to not only quote on delim (,) but quote if string includes delim(,) or newline characters.

  2. Update sanitize to NOT quote if the data is wrapped in quotes already , regex match ^".*?"$ then do NOT quote.

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.