Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string-length

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-length - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

3

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc