Skip to content

Instantly share code, notes, and snippets.

@ha6000
Last active September 23, 2020 16:19
Show Gist options
  • Save ha6000/2646ed018a80aa1a1c8553f24801c771 to your computer and use it in GitHub Desktop.
Save ha6000/2646ed018a80aa1a1c8553f24801c771 to your computer and use it in GitHub Desktop.
function wrap(msg, charLimit = 2000, wrapChar = '\n') {
const messages = [];
while (msg.length > charLimit) {
const firstPart = msg.slice(0, charLimit);
let lastNewline = firstPart.lastIndexOf('\n');
if (lastNewline < 0) lastNewline = firstPart.length;
messages.push(firstPart.slice(0, lastNewline));
msg = msg.slice(lastNewline + 1);
}
if (msg) messages.push(msg);
return messages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment