🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

string-width

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-width - npm Package Compare versions

Comparing version

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",