# chalk/ansi-regex architecture

> Architecture diagram of the GitHub repository chalk/ansi-regex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chalk/ansi-regex
- Repository: https://github.com/chalk/ansi-regex

## Overview

ansi-regex is a small JavaScript utility that returns a regular expression for finding ANSI escape sequences in text. The user calls the exported function with an optional `onlyFirst` setting; the function builds a regex from the supported-sequence pattern, which the caller can then apply to text. The README describes the matcher’s supported sequence families and limits. The runtime implementation is shown; no separate parsing, storage, or terminal-emulation subsystem is present.

Main entry points: [`index.js`](https://github.com/chalk/ansi-regex/blob/main/index.js) (ansiRegex API)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_user(("Library caller"))
node_api["ansiRegex API<br/>[index.js]"]
node_pattern["ANSI pattern<br/>[index.js]"]
node_regex["Matcher regex"]

node_user -->|"calls"| node_api
node_api -->|"uses pattern"| node_pattern
node_api -->|"returns regex"| node_regex
node_user -->|"matches text"| node_regex

click node_api "https://github.com/chalk/ansi-regex/blob/main/index.js"
click node_pattern "https://github.com/chalk/ansi-regex/blob/main/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_user,node_regex toneIndigo
class node_api toneMint
class node_pattern toneTeal
```

## Components

### Other components

- **Library caller**
- [ansiRegex API](https://github.com/chalk/ansi-regex/blob/main/index.js): `index.js`
- [ANSI pattern](https://github.com/chalk/ansi-regex/blob/main/index.js): `index.js`
- **Matcher regex**

## Connections

- Library caller → ansiRegex API: calls (evidence: `readme.md`)
- ansiRegex API → ANSI pattern: uses pattern (evidence: `index.js`)
- ansiRegex API → Matcher regex: returns regex (evidence: `index.js`)
- Library caller → Matcher regex: matches text (evidence: `readme.md`)
