string-length
Advanced tools
Comparing version 4.0.1 to 4.0.2
/** | ||
Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi). | ||
`String#length` errornously counts [astral symbols](https://web.archive.org/web/20150721114550/http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters. | ||
`String#length` erroneously counts [astral symbols](https://web.archive.org/web/20150721114550/http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters. | ||
@@ -6,0 +6,0 @@ @example |
@@ -10,5 +10,11 @@ 'use strict'; | ||
return stripAnsi(string).match(charRegex()).length; | ||
const strippedString = stripAnsi(string); | ||
if (strippedString === '') { | ||
return 0; | ||
} | ||
return strippedString.match(charRegex()).length; | ||
}; | ||
module.exports = stringLength; |
{ | ||
"name": "string-length", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,6 +0,6 @@ | ||
# string-length [![Build Status](https://travis-ci.org/sindresorhus/string-length.svg?branch=master)](https://travis-ci.org/sindresorhus/string-length) | ||
# string-length | ||
> Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi) | ||
`String#length` errornously counts [astral symbols](https://web.archive.org/web/20150721114550/http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters. | ||
`String#length` erroneously counts [astral symbols](https://web.archive.org/web/20150721114550/http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters. | ||
@@ -7,0 +7,0 @@ ## Install |
30
4052