1.0.0 ā€¢ Published 7 years ago

split-text-to-chunks v1.0.0

Weekly downloads
1,114
License
MIT
Repository
github
Last release
7 years ago

Split text into chunks

Prefers splitting at whitespace characters, but falls back to "hard wrapping", and obeys existing newlines.

const {split,width} = require('split-text-to-chunks')

const str = 'A lazy šŸ¶ made a pile of šŸ’©'

split(str, 8/*columns*/)
// -> [ 'A lazy šŸ¶', 'made a ', 'pile of ', 'šŸ’©' ]

split('A lazy dog', 3)
// -> [ 'A ', 'laz', 'y ', 'dog' ]

split('A lazy\ndog', 10)
// -> [ 'A lazy', 'dog' ]

width(str)
// -> 25

width(str, 20/* max, stop counting */)
// -> 20

width('one\ntwo\nthree')
// -> 5
$ npm i -g split-text-to-chunks

$ printf "A lazy šŸ¶ made a pile of šŸ’©" | wordwrap --columns 8 # default: 80
A lazy šŸ¶
made a
pile of
šŸ’©

$ printf "A lazy šŸ¶\nmade a pile of šŸ’©" | wordwrap --width
16