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 3.1.0 to 4.0.0

37

index.d.ts

@@ -1,29 +0,22 @@

declare const stringLength: {
/**
Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi).
/**
Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi).
`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.
`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.
@example
```
import stringLength = require('string-length');
@example
```
import stringLength = require('string-length');
'🐴'.length;
//=> 2
'🐴'.length;
//=> 2
stringLength('🐴');
//=> 1
stringLength('🐴');
//=> 1
stringLength('\u001B[1municorn\u001B[22m');
//=> 7
```
*/
(string: string): number;
stringLength('\u001B[1municorn\u001B[22m');
//=> 7
```
*/
declare function stringLength(string: string): number;
// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function stringLength(string: string): number;
// export = stringLength;
default: typeof stringLength;
};
export = stringLength;
'use strict';
const stripAnsi = require('strip-ansi');
const astralRegex = require('astral-regex');
const charRegex = require('char-regex');
const stringLength = string => stripAnsi(string).replace(astralRegex(), ' ').length;
const stringLength = string => stripAnsi(string).match(charRegex()).length;
module.exports = stringLength;
// TODO: Remove this for the next major release
module.exports.default = stringLength;
{
"name": "string-length",
"version": "3.1.0",
"version": "4.0.0",
"description": "Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes",

@@ -10,6 +10,6 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -38,10 +38,10 @@ "scripts": {

"dependencies": {
"astral-regex": "^1.0.0",
"strip-ansi": "^5.2.0"
"char-regex": "^1.0.2",
"strip-ansi": "^6.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
"ava": "^3.1.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
}
}

@@ -7,3 +7,2 @@ # string-length [![Build Status](https://travis-ci.org/sindresorhus/string-length.svg?branch=master)](https://travis-ci.org/sindresorhus/string-length)

## Install

@@ -15,3 +14,2 @@

## Usage

@@ -32,10 +30,17 @@

## Related
- [string-length-cli](https://github.com/LitoMore/string-length-cli) - CLI for this module
- [string-width](https://github.com/sindresorhus/string-width) - Get visual width of a string
---
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-string-length?utm_source=npm-string-length&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

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