Socket
Socket
Sign inDemoInstall

string-length

Package Overview
Dependencies
3
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 2.0.0

9

index.js
'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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc