balanced-line-split

Split a string into multiple lines of similar lengths.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
balanced-line-split
2.0.03 years ago6 years agoMinified + gzip package size for balanced-line-split in KB

Readme

balanced-line-split
Split a string into multiple lines of similar lengths.

Install

$ npm install balanced-line-split

Usage

import balancedLineSplit from 'balanced-line-split';

const string = 'split me evenly';
const result = balancedLineSplit(string, 3);

// split
// me
// evenly

API

balancedLineSplit(str, lines = 1, maxLineLength = Infinity)

string

Type: string
The string to split.

lines

Type: Number
The number of lines to split the string across. Note that the resulting string will include enough line breaks to match this number of lines, even if there is no text to fill them.

maxLineLength

Type: Number
Attempt to stay within a specified maximum line length.

Related

  • Balance Text - balanced-line-split is based off the algorithm from this package

License

MIT © Brad Dougherty