Closed MichaelVyverman closed 2 years ago
I tried d3-dsv, but it did not escape newlines. The package wraps cells containing delimiters in quotes, but this is not sufficient when viewing files in text editors or importing in tools like excel.
Some packages are only available for Node.js. Other recommendations on Yarn are either deprecated, unstable, less than 1k downloads or removed from GitHub.
Keeping with this solution
replace TSV-specific characters in the content with escaped versions using JSON stringify and remove the begin and end quotes from this:
Tested manually with content containing newlines. Before the change, any text editor used the newlines, but using the escape the characters where visible but not used. Alternatively I could just remove them if that is more appropriate.
Advantage of escaping is that it still shows the original content, but it might still confuse naive parsers...
Note: according to the standard, https://tc39.es/ecma262/multipage/structured-data.html#sec-json.stringify in addition to newlines and tabs,
JSON.stringify
also escapes quotes. These don't show up in text editors. Effect on TSV parsers unknown.This is a change from #127 using JSON stringify