fast-string-width
A fast function for calculating the visual width of a string once printed to the terminal.
Last updated 6 months ago by fabiospampinato .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fast-string-width 
SYNC missed versions from official npm registry.

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

Current Tags

  • 3.0.2                                ...           latest (6 months ago)

11 Versions

  • 3.0.2                                ...           6 months ago
  • 3.0.1                                ...           8 months ago
  • 3.0.0                                ...           8 months ago
  • 2.0.0                                ...           8 months ago
  • 1.1.0                                ...           a year ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |