# has-ansi

> Check if a string has ANSI escape codes

Latest version **6.0.2** (published 2025-09-08) · MIT license · 0 weekly downloads

## Install

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

## 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 | 6.0.2 |
| Published | 2025-09-08 |
| First published | 2014-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 50 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | ansi, styles, color, colour, colors, terminal, console, string, tty, escape, shell, xterm, command-line, text, regex, regexp, match, test, find, pattern, has |

## Links

- npm: https://www.npmjs.com/package/has-ansi
- Repository: https://github.com/chalk/has-ansi
- Homepage: https://github.com/chalk/has-ansi#readme
- Issues: https://github.com/chalk/has-ansi/issues
- Funding: https://github.com/chalk/has-ansi?sponsor=1
- npm.io page: https://npm.io/package/has-ansi

## Dependencies (1)

- [ansi-regex](https://npm.io/package/ansi-regex.md) ^6.0.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 6.0.2 (latest) — 2025-09-08
- 6.0.0 — 2024-07-10
- 5.0.1 — 2021-09-13
- 5.0.0 — 2021-04-16
- 4.0.1 — 2021-02-26
- 4.0.0 — 2019-09-10
- 3.0.0 — 2017-06-20
- 2.0.0 — 2015-06-30
- 1.0.3 — 2015-02-22
- 1.0.2 — 2015-02-16
- 1.0.1 — 2014-12-28
- 1.0.0 — 2014-08-13
- 0.1.0 — 2014-06-14

## README

# has-ansi

> Check if a string has [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)

## Install

```sh
npm install has-ansi
```

## Usage

```js
import hasAnsi from 'has-ansi';

hasAnsi('\u001B[4mUnicorn\u001B[0m');
//=> true

hasAnsi('cake');
//=> false
```

## Related

- [has-ansi-cli](https://github.com/chalk/has-ansi-cli) - CLI for this module
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right

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