# @mlc-ai/web-xgrammar

> This folder contains the source code and emcc bindings for compiling XGrammar to Javascript/Typescript via [emscripten](https://emscripten.org/).

Latest version **0.1.27** (published 2025-12-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @mlc-ai/web-xgrammar
pnpm add @mlc-ai/web-xgrammar
yarn add @mlc-ai/web-xgrammar
bun add @mlc-ai/web-xgrammar
```

## Health

**Score 65/100 (B)** — status: stable.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.27 |
| Published | 2025-12-25 |
| First published | 2024-11-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2005 |
| Maintainers | tqchen, akaashrp, charliefruan, neetnestor, rickzx, ruihanglai, sudeepag |
| Keywords | machine_learning, llm, nlp |

## Links

- npm: https://www.npmjs.com/package/@mlc-ai/web-xgrammar
- Repository: https://github.com/mlc-ai/xgrammar
- Homepage: https://github.com/mlc-ai/xgrammar/tree/main/web
- Issues: https://github.com/mlc-ai/xgrammar/issues
- npm.io page: https://npm.io/package/@mlc-ai/web-xgrammar

## Recent versions

- 0.1.27 (latest) — 2025-12-25
- 0.1.0 — 2024-11-22

## README

# web-xgrammar

This folder contains the source code and emcc bindings for compiling XGrammar to Javascript/Typescript via [emscripten](https://emscripten.org/).

### Build from source
1. Install [emscripten](https://emscripten.org). It is an LLVM-based compiler that compiles C/C++ source code to WebAssembly.
    - Follow the [installation instruction](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions-using-the-emsdk-recommended) to install the latest emsdk.
    - Source `emsdk_env.sh` by `source /path/to/emsdk_env.sh`, so that `emcc` is reachable from PATH and the command `emcc` works.
    - We can verify the successful installation by trying out `emcc` in the terminal.

2. Modify the content of `cmake/config.cmake` to be `web/config.cmake`.

3. Run the following

    ```bash
    source /path/to/emsdk_env.sh
    npm install
    npm run build
    ```

### Example
To try out the test webpage, run the following
```bash
cd example
npm install
npm start
```

### Testing
For testing in `node` environment, run:
```bash
npm test
```

---
_Source: https://npm.io/package/@mlc-ai/web-xgrammar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
