# fast-string-width

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

Latest version **3.0.2** (published 2025-09-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-string-width
pnpm add fast-string-width
yarn add fast-string-width
bun add fast-string-width
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2025-09-30 |
| First published | 2024-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Maintainers | fabiospampinato |
| Keywords | fast, string, width, cli, terminal |

## Links

- npm: https://www.npmjs.com/package/fast-string-width
- Repository: https://github.com/fabiospampinato/fast-string-width
- Homepage: https://github.com/fabiospampinato/fast-string-width#readme
- Issues: https://github.com/fabiospampinato/fast-string-width/issues
- npm.io page: https://npm.io/package/fast-string-width

## Dependencies (1)

- [fast-string-truncated-width](https://npm.io/package/fast-string-truncated-width.md) ^3.0.2

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2025-09-30
- 3.0.1 — 2025-08-22
- 3.0.0 — 2025-08-22
- 2.0.0 — 2025-08-04
- 1.1.0 — 2025-01-11
- 1.0.5 — 2024-02-27
- 1.0.4 — 2024-02-26
- 1.0.3 — 2024-02-25
- 1.0.2 — 2024-02-25
- 1.0.1 — 2024-02-25
- 1.0.0 — 2024-02-25

## README

# Fast String Width

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

See [`fast-string-truncated-width`](https://github.com/fabiospampinato/fast-string-truncated-width) for a lower-level version of this.

## Install

```sh
npm install fast-string-width
```

## Usage

```ts
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

---
_Source: https://npm.io/package/fast-string-width · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
