Skip to content

Commit

Permalink
Fix newline regex (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarl authored Jan 29, 2025
1 parent 030af9e commit 2569d6c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/helpers/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export const extractEmoji = (s: string) => s.match(EMOJI_RANGE) || [];
const NEWLINE = /\n/g;
export const countLines = (s: string) => s.match(NEWLINE)?.length || 0;

const DOUBLE_NEWLINE = /\n\n/g;
const TOO_MANY_NEWLINES = /\n\n\n/g;
const APPROPRIATE_NEWLINES = "\n\n";
export const compressLineBreaks = (s: string) => {
while (DOUBLE_NEWLINE.test(s)) {
s = s.replaceAll(DOUBLE_NEWLINE, "\n");
while (TOO_MANY_NEWLINES.test(s)) {
s = s.replaceAll(TOO_MANY_NEWLINES, APPROPRIATE_NEWLINES);
}
return s;
};

0 comments on commit 2569d6c

Please sign in to comment.