File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
packages/utils/src/lib/text-formats/ascii Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ const BORDERS = {
5353 } ,
5454} ;
5555
56+ const WORD_REGEX = / ^ [ a - z A - Z ] + ( - [ a - z A - Z ] ) ? $ / ;
57+
5658export 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 (
You can’t perform that action at this time.
0 commit comments