2 const stripAnsi = require('strip-ansi');
3 const isFullwidthCodePoint = require('is-fullwidth-code-point');
5 module.exports = str => {
6 if (typeof str !== 'string' || str.length === 0) {
14 for (let i = 0; i < str.length; i++) {
15 const code = str.codePointAt(i);
17 // Ignore control characters
18 if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
22 // Ignore combining characters
23 if (code >= 0x300 && code <= 0x36F) {
32 width += isFullwidthCodePoint(code) ? 2 : 1;