Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-string-width

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-string-width - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

38

dist/index.js

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

let length = input.length;
let match = null;
let unmatched = '';
let unmatchedStart = 0;
let unmatchedEnd = 0;
let width = 0;

@@ -31,4 +31,4 @@ /* PARSE LOOP */

/* UNMATCHED */
if (unmatched || index >= length) {
unmatched || (unmatched = input.slice(indexPrev, index));
if ((unmatchedEnd > (unmatchedStart + 1)) || (index >= length && index > (indexPrev + 1))) {
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
for (const char of unmatched.replaceAll(MODIFIER_RE, '')) {

@@ -49,3 +49,3 @@ const codePoint = char.codePointAt(0) || 0;

}
unmatched = '';
unmatchedStart = unmatchedEnd = 0;
}

@@ -57,6 +57,6 @@ /* EXITING */

LATIN_RE.lastIndex = index;
match = LATIN_RE.exec(input);
if (match) {
width += match[0].length * REGULAR_WIDTH;
unmatched = input.slice(indexPrev, index);
if (LATIN_RE.test(input)) {
width += (LATIN_RE.lastIndex - index) * REGULAR_WIDTH;
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = LATIN_RE.lastIndex;

@@ -67,6 +67,6 @@ continue;

ANSI_RE.lastIndex = index;
match = ANSI_RE.exec(input);
if (match) {
if (ANSI_RE.test(input)) {
width += ANSI_WIDTH;
unmatched = input.slice(indexPrev, index);
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = ANSI_RE.lastIndex;

@@ -77,6 +77,6 @@ continue;

CONTROL_RE.lastIndex = index;
match = CONTROL_RE.exec(input);
if (match) {
width += match[0].length * CONTROL_WIDTH;
unmatched = input.slice(indexPrev, index);
if (CONTROL_RE.test(input)) {
width += (CONTROL_RE.lastIndex - index) * CONTROL_WIDTH;
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = CONTROL_RE.lastIndex;

@@ -87,6 +87,6 @@ continue;

EMOJI_RE.lastIndex = index;
match = EMOJI_RE.exec(input);
if (match) {
if (EMOJI_RE.test(input)) {
width += EMOJI_WIDTH;
unmatched = input.slice(indexPrev, index);
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = EMOJI_RE.lastIndex;

@@ -93,0 +93,0 @@ continue;

@@ -5,3 +5,3 @@ {

"description": "A fast function for calculating the visual width of a string once printed to the terminal.",
"version": "1.0.2",
"version": "1.0.3",
"type": "module",

@@ -8,0 +8,0 @@ "main": "dist/index.js",

@@ -36,4 +36,4 @@

let length = input.length;
let match: RegExpMatchArray | null = null;
let unmatched = '';
let unmatchedStart = 0;
let unmatchedEnd = 0;
let width = 0;

@@ -47,5 +47,5 @@

if ( unmatched || index >= length ) {
if ( ( unmatchedEnd > ( unmatchedStart + 1 ) ) || ( index >= length && index > ( indexPrev + 1 ) ) ) {
unmatched ||= input.slice ( indexPrev, index );
const unmatched = input.slice ( unmatchedStart, unmatchedEnd ) || input.slice ( indexPrev, index );

@@ -76,3 +76,3 @@ for ( const char of unmatched.replaceAll ( MODIFIER_RE, '' ) ) {

unmatched = '';
unmatchedStart = unmatchedEnd = 0;

@@ -88,8 +88,8 @@ }

LATIN_RE.lastIndex = index;
match = LATIN_RE.exec ( input );
if ( match ) {
if ( LATIN_RE.test ( input ) ) {
width += match[0].length * REGULAR_WIDTH;
unmatched = input.slice ( indexPrev, index );
width += ( LATIN_RE.lastIndex - index ) * REGULAR_WIDTH;
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = LATIN_RE.lastIndex;

@@ -104,8 +104,8 @@

ANSI_RE.lastIndex = index;
match = ANSI_RE.exec ( input );
if ( match ) {
if ( ANSI_RE.test ( input ) ) {
width += ANSI_WIDTH;
unmatched = input.slice ( indexPrev, index );
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = ANSI_RE.lastIndex;

@@ -120,8 +120,8 @@

CONTROL_RE.lastIndex = index;
match = CONTROL_RE.exec ( input );
if ( match ) {
if ( CONTROL_RE.test ( input ) ) {
width += match[0].length * CONTROL_WIDTH;
unmatched = input.slice ( indexPrev, index );
width += ( CONTROL_RE.lastIndex - index ) * CONTROL_WIDTH;
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = CONTROL_RE.lastIndex;

@@ -136,8 +136,8 @@

EMOJI_RE.lastIndex = index;
match = EMOJI_RE.exec ( input );
if ( match ) {
if ( EMOJI_RE.test ( input ) ) {
width += EMOJI_WIDTH;
unmatched = input.slice ( indexPrev, index );
unmatchedStart = indexPrev;
unmatchedEnd = index;
index = indexPrev = EMOJI_RE.lastIndex;

@@ -144,0 +144,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc