Last active
September 23, 2020 16:19
-
-
Save ha6000/2646ed018a80aa1a1c8553f24801c771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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