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';
const options = {
controlWidth: 0,
tabWidth: 8,
emojiWidth: 2,
regularWidth: 1,
wideWidth: 2
};
fastStringWidth ( 'hello', options );
fastStringWidth ( '\x1b[31mhello', options );
fastStringWidth ( '👨👩👧👦', options );
fastStringWidth ( 'hello👨👩👧👦', options );
fastStringWidth ( '👶👶🏽', { ...options, emojiWidth: 1.5 } );
License
MIT © Fabio Spampinato