word-width

Project word-width is simple browserjs / nodejs library for calculate ascii length of unicode string in terminal / console.

Install

npm install word-width 

Then import it.

// import library use script tag.
<script type="text/javascript" src="dist/word-width.min.js"></script>

// or ES6 style.
var WordWidth = require('word-width');

Usage

WordWidth('Hello Word Width!');           //17
  
// unicode
WordWidth('コンニチハ, セカイ!');         //19
WordWidth('越过长城,走向世界');          //18
  

The code of word-width hosted on Github, click here. Welcome to issue or pull request.