Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including string-break with all npm packages installed. Try it out:

var stringBreak = require("string-break")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

string-break v1.2.0

Break string into lines according to visual width.


NPM version Build Status Build status Coverage status npm download

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


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


npm install string-break --save


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

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



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free