You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

fast-string-width

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-string-width

A fast function for calculating the visual width of a string once printed to the terminal.

latest
Source
npmnpm
Version
3.0.2
Version published
Weekly downloads
959K
7.95%
Maintainers
1
Weekly downloads
 
Created
Source

Fast String Width

A fast function for calculating the visual width of a string once printed to the terminal.

See fast-string-truncated-width for a lower-level version of this.

Install

npm install fast-string-width

Usage

import fastStringWidth from 'fast-string-width';

// The width of various classes of characters is configurable

const options = {
  controlWidth: 0,
  tabWidth: 8,
  emojiWidth: 2,
  regularWidth: 1,
  wideWidth: 2
};

// Calculating the visual width of some strings

fastStringWidth ( 'hello', options ); // => 5
fastStringWidth ( '\x1b[31mhello', options ); // => 5
fastStringWidth ( '👨‍👩‍👧‍👦', options ); // => 2
fastStringWidth ( 'hello👨‍👩‍👧‍👦', options ); // => 7

// Calculating the visual width while tweaking the width of emojis

fastStringWidth ( '👶👶🏽', { ...options, emojiWidth: 1.5 } ); // => 3

License

MIT © Fabio Spampinato

Keywords

fast

FAQs

Package last updated on 30 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts