-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: cache regular expresions for string formatters
- Loading branch information
1 parent
ab22f53
commit 0356b9d
Showing
6 changed files
with
15 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const quote = '"'; | ||
const escapedQuote = '""""'; | ||
|
||
const quoteRegExp = new RegExp(quote, 'g'); | ||
export default function stringExcel(value: string) { | ||
return `"=""${value.replace(new RegExp(quote, 'g'), escapedQuote)}"""`; | ||
return `"=""${value.replace(quoteRegExp, escapedQuote)}"""`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
const lfRegExp = new RegExp('(?<!\r)\n', 'g'); | ||
export function forceCrlfEol(content: string): string { | ||
// eslint-disable-next-line no-control-regex | ||
return content.replace(new RegExp('(?<!\r)\n', 'g'), '\r\n'); | ||
return content.replace(lfRegExp, '\r\n'); | ||
} | ||
|
||
const crlfRegExp = new RegExp('\r\n', 'g'); | ||
export function forceLfEol(content: string): string { | ||
// eslint-disable-next-line no-control-regex | ||
return content.replace(new RegExp('\r\n', 'g'), '\n'); | ||
return content.replace(crlfRegExp, '\n'); | ||
} |