break-string

1.0.0 • Public • Published

break-string

Break string into lines according to visual width.

MIT License

build:? coverage:?

Some Unicode characters are fullwidth and use double the normal width. ANSI escape codes are stripped and doesn't affect the width.

Useful to be able to break the string into lines according to visual width(the number of columns) in the terminal.

Inspired by:

Install

$ npm install --save break-string

Usage

var breakString = require('break-string');
 
 
// normal string
breakString('abcdefg', 4);
// => ['abcd', 'efg']
 
 
// with line break
breakString('abcd\nefg', 3);
// => ['abc', 'd', 'efg']
breakString('abcd\nefg', 4);
// => ['abcd', 'efg']
breakString('abcd\nefg', 5);
// => ['abcd', 'efg']
 
 
// with astral symbols
breakString('a🐴bcde', 4);
// => ['a🐴bc', 'de']
 
 
// with double with char
breakString('a古bcde', 4);
// => ['a古b', 'cde']
 
 
// with ansi code
breakString('uni\u001b[22mcorn', 4);
// => ['uni\u001b[22mc', 'orn']

Package Sidebar

Install

npm i break-string

Weekly Downloads

3

Version

1.0.0

License

MIT

Last publish

Collaborators

  • bubkoo