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 ad032d3 commit cb19fd4Copy full SHA for cb19fd4
index.js
@@ -2,6 +2,12 @@
2
const stripAnsi = require('strip-ansi');
3
const charRegex = require('char-regex');
4
5
-const stringLength = string => stripAnsi(string).match(charRegex()).length;
+const stringLength = string => {
6
+ if (string === '') {
7
+ return 0;
8
+ }
9
+
10
+ return stripAnsi(string).match(charRegex()).length;
11
+};
12
13
module.exports = stringLength;
test.js
@@ -2,6 +2,7 @@ const test = require('ava');
const stringLength = require('.');
test('get the real length of a string', t => {
+ t.is(stringLength(''), 0);
t.is(stringLength('𠀔'), 1);
t.is(stringLength('foo𠁐bar𠀃'), 8);
t.is(stringLength('あ'), 1);
0 commit comments