Skip to content

Instantly share code, notes, and snippets.

@galvez galvez/wrapAt.js

Created Nov 27, 2018
Embed
What would you like to do?
function wrapAt (str, max) {
if (str.length > max) {
const parts = str.split(' ')
let i = 0
for (let w = 0; i < parts.length; i++) {
w += parts[i].length
if (w >= max) {
parts[i] = `\n${parts[i]}`
w = 0
}
}
return parts.join(' ')
} else {
return str
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.