Split text into chunks
Prefers splitting at whitespace characters, but falls back to "hard wrapping", and obeys existing newlines.
const splitwidth = const str = 'A lazy 🐶 made a pile of 💩' // -> [ 'A lazy 🐶', 'made a ', 'pile of ', '💩' ] // -> [ 'A ', 'laz', 'y ', 'dog' ] // -> [ 'A lazy', 'dog' ] // -> 25 // -> 20 // -> 5
$ npm i -g split-text-to-chunks $ printf "A lazy 🐶 made a pile of 💩" | wordwrap --columns 8 # default: 80 A lazy 🐶made apile of💩 $ printf "A lazy 🐶\nmade a pile of 💩" | wordwrap --width16