string-break

Break string into lines according to visual width.


Keywords
break, string, fixed-width, chinese, console, terminal, command-line, cli, escape, ansi, full-width, fullwidth, columns, column, visual, width, unicode, char, character
License
MIT
Install
npm install string-break@1.2.0

Documentation

String-Break

NPM version Build status npm download Coverage status

String-Break 是命令行字符串格式化工具,可以方便的将长字符串按照宽度分段。

特点:

  • 支持中文,英文,中英文混排
  • 英文不会被截断
  • 标点不会出现在行首

Install

npm install string-break --save

Usage

const stringBreak = require('string-break');
const str = '远处海港传来阵阵船笛 我一直飘零到被你拣起 如今望著反映窗户玻璃 有个我陌生又熟悉';

let lines = stringBreak(str, 30);
/**
 * lines: [ 
 *   '远处海港传来阵阵船笛 我一直飘',
 *   '零到被你拣起 如今望著反映窗户',
 *   '玻璃 有个我陌生又熟悉'
 * ]
 */

License

MIT.