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 🙏

© 2025 – Pkg Stats / Ryan Hefner

soldier

v0.1.0

Published

A modern, type-safe CLI framework with zero dependencies

Readme

Soldier 🎖️

A modern CLI framework for JavaScript & TypeScript with zero dependencies

Works perfectly with plain JavaScript, but gives you amazing type inference when you use TypeScript.

Why Soldier?

Built from the ground up for both JavaScript and TypeScript, Soldier provides automatic validation, type conversion, and a cleaner API than existing solutions. Get all the features whether you use JS or TS!

vs Commander

| Feature | Soldier | Commander | |---------|---------|-----------| | Dependencies | 0 | 0 | | Bundle Size | ~5KB | ~7KB | | TypeScript | Native, full type inference | Types via @types | | Option Types | Automatic type conversion & validation | Manual parsing | | Validation | Built-in (min/max, choices, required) | Manual | | Type Safety | Fully inferred option types | Requires manual typing | | Async Actions | Native async/await support | Callback-based | | Modern | ES Modules, latest TypeScript | CommonJS legacy |

Installation

npm install soldier

Quick Start

import { cli } from 'soldier';

const app = cli('my-app')
  .version('1.0.0')
  .description('My awesome CLI');

app
  .command('deploy')
  .description('Deploy to environment')
  .option('--env <env>', {
    description: 'Environment',
    choices: ['prod', 'dev', 'staging'] as const,
    required: true
  })
  .option('--force', {
    description: 'Force deployment',
    type: 'boolean'
  })
  .option('--port <port>', {
    type: 'number',
    min: 1,
    max: 65535,
    default: 3000
  })
  .action(async (opts) => {
    // opts is fully typed!
    // opts.env: 'prod' | 'dev' | 'staging'
    // opts.force: boolean | undefined
    // opts.port: number

    console.log(`Deploying to ${opts.env} on port ${opts.port}`);
  });

app.parse();

JavaScript Users

Works exactly the same in plain JavaScript! Just remove the as const:

import { cli } from 'soldier';

const app = cli('my-app')
  .version('1.0.0');

app
  .command('deploy')
  .option('--env <env>', {
    choices: ['prod', 'dev', 'staging'],  // No "as const" needed
    required: true
  })
  .option('--port <port>', {
    type: 'number',
    min: 1,
    max: 65535,
    default: 3000
  })
  .action(async (opts) => {
    // All validation automatic!
    // opts.port is already a number (not a string!)
    console.log(`Deploying to ${opts.env} on port ${opts.port}`);
  });

app.parse();

You get all the same features - validation, type conversion, clean API. The only difference is TypeScript gives you IntelliSense autocomplete.

See full JavaScript guide →

Features

🎯 Full Type Inference

Options are automatically typed based on their configuration:

app
  .command('serve')
  .option('--port <port>', { type: 'number', default: 3000 })
  .option('--host <host>', { default: 'localhost' })
  .option('--watch', { type: 'boolean' })
  .action((opts) => {
    opts.port   // number
    opts.host   // string
    opts.watch  // boolean | undefined
  });

✅ Built-in Validation

No need for manual validation logic:

app
  .command('config')
  .option('--env <env>', {
    choices: ['production', 'staging', 'development'] as const,
    required: true  // Error if not provided
  })
  .option('--timeout <ms>', {
    type: 'number',
    min: 100,      // Error if less than 100
    max: 30000     // Error if greater than 30000
  })
  .action((opts) => {
    // All validation is done automatically
  });

🔄 Automatic Type Conversion

Values are automatically parsed to the correct type:

// $ my-cli calc --x 5 --y 10 --verbose

app
  .command('calc')
  .option('--x <number>', { type: 'number' })
  .option('--y <number>', { type: 'number' })
  .option('--verbose', { type: 'boolean' })
  .action((opts) => {
    const result = opts.x + opts.y;  // No parsing needed!
    console.log(result);             // 15 (not "510")
  });

📚 Beautiful Auto-Generated Help

Help text is automatically generated from your configuration:

$ my-cli deploy --help

Deploy application to specified environment

Usage:
  my-cli deploy [options]

Options:
      --env <value>        Target environment (required, choices: production, staging, development)
      --force              Force deployment (default: false)
      --port <value>       Port number (default: 3000, min: 1, max: 65535)

Examples:
  $ my-cli deploy --env production --force
    Deploy to production

⚡ Short Aliases

Add convenient short flags:

app
  .command('build')
  .option('-o, --output <path>', {
    description: 'Output directory',
    default: 'dist'
  })
  .option('-w, --watch', {
    type: 'boolean',
    description: 'Watch for changes'
  })
  .action((opts) => {
    // Can use -o or --output
  });

📖 Examples

Add helpful examples to your commands:

app
  .command('deploy')
  .option('--env <env>', { choices: ['prod', 'dev'] as const })
  .example('my-cli deploy --env prod', 'Deploy to production')
  .example('my-cli deploy --env dev', 'Deploy to development')
  .action((opts) => {
    // ...
  });

API Reference

cli(name: string)

Create a new CLI application.

const app = cli('my-app');

.version(version: string)

Set the CLI version.

app.version('1.0.0');

.description(description: string)

Set the CLI description.

app.description('My awesome CLI');

.command(name: string)

Create a new command.

app.command('build');

.option(flags: string, config: OptionConfig)

Add an option to a command.

command.option('--env <environment>', {
  description: 'Target environment',
  choices: ['prod', 'dev'] as const,
  required: true
});

Option Configuration

{
  description?: string;    // Help text
  type?: 'string' | 'number' | 'boolean';  // Type (inferred from flags if not set)
  required?: boolean;      // Make option required
  default?: any;           // Default value
  alias?: string;          // Short flag (auto-extracted from flags)

  // String options:
  choices?: readonly string[];  // Allowed values

  // Number options:
  min?: number;            // Minimum value
  max?: number;            // Maximum value
}

.action(handler: ActionHandler)

Set the command handler.

command.action(async (opts, ...args) => {
  // opts contains parsed options (fully typed!)
  // args contains positional arguments
});

.example(command: string, description: string)

Add an example to the command.

command.example('my-cli deploy --env prod', 'Deploy to production');

.parse(argv?: string[])

Parse and execute the CLI. Defaults to process.argv.slice(2).

app.parse();  // Parse process.argv
app.parse(['deploy', '--env', 'prod']);  // Parse custom args

Examples

See the examples directory for complete working examples:

TypeScript:

JavaScript:

Run them:

# TypeScript examples
node examples/simple.ts greet --name Alice
node examples/deploy.ts deploy --env staging --port 8080

# JavaScript examples
node examples/simple.js greet --name "World" --loud
node examples/deploy.js deploy --env staging --port 8080
node examples/api.js start --port 4000 --workers 2

Comparison Code

Soldier

import { cli } from 'soldier';

const app = cli('deploy')
  .version('1.0.0')
  .description('Deploy tool');

app
  .command('up')
  .option('--env <env>', {
    choices: ['prod', 'dev'] as const,
    required: true
  })
  .option('--port <port>', {
    type: 'number',
    min: 1,
    max: 65535,
    default: 3000
  })
  .action(async (opts) => {
    // opts.env is 'prod' | 'dev'
    // opts.port is number
    // Validation is automatic
    console.log(`Deploying to ${opts.env}:${opts.port}`);
  });

app.parse();

Commander

import { program } from 'commander';

program
  .version('1.0.0')
  .description('Deploy tool');

program
  .command('up')
  .requiredOption('--env <env>', 'Environment')
  .option('--port <port>', 'Port', '3000')
  .action((opts) => {
    // Manual type checking needed
    const env = opts.env as string;
    const port = parseInt(opts.port);

    // Manual validation needed
    if (!['prod', 'dev'].includes(env)) {
      console.error('Invalid env');
      process.exit(1);
    }
    if (port < 1 || port > 65535) {
      console.error('Invalid port');
      process.exit(1);
    }

    console.log(`Deploying to ${env}:${port}`);
  });

program.parse();

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.

Roadmap

  • [ ] Subcommands (nested commands)
  • [ ] Custom validators
  • [ ] Config file support
  • [ ] Shell completion generation
  • [ ] Interactive prompts
  • [ ] Color output utilities
  • [ ] Progress bars

Why "Soldier"?

Because it's disciplined, reliable, and gets the job done. Plus, CLI → command → military theme.