Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

string-width

Package Overview
Dependencies
Maintainers
1
Versions
28
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
8.0.0
to
8.1.0
+2
-17
index.js

@@ -9,3 +9,3 @@ import stripAnsi from 'strip-ansi';

1. Skip non-printing clusters (Default_Ignorable, Control, pure Mark, lone Surrogates). Tabs are ignored by design.
2. Emoji clusters are double-width only when VS16 is present, the base has Emoji_Presentation (and not VS15), or the cluster has multiple scalars (flags, ZWJ, keycaps, tags, etc.).
2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
3. Otherwise use East Asian Width of the cluster’s first visible code point, and add widths for trailing Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).

@@ -24,4 +24,2 @@ */

const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
// Default emoji presentation (single-scalar emoji without VS16)
const emojiPresentationRegex = /^\p{Emoji_Presentation}$/v;

@@ -36,15 +34,2 @@ function baseVisible(segment) {

function isDoubleWidthEmojiCluster(segment) {
const visible = baseVisible(segment);
const baseScalar = visible.codePointAt(0);
const baseChar = String.fromCodePoint(baseScalar);
const baseIsEmojiPresentation = emojiPresentationRegex.test(baseChar);
const hasVs16 = segment.includes('\uFE0F');
const hasVs15 = segment.includes('\uFE0E');
const codePointCount = [...segment].length;
const multiScalarMeaningful = codePointCount > 1 && !(codePointCount === 2 && hasVs15 && !hasVs16);
return hasVs16 || (baseIsEmojiPresentation && !hasVs15) || multiScalarMeaningful;
}
function trailingHalfwidthWidth(segment, eastAsianWidthOptions) {

@@ -93,3 +78,3 @@ let extra = 0;

// Emoji width logic
if (rgiEmojiRegex.test(segment) && isDoubleWidthEmojiCluster(segment)) {
if (rgiEmojiRegex.test(segment)) {
width += 2;

@@ -96,0 +81,0 @@ continue;

+1
-1
{
"name": "string-width",
"version": "8.0.0",
"version": "8.1.0",
"description": "Get the visual width of a string - the number of columns required to display it",

@@ -5,0 +5,0 @@ "license": "MIT",