Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/saiashirwad/parserator/llms.txt

Use this file to discover all available pages before exploring further.

Installation

Get started with Parserator in seconds. Install the package and you’re ready to build parsers.

Install the package

Choose your preferred package manager:
npm install parserator

TypeScript requirements

Parserator requires TypeScript 5.0 or higher for full type inference.
Parserator has typescript@^5.0.0 as a peer dependency. Make sure your project uses TypeScript 5.0 or later to get the best type inference experience.
If you haven’t installed TypeScript yet:
npm install --save-dev typescript

Verify installation

Create a simple test file to verify everything works:
test.ts
import { parser, char, digit } from "parserator";

const singleDigit = digit;
const result = singleDigit.parseOrThrow("5");

console.log(result); // "5"
Run it with your TypeScript runtime:
npx ts-node test.ts
If you see "5" printed to the console, you’re all set!

TypeScript configuration

For the best experience, ensure your tsconfig.json includes these settings:
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  }
}
The strict flag is recommended to get the full benefits of TypeScript’s type checking with Parserator’s inferred types.

Import styles

Parserator supports both named and wildcard imports:
// Named imports (recommended)
import { parser, char, string, many1, digit, or } from "parserator";

// Wildcard import
import * as P from "parserator";
const myParser = P.parser(function* () {
  yield* P.char("(");
  // ...
});

Module formats

Parserator is distributed as both ESM and CommonJS:
// ESM (recommended)
import { parser } from "parserator";

// CommonJS
const { parser } = require("parserator");
The package automatically uses the correct format based on your project configuration.

Next steps

Quickstart

Build your first parser with a step-by-step tutorial

Core concepts

Learn the fundamental concepts behind parser combinators