string-width
Advanced tools
Comparing version 6.0.0 to 6.1.0
18
index.js
@@ -5,11 +5,2 @@ import stripAnsi from 'strip-ansi'; | ||
let segmenter; | ||
function * splitString(string) { | ||
segmenter ??= new Intl.Segmenter(); | ||
for (const {segment: character} of segmenter.segment(string)) { | ||
yield character; | ||
} | ||
} | ||
export default function stringWidth(string, options) { | ||
@@ -34,8 +25,6 @@ if (typeof string !== 'string' || string.length === 0) { | ||
string = string.replace(emojiRegex(), ' '); | ||
const ambiguousCharacterWidth = options.ambiguousIsNarrow ? 1 : 2; | ||
let width = 0; | ||
for (const character of splitString(string)) { | ||
for (const {segment: character} of new Intl.Segmenter().segment(string)) { | ||
const codePoint = character.codePointAt(0); | ||
@@ -53,2 +42,7 @@ | ||
if (emojiRegex().test(character)) { | ||
width += 2; | ||
continue; | ||
} | ||
const code = eastAsianWidth.eastAsianWidth(character); | ||
@@ -55,0 +49,0 @@ switch (code) { |
{ | ||
"name": "string-width", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Get the visual width of a string - the number of columns required to display it", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
5820
79