2 const stripAnsi = require('strip-ansi');
3 const isFullwidthCodePoint = require('is-fullwidth-code-point');
4 const emojiRegex = require('emoji-regex')();
6 module.exports = input => {
7 input = input.replace(emojiRegex, ' ');
9 if (typeof input !== 'string' || input.length === 0) {
13 input = stripAnsi(input);
17 for (let i = 0; i < input.length; i++) {
18 const code = input.codePointAt(i);
20 // Ignore control characters
21 if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
25 // Ignore combining characters
26 if (code >= 0x300 && code <= 0x36F) {
35 width += isFullwidthCodePoint(code) ? 2 : 1;