Skip to content

Commit

Permalink
More efficiently handle regex construction
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Jul 7, 2024
1 parent 3271f00 commit 9250cde
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/CsvToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function csvToMarkdown(csvContent, delimiter, hasHeader) {
var tabularData = [];
var maxRowLen = [];
var regsafeDelimiter = delimiter.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
var regex = new RegExp("".concat(regsafeDelimiter, "(?![^\"]*\"(?:$|").concat(regsafeDelimiter, "))"));
columns.forEach(function (e, i) {
if (typeof tabularData[i] == "undefined") {
tabularData[i] = [];
}
var regex = new RegExp("".concat(regsafeDelimiter, "(?![^\"]*\"(?:$|").concat(regsafeDelimiter, "))"));
var row = e.split(regex);
row.forEach(function (ee, ii) {
if (typeof maxRowLen[ii] == "undefined") {
Expand Down
3 changes: 1 addition & 2 deletions src/CsvToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ export default function csvToMarkdown(csvContent: string, delimiter: string = "\
const maxRowLen: number[] = [];

const regsafeDelimiter = delimiter.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(`${regsafeDelimiter}(?![^"]*"(?:$|${regsafeDelimiter}))`);

columns.forEach((e, i) => {
if (typeof tabularData[i] == "undefined") {
tabularData[i] = [];
}

const regex = new RegExp(`${regsafeDelimiter}(?![^"]*"(?:$|${regsafeDelimiter}))`);
const row = e.split(regex);
row.forEach((ee, ii) => {
if (typeof maxRowLen[ii] == "undefined") {
Expand Down

0 comments on commit 9250cde

Please sign in to comment.