Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fabiospampinato/fast-string-width

Repository files navigation

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

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">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 (c) Fabio Spampinato

About

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

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Sponsor this project

Packages

Contributors

Languages

  • TypeScript 52.1%
  • JavaScript 47.9%