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 breakword with all npm packages installed. Try it out:

var breakword = require("breakword")

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

breakword v1.0.5

Get index of character after which variable 'word' must be broken given variable 'length' (accounts for wide characters).


Get index i.e. 0,1,2,... of the character where a word must be broken given it must be wrapped within a certain length of spaces.

Useful because javascript's String.length does not reflect the true width of emojis and wide characters.


npm install breakword 


  1. To find the index of the character to break after if we want to limit our characters fit on a line 3 spaces wide.
var Breakword = require ("breakword");
var word = "打破我的角色三";
var breakIndex = Breakword(word,3); 
console.log(breakIndex) //0

The result here - 0 - means all the characters before index 0 (in this case only the character 打) can fit in a line 3 spaces long.


npm test
  • Save new test results to test/test.json
npm --save run test
  • Display test outputs only
npm --display run test


npm run-script build
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