File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -91,16 +91,17 @@ interface Block {
9191const CHANGELOG_LINE = / ^ \s * • / ;
9292type Messages = [ Block [ ] , ...Array < Block [ ] | FileUpload > ] ;
9393
94- /** Split a long spring into chunks by character limit */
94+ /** Split a long string into chunks by character limit */
9595const splitCharacterLimitAtNewline = ( line : string , charLimit : number ) => {
9696 const splitLines = [ ] ;
9797 let buffer = line ;
9898
9999 while ( buffer ) {
100100 // get the \n closest to the char limit
101- const newlineIndex = buffer . lastIndexOf ( "\n" , charLimit ) || charLimit ;
102- splitLines . push ( buffer . slice ( 0 , newlineIndex ) ) ;
103- buffer = buffer . slice ( newlineIndex ) ;
101+ const newlineIndex = buffer . indexOf ( "\n" , charLimit ) ;
102+ const endOfLine = newlineIndex >= 0 ? newlineIndex : charLimit ;
103+ splitLines . push ( buffer . slice ( 0 , endOfLine ) ) ;
104+ buffer = buffer . slice ( endOfLine ) ;
104105 }
105106
106107 return splitLines ;
You can’t perform that action at this time.
0 commit comments