string-length
Advanced tools
Comparing version 1.0.1 to 2.0.0
'use strict'; | ||
var stripAnsi = require('strip-ansi'); | ||
const stripAnsi = require('strip-ansi'); | ||
const astralRegex = require('astral-regex'); | ||
module.exports = function (str) { | ||
var reAstral = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; | ||
return stripAnsi(str).replace(reAstral, ' ').length; | ||
}; | ||
module.exports = input => stripAnsi(input).replace(astralRegex(), ' ').length; |
{ | ||
"name": "string-length", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes", | ||
@@ -13,6 +13,6 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
@@ -25,4 +25,5 @@ "files": [ | ||
"string", | ||
"str", | ||
"length", | ||
"size", | ||
"count", | ||
"astral", | ||
@@ -37,7 +38,9 @@ "symbol", | ||
"dependencies": { | ||
"strip-ansi": "^3.0.0" | ||
"astral-regex": "^1.0.0", | ||
"strip-ansi": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # string-length [![Build Status](https://travis-ci.org/sindresorhus/string-length.svg?branch=master)](https://travis-ci.org/sindresorhus/string-length) | ||
`String#length` errornously counts [astral symbols](http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters. | ||
`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. | ||
@@ -12,3 +12,3 @@ | ||
``` | ||
$ npm install --save string-length | ||
$ npm install string-length | ||
``` | ||
@@ -20,2 +20,4 @@ | ||
```js | ||
const stringLength = require('string-length'); | ||
'🐴'.length; | ||
@@ -27,3 +29,3 @@ //=> 2 | ||
stringLength('\u001b[1municorn\u001b[22m'); | ||
stringLength('\u001B[1municorn\u001B[22m'); | ||
//=> 7 | ||
@@ -33,4 +35,9 @@ ``` | ||
## Related | ||
- [string-width](https://github.com/sindresorhus/string-width) - Get visual width of a string | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
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
2967
39
2
2
4
+ Addedastral-regex@^1.0.0
+ Addedansi-regex@3.0.1(transitive)
+ Addedastral-regex@1.0.0(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
Updatedstrip-ansi@^4.0.0