We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 47a0be0 commit 32de93aCopy full SHA for 32de93a
index.js
@@ -7,7 +7,13 @@ const stringLength = string => {
7
return 0;
8
}
9
10
- return stripAnsi(string).match(charRegex()).length;
+ const strippedString = stripAnsi(string);
11
+
12
+ if (strippedString === '') {
13
+ return 0;
14
+ }
15
16
+ return strippedString.match(charRegex()).length;
17
};
18
19
module.exports = stringLength;
test.js
@@ -3,6 +3,7 @@ const stringLength = require('.');
3
4
test('get the real length of a string', t => {
5
t.is(stringLength(''), 0);
6
+ t.is(stringLength('\u001B[1m\u001B[22m'), 0);
t.is(stringLength('𠀔'), 1);
t.is(stringLength('foo𠁐bar𠀃'), 8);
t.is(stringLength('あ'), 1);
0 commit comments