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

tinyargs

v0.1.4

Published

A tiny and flexible command-line argument parser for Node.js and Deno.

Readme

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


tinyargs

npm version npm downloads Coverage Status

A tiny and flexible command-line argument parser for Node.js and Deno.

Features

  • Support combined short flags, -abc foo is expanded to -a -b -c foo
  • Support using equal sign to specify argument value, -c=config.js is expanded to -c config.js
  • Support positional arguments like your-cli foo bar
  • Support collecting trailing arguments
  • Support sub commands

Install

npm i tinyargs

Deno users:

import { parse } from "https://deno.land/x/tinyargs/mod.ts"

Examples

Simple Example

import { parse } from "tinyargs"

const cli = parse(process.argv.slice(2), [
  { name: "help", flags: ["h"], type: Boolean, stop: true },
  { name: "version", flags: ["v"], type: Boolean, stop: true },
  { name: "files", type: String, positional: true, multiple: true },
])

if (cli.help) {
  console.log(`...your help message`)
  process.exit()
}

if (cli.version) {
  console.log(`...version number`)
  process.exit()
}

console.log(cli.files)

Run this cli:

$ node cli.js -h
...your help message

$ node cli.js -v
...version number

$ node cli.js foo.js bar.js
[ 'foo.js', 'bar.js' ]

$ node cli.js
error: missing positional argument: files

If -h, --help or -v, --version appears, the remaining arguments are not parsed, since we added stop: true to the option.

By default all options and positional arguments are required to have a value, if you add a string option named foo but it's used like --foo --bar, it will throw an error. This can be customized by setting optionalValue: true, which in this case would give foo a default value of true instead.

Sub Commands

Create a CLI with two sub commands: (We use <> and [] to denote cli arguments in the docs, <> means it's required, [] means it's optional.)

  • run <script> [args...]: like yarn run or npm run, run a script and collect trailing arguments so that you can pass them to the script later.
  • download <url>: download from a url.
const cli = parse(process.argv.slice(2), [
  { name: "command", type: String, positional: true },
  {
    name: "script",
    type: String,
    positional: true,
    when: (cli) => cli.command === "run",
    stop: true,
  },
  {
    name: "url",
    type: String,
    positional: true,
    when: (cli) => cli.command === "download",
  },
])

if (cli.command === "run") {
  console.log(`...running ${cli.script} with forwarded arguments ${cli._}`)
} else if (cli.command === "download") {
  console.log(`...downloading ${cli.url}`)
} else {
  console.log(`...unknown command ${cli.command}`)
}

Guide

Flags

Define a flag that could be used as your-cli --file <value>, only name and type are required:

parse(process.argv.slice(2), [{ name: "file", type: String }])

Positional Arguments

Define a positional argument that could be used as your-cli <file>, by setting positional: true:

parse(process.argv.slice(2), [{ name: "file", type: String, positional: true }])

Repeated / Multiple Flags and Positional Arguments

Flags can be repeated if you set multiple: true:

parse(process.argv.slice(2), [{ name: "file", type: String, multiple: true }])

Now your cli can be used as your-cli --file a.js --file b.js, the resulting object will look like: { file: [ 'a.js', 'b.js' ] }.

Positional arguments work in a similar fashion:

parse(process.argv.slice(2), [
  { name: "file", type: String, positional: true, multiple: true },
])

Now you can do your-cli a.js b.js, the resulting object will look like: { file: [ 'a.js', 'b.js' ] }.

Note that you can't have two multiple poitional arguments in the same command, because the first one will collect all positional arguments.

Collecting Trailing Arguments

There're two way, first is to use the stop option, which will stop parsing arguments after the option, and arguments beyond that point will be collected under _ in the returned object:

const cli = parse(
  ["--foo", "bar", "baz", "--some-flag"],
  [{ name: "foo", type: Boolean, stop: true }],
)

console.log(cli)
// { foo: true, _: [ 'bar', 'baz', '--some-flag' ] }

The second way is to use positional: true with multiple: 'include-flags', which will collect trailing arguments into the specific option:

const cli = parse(
  ["--foo", "bar", "baz", "--some-flag"],
  [
    { name: "foo", type: Boolean },
    {
      name: "args",
      type: String,
      positional: true,
      multiple: "include-flags",
    },
  ],
)

console.log(cli)
// { foo: true, args: [ 'bar', 'baz', '--some-flag' ] }

API Reference

https://www.jsdocs.io/package/tinyargs

Sponsors

sponsors

License

MIT © EGOIST