string-length
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -1,2 +0,2 @@ | ||
export interface Options { | ||
export type Options = { | ||
/** | ||
@@ -8,3 +8,3 @@ Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted. They are ignored by default. | ||
readonly countAnsiEscapeCodes?: boolean; | ||
} | ||
}; | ||
@@ -11,0 +11,0 @@ /** |
11
index.js
import stripAnsi from 'strip-ansi'; | ||
import charRegex from 'char-regex'; | ||
const segmenter = new Intl.Segmenter(); | ||
export default function stringLength(string, {countAnsiEscapeCodes = false} = {}) { | ||
@@ -17,3 +18,9 @@ if (string === '') { | ||
return string.match(charRegex()).length; | ||
let length = 0; | ||
for (const _ of segmenter.segment(string)) { // eslint-disable-line no-unused-vars | ||
length++; | ||
} | ||
return length; | ||
} |
{ | ||
"name": "string-length", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes", | ||
@@ -14,3 +14,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=12.20" | ||
"node": ">=16" | ||
}, | ||
@@ -41,10 +41,9 @@ "type": "module", | ||
"dependencies": { | ||
"char-regex": "^2.0.0", | ||
"strip-ansi": "^7.0.1" | ||
"strip-ansi": "^7.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.44.0" | ||
"ava": "^5.3.0", | ||
"tsd": "^0.28.1", | ||
"xo": "^0.54.2" | ||
} | ||
} |
@@ -9,5 +9,5 @@ # string-length | ||
```sh | ||
npm install string-length | ||
``` | ||
$ npm install string-length | ||
``` | ||
@@ -48,13 +48,1 @@ ## Usage | ||
- [string-width](https://github.com/sindresorhus/string-width) - Get visual width of a string | ||
--- | ||
<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> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
40
4252
47
- Removedchar-regex@^2.0.0
- Removedchar-regex@2.0.1(transitive)
Updatedstrip-ansi@^7.1.0