Improve arrayToCSV to escape quotes in strings and un-quote numeric values.

This commit is contained in:
Dan Howe
2019-03-18 23:16:19 +10:00
parent 9fbb61c79c
commit 74e212fb9a
2 changed files with 5 additions and 1 deletions

View File

@ -10,3 +10,6 @@ test('arrayToCSV works with default delimiter', () => {
test('arrayToCSV works with custom delimiter', () => {
expect(arrayToCSV([['a', 'b'], ['c', 'd']], ';')).toBe('"a";"b"\n"c";"d"');
});
test('arrayToCSV escapes quotes and doesn\'t quote numbers', () => {
expect(arrayToCSV([['a', '"b" great'], ['c', 3.1415]])).toBe('"a","""b"" great"\n"c",3.1415');
});