# ansi-truncate

> A tiny function for truncating a string that may contain ANSI escape sequences.

Latest version **1.4.0** (published 2025-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install ansi-truncate
pnpm add ansi-truncate
yarn add ansi-truncate
bun add ansi-truncate
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2025-08-22 |
| First published | 2022-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | fabiospampinato |
| Keywords | ansi, truncate |

## Links

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

## Dependencies (1)

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

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.4.0 (latest) — 2025-08-22
- 1.3.0 — 2025-08-04
- 1.2.0 — 2025-01-11
- 1.1.2 — 2024-02-27
- 1.1.1 — 2024-02-27
- 1.1.0 — 2024-02-25
- 1.0.1 — 2022-05-06
- 1.0.0 — 2022-05-06

## README

# ANSI Truncate

A tiny function for truncating a string that may contain ANSI escape sequences.

## Install

```sh
npm install ansi-truncate
```

## Usage

```ts
import colors from 'tiny-colors';
import truncate from 'ansi-truncate';

// Let's truncate a string to a visual width of 2

truncate ( colors.red ( 'foo' ), 2 ); // => Same as: colors.red ( 'f…' );
```

## License

MIT © Fabio Spampinato

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