string-length
Advanced tools
Comparing version
'use strict'; | ||
var stripAnsi = require('strip-ansi'); | ||
var reAstral = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; | ||
module.exports = function (str) { | ||
return str.replace(reAstral, ' ').length; | ||
return stripAnsi(str).replace(reAstral, ' ').length; | ||
}; |
{ | ||
"name": "string-length", | ||
"version": "0.1.1", | ||
"description": "Get the real length of a string by correctly counting astral symbols", | ||
"version": "0.1.2", | ||
"description": "Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes", | ||
"license": "MIT", | ||
@@ -30,4 +30,10 @@ "repository": "sindresorhus/string-length", | ||
"surrogates", | ||
"codepoints" | ||
"codepoints", | ||
"ansi", | ||
"escape", | ||
"codes" | ||
], | ||
"dependencies": { | ||
"strip-ansi": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
@@ -34,0 +40,0 @@ "mocha": "*", |
# string-length [](https://travis-ci.org/sindresorhus/string-length) | ||
> Get the real length of a string by correctly counting astral symbols | ||
> Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi) | ||
@@ -31,2 +31,5 @@ `String#length` errornously counts [astral symbols](http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters. | ||
//=> 1 | ||
stringLength('\x1b[1municorn\x1b[22m'); | ||
//=> 7 | ||
``` | ||
@@ -33,0 +36,0 @@ |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
1829
19.7%6
20%40
8.11%1
Infinity%+ Added
+ Added
+ Added