Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads138/wk
Published22 hours ago (0.9.1)

Type-safe combinatorial command-line interface parser

@optique/core

Warning

The API is stabilizing, but may change before the 1.0 release.

The core package of Optique which provides the shared types and parser combinators. It is designed to be used in universal JavaScript runtimes, including Node.js, Deno, Bun, edge functions, and web browsers—although you usually won't use it directly in browsers.

Tip

Building CLI apps? Consider @optique/run for automatic process.argv handling and process.exit() integration. This core package is perfect for libraries, web apps, or when you need full control over argument parsing.

When to use @optique/core

Use @optique/core instead when:

  • Building web applications or libraries
  • You need full control over argument sources and error handling
  • Working in environments without process (browsers, web workers)
  • Building reusable parser components

Use @optique/run when:

  • Building CLI applications for Node.js, Bun, or Deno
  • You want automatic process.argv parsing and process.exit() handling
  • You need automatic terminal capability detection (colors, width)
  • You prefer a simple, batteries-included approach

Quick example

import { runParser } from "@optique/core/facade";
import { object, option, argument } from "@optique/core/parser";
import { string, integer } from "@optique/core/valueparser";
import process from "node:process";

const parser = object({
  name: argument(string()),
  age: option("-a", "--age", integer()),
  verbose: option("-v", "--verbose"),
});

const config = runParser(parser, "myapp", process.argv.slice(2), {
  help: "both",
  onError: process.exit,
});

console.log(`Hello ${config.name}!`);
if (config.age) console.log(`You are ${config.age} years old.`);
if (config.verbose) console.log("Verbose mode enabled.");

For more resources, see the docs and the examples/ directory.

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@optique/core

Import symbol

import * as core from "@optique/core";
or

Import directly with a jsr specifier

import * as core from "jsr:@optique/core";

Add Package

pnpm i jsr:@optique/core
or (using pnpm 10.8 or older)
pnpm dlx jsr add @optique/core

Import symbol

import * as core from "@optique/core";

Add Package

yarn add jsr:@optique/core
or (using Yarn 4.8 or older)
yarn dlx jsr add @optique/core

Import symbol

import * as core from "@optique/core";

Add Package

vlt install jsr:@optique/core

Import symbol

import * as core from "@optique/core";

Add Package

npx jsr add @optique/core

Import symbol

import * as core from "@optique/core";

Add Package

bunx jsr add @optique/core

Import symbol

import * as core from "@optique/core";