npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cli-forge/parser

v1.1.0

Published

**A type-safe argument parser for Node.js with full TypeScript inference.**

Readme

@cli-forge/parser

A type-safe argument parser for Node.js with full TypeScript inference.

This is the low-level parsing engine that powers cli-forge. Use this package directly if you need fine-grained control over argument parsing without the higher-level command management features.

Installation

npm install @cli-forge/parser

Quick Start

import { parser } from '@cli-forge/parser';

const args = parser()
  .option('name', { type: 'string', required: true })
  .option('port', { type: 'number', default: 3000 })
  .option('verbose', { type: 'boolean', alias: ['v'] })
  .parse(['--name', 'my-app', '--port', '8080', '-v']);

// args is fully typed:
// { name: string; port: number; verbose: boolean }
console.log(args.name);    // 'my-app'
console.log(args.port);    // 8080
console.log(args.verbose); // true

Features

  • Full TypeScript inference - Types accumulate as you chain .option() calls
  • Multiple option types - string, number, boolean, array, object
  • Value sources - CLI args, environment variables, config files, defaults
  • Validation - choices, validate, required, conflicts, implies
  • Config file support - JSON/YAML with inheritance via extends
  • Coercion - Transform values during parsing

Option Types

String

parser().option('name', {
  type: 'string',
  description: 'User name',
  default: 'anonymous',
});

Number

parser().option('port', {
  type: 'number',
  description: 'Port number',
  default: 3000,
});

Boolean

parser().option('verbose', {
  type: 'boolean',
  alias: ['v'],
  description: 'Enable verbose output',
});
// Supports: --verbose, --verbose true, --no-verbose

Array

parser().option('files', {
  type: 'array',
  items: 'string',
  description: 'Input files',
});
// Supports: --files a b c, --files a,b,c, --files a --files b

Object

parser().option('config', {
  type: 'object',
  properties: {
    host: { type: 'string', default: 'localhost' },
    port: { type: 'number', required: true },
    ssl: { type: 'boolean' },
  },
});
// Supports: --config.host example.com --config.port 443 --config.ssl

Positional Arguments

parser()
  .positional('input', { type: 'string', required: true })
  .positional('output', { type: 'string' })
  .parse(['input.txt', 'output.txt']);

Validation

Choices

parser().option('level', {
  type: 'string',
  choices: ['debug', 'info', 'warn', 'error'],
});

Custom Validation

parser().option('port', {
  type: 'number',
  validate: (value) => {
    if (value < 1 || value > 65535) {
      throw new Error('Port must be between 1 and 65535');
    }
    return true;
  },
});

Conflicts and Implies

parser()
  .option('quiet', { type: 'boolean' })
  .option('verbose', {
    type: 'boolean',
    conflicts: ['quiet'],
  })
  .option('output', {
    type: 'string',
    implies: { format: 'json' },
  });

Environment Variables

parser().option('apiKey', {
  type: 'string',
  env: 'API_KEY',
});
// Will read from process.env.API_KEY if --apiKey not provided

Configuration Files

parser()
  .configFile('myapp.config.json')
  .option('port', { type: 'number' })
  .parse([]);

Config files support inheritance:

{
  "extends": "./base-config.json",
  "port": 8080
}

Coercion

Transform values during parsing:

parser().option('date', {
  type: 'string',
  coerce: (value) => new Date(value),
});

Type Inference

The parser tracks types as options are added:

const p = parser()
  .option('name', { type: 'string' })        // { name?: string }
  .option('port', { type: 'number' })        // { name?: string; port?: number }
  .option('required', { type: 'string', required: true }); // { name?: string; port?: number; required: string }

Related Packages

  • cli-forge - High-level CLI builder with commands, middleware, and documentation generation

Documentation

Full documentation available at: https://craigory.dev/cli-forge/

License

ISC