split-text-to-chunks
Split a text string to chunks for e.g. word wrapping
Last updated 7 years ago by thomas-jensen .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install split-text-to-chunks 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.0                                ...           latest (7 years ago)

1 Versions

  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE