2 ms·
Wow, I never knew so much thought had been put into line breaking algorithms before! I wanted to get a simple and fast solution into a one line regex a while b
by tomxor 8y ago
Wow, I never knew so much thought had been put into line breaking algorithms before!
I wanted to get a simple and fast solution into a one line regex a while back with the simple premise of: breaking on spaces before n chars, i was quite happy with it [1]:
const wrap = (s) => s.replace(
/(?![^\n]{1,32}$)([^\n]{1,32})\s/g, '$1\n'
);
...this looks like a child drawing compared to the article, but then i'm heavily biased towards simplicity over sophistication.
[1] https://stackoverflow.com/questions/14484787/wrap-text-in-javascript/51506718#51506718 https://stackoverflow.com/questions/14484787/wrap-text-in-ja...