Skip to content

Commit

Permalink
fix: handling of long strings in slack
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleGreenYoda42 committed Jun 26, 2024
1 parent 335fadb commit cbd3424
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ interface Block {
const CHANGELOG_LINE = /^\s*•/;
type Messages = [Block[], ...Array<Block[] | FileUpload>];

/** Split a long spring into chunks by character limit */
/** Split a long string into chunks by character limit */
const splitCharacterLimitAtNewline = (line: string, charLimit: number) => {
const splitLines = [];
let buffer = line;

while (buffer) {
// get the \n closest to the char limit
const newlineIndex = buffer.lastIndexOf("\n", charLimit) || charLimit;
splitLines.push(buffer.slice(0, newlineIndex));
buffer = buffer.slice(newlineIndex);
const newlineIndex = buffer.indexOf("\n", charLimit);
const endOfLine = newlineIndex >= 0 ? newlineIndex : charLimit;
splitLines.push(buffer.slice(0, endOfLine));
buffer = buffer.slice(endOfLine);
}

return splitLines;
Expand Down

0 comments on commit cbd3424

Please sign in to comment.