word-width is simple browserjs / nodejs library for calculate ascii length of unicode string in terminal / console.
Inspired by jquast/wcwidth which is written by Python.
npm install --save word-width
Script
tag.
<script type="text/javascript" src="dist/word-width.min.js"></script>
ES6
style.
var WordWidth = require('word-width');
//or
import WordWidth from 'word-width';
There is only one API named WordWidth(word)
.
// english
WordWidth('Hello Word Width!'); //17
// unicode
WordWidth('コンニチハ, セカイ!'); //19
WordWidth('越过长城,走向世界'); //18
npm install
npm test
MIT