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 4.0.2 to 5.0.0

15

index.d.ts

@@ -0,1 +1,10 @@

export interface Options {
/**
Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted. They are ignored by default.
@default false
*/
readonly countAnsiEscapeCodes?: boolean;
}
/**

@@ -8,3 +17,3 @@ Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi).

```
import stringLength = require('string-length');
import stringLength from 'string-length';

@@ -21,4 +30,2 @@ '🐴'.length;

*/
declare function stringLength(string: string): number;
export = stringLength;
export default function stringLength(string: string, options?: Options): number;

@@ -1,6 +0,5 @@

'use strict';
const stripAnsi = require('strip-ansi');
const charRegex = require('char-regex');
import stripAnsi from 'strip-ansi';
import charRegex from 'char-regex';
const stringLength = string => {
export default function stringLength(string, {countAnsiEscapeCodes = false} = {}) {
if (string === '') {

@@ -10,11 +9,11 @@ return 0;

const strippedString = stripAnsi(string);
if (!countAnsiEscapeCodes) {
string = stripAnsi(string);
}
if (strippedString === '') {
if (string === '') {
return 0;
}
return strippedString.match(charRegex()).length;
};
module.exports = stringLength;
return string.match(charRegex()).length;
}
{
"name": "string-length",
"version": "4.0.2",
"version": "5.0.0",
"description": "Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes",
"license": "MIT",
"repository": "sindresorhus/string-length",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {

@@ -13,4 +14,6 @@ "name": "Sindre Sorhus",

"engines": {
"node": ">=10"
"node": ">=12.20"
},
"type": "module",
"exports": "./index.js",
"scripts": {

@@ -38,10 +41,10 @@ "test": "xo && ava && tsd"

"dependencies": {
"char-regex": "^1.0.2",
"strip-ansi": "^6.0.0"
"char-regex": "^2.0.0",
"strip-ansi": "^7.0.0"
},
"devDependencies": {
"ava": "^3.1.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.40.2"
}
}

@@ -16,3 +16,3 @@ # string-length

```js
const stringLength = require('string-length');
import stringLength from 'string-length';

@@ -29,2 +29,17 @@ '🐴'.length;

## API
### stringLength(string, options?)
#### options
Type: `object`
##### countAnsiEscapeCodes
Type: `boolean`\
Default: `false`
Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted. They are ignored by default.
## Related

@@ -31,0 +46,0 @@

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