string-length
Advanced tools
Comparing version 0.1.1 to 0.1.2
'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 [![Build Status](https://travis-ci.org/sindresorhus/string-length.svg?branch=master)](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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
6
40
1
+ Addedstrip-ansi@^0.2.1
+ Addedansi-regex@0.1.0(transitive)
+ Addedstrip-ansi@0.2.2(transitive)