-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
16 changes: 16 additions & 0 deletions
16
Radio3.0@claudiux/files/Radio3.0@claudiux/lib/text-wrap.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Text wrapper | ||
const formatTextWrap = (text, maxLineLength) => { | ||
const words = text.replace(/[\r\n]+/g, " ").split(" "); | ||
let lineLength = 0; | ||
|
||
// use functional reduce, instead of for loop | ||
return words.reduce((result, word) => { | ||
if (lineLength + word.length >= maxLineLength) { | ||
lineLength = word.length; | ||
return result + `\n${word}`; // don't add spaces upfront | ||
} else { | ||
lineLength += word.length + (result ? 1 : 0); | ||
return result ? result + ` ${word}` : `${word}`; // add space only when needed | ||
} | ||
}, ""); | ||
} |
This file contains 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
This file contains 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