# @mermaid-js/parser

> MermaidJS parser

Latest version **1.2.1** (published 2026-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mermaid-js/parser
pnpm add @mermaid-js/parser
yarn add @mermaid-js/parser
bun add @mermaid-js/parser
```

## Health

**Score 80/100 (A)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; large bundle.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2026-08-19 |
| First published | 2023-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 11.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 90018 |
| Author | Yokozuna59 |
| Maintainers | knsv, ugnikalnis, ashishjain0512, sidv, aloisklink, p_brolin47 |
| Keywords | mermaid, parser, ast |

## Links

- npm: https://www.npmjs.com/package/@mermaid-js/parser
- Repository: https://github.com/mermaid-js/mermaid
- Homepage: https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/parser/#readme
- Issues: https://github.com/mermaid-js/mermaid/issues
- npm.io page: https://npm.io/package/@mermaid-js/parser

## Dependencies (1)

- [@chevrotain/types](https://npm.io/package/@chevrotain/types.md) ~11.1.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2026-08-19
- 0.3.1-rc.1 (next) — 2024-09-17
- 1.2.0 — 2026-06-25
- 1.1.1 — 2026-05-11
- 1.1.0 — 2026-04-01
- 1.0.1 — 2026-03-09
- 1.0.0 — 2026-02-17
- 0.6.3 — 2025-10-07
- 0.6.2 — 2025-07-16
- 0.6.1 — 2025-07-07
- 0.6.0 — 2025-07-03
- 0.5.0 — 2025-06-20
- 0.4.0 — 2025-03-25
- 0.3.0 — 2024-09-02
- 0.2.0 — 2024-08-24
- … 4 more at https://npm.io/package/@mermaid-js/parser/versions

## README

<p align="center">
<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/develop/docs/public/favicon.svg" height="150">

</p>
<h1 align="center">
Mermaid Parser
</h1>

<p align="center">
Mermaid parser package
<p>

[![NPM](https://img.shields.io/npm/v/@mermaid-js/parser)](https://www.npmjs.com/package/@mermaid-js/parser)

## How the package works

The package exports a `parse` function that has two parameters:

```ts
declare function parse<T extends DiagramAST>(
  diagramType: keyof typeof initializers,
  text: string
): T;
```

## How does a Langium-based parser work?

```mermaid
sequenceDiagram
actor Package
participant Module
participant TokenBuilder
participant Lexer
participant Parser
participant ValueConverter


Package ->> Module: Create services
Module ->> TokenBuilder: Override or/and<br>reorder rules
TokenBuilder ->> Lexer: Read the string and transform<br>it into a token stream
Lexer ->> Parser: Parse token<br>stream into AST
Parser ->> ValueConverter: Clean/modify tokenized<br>rules returned value
ValueConverter -->> Package: Return AST
```

- When to override `TokenBuilder`?
  - To override keyword rules.
  - To override terminal rules that need a custom function.
  - To manually reorder the list of rules.

- When to override `Lexer`?
  - To modify input before tokenizing.
  - To insert/modify tokens that cannot or have not been parsed.

- When to override `LangiumParser`?
  - To insert or modify attributes that can't be parsed.

- When to override `ValueConverter`?
  - To modify the returned value from the parser.

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