-
Notifications
You must be signed in to change notification settings - Fork 32
Feature/tsv support #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/tsv support #394
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,8 +110,8 @@ export function _createTableEntries ( | |
// (not all programs support values with line breaks). | ||
// Rule: All other fields do not require double quotes. | ||
// Rule: Double quotes within values are represented by two contiguous double quotes. | ||
function encloser (value: string, delimiter: ',' | ';') { | ||
const enclosingTester = new RegExp(`${delimiter}|"|\n`) | ||
function encloser (value: string, delimiter: ',' | ';' | '\t') { | ||
const enclosingTester = new RegExp(`${delimiter === "\t" ? "\\t" : delimiter}|"|\n`) | ||
Comment on lines
+113
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review the updated The function now correctly handles the tab delimiter ( However, the implementation could be further optimized by pre-compiling the regular expression outside of the function to avoid re-compilation on every function call, which can improve performance especially when processing large datasets. Consider pre-compiling the regular expression to improve performance: + const enclosingTesterMap = {
+ ',': new RegExp(",|\"|\n"),
+ ';': new RegExp(";|\"|\n"),
+ '\t': new RegExp("\\t|\"|\n")
+ }
function encloser(value: string, delimiter: ',' | ';' | '\t') {
- const enclosingTester = new RegExp(`${delimiter === "\t" ? "\\t" : delimiter}|"|\n`)
+ const enclosingTester = enclosingTesterMap[delimiter]
const enclosingCharacter = enclosingTester.test(value) ? '"' : ''
const escaped = value.replace(/"/g, '""')
return `${enclosingCharacter}${escaped}${enclosingCharacter}`
}
|
||
const enclosingCharacter = enclosingTester.test(value) ? '"' : '' | ||
const escaped = value.replace(/"/g, '""') | ||
|
||
|
@@ -120,7 +120,7 @@ function encloser (value: string, delimiter: ',' | ';') { | |
|
||
interface CreateCSVDataOptions { | ||
beforeTableEncode?: (entries: ITableEntries) => ITableEntries, | ||
delimiter?: ',' | ';', | ||
delimiter?: ',' | ';' | "\t", | ||
} | ||
|
||
const defaultCreateCSVDataOption: Required<CreateCSVDataOptions> = { beforeTableEncode: i => i, delimiter: ',' } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation updates for TSV support are accurate.
The updates to the
exportType
anddelimiter
options in the documentation correctly reflect the new support for TSV files. This enhances user understanding and usability of the library.Static Analysis Fixes:
Apply these corrections:
Also applies to: 136-136