Skip to content

Commit f802a2d

Browse files
committed
fix(utils): break urls in ascii table differently to regular words
1 parent 1efe5b0 commit f802a2d

File tree

1 file changed

+9
-4
lines changed
  • packages/utils/src/lib/text-formats/ascii

1 file changed

+9
-4
lines changed

packages/utils/src/lib/text-formats/ascii/table.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const BORDERS = {
5353
},
5454
};
5555

56+
const WORD_REGEX = /^[a-zA-Z]+(-[a-zA-Z])?$/;
57+
5658
export function formatAsciiTable(
5759
table: Table,
5860
options?: AsciiTableOptions,
@@ -164,10 +166,13 @@ function wrapText(text: string, width: number | undefined): string {
164166
const words = extractWords(text);
165167
const longWords = words.filter(word => word.length > width);
166168
const replacements = longWords.map(original => {
167-
const parts = original.includes('-')
168-
? original.split('-')
169-
: partitionString(original, width - 1);
170-
const replacement = parts.join('-\n');
169+
const isWord = WORD_REGEX.test(original);
170+
const parts = isWord
171+
? original.includes('-')
172+
? original.split('-')
173+
: partitionString(original, width - 1)
174+
: partitionString(original, width);
175+
const replacement = parts.join(isWord ? '-\n' : '\n');
171176
return { original, replacement };
172177
});
173178
const textWithSplitLongWords = replacements.reduce(

0 commit comments

Comments
 (0)