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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@benev/argv

v0.1.0

Published

command line argument parser

Downloads

152

Readme

🎛️ @benev/argv

command line argument parser

🤖 for making node cli programs
💁 autogenerated --help page
🕵️‍♂️ designed for good typescript typings
🧼 zero dependencies
💖 made free and open source, just for you

example generated help page

$ icecream waffle-cone --flavor="cookie-dough" --scoops="5" +help

example help output

instructions

  1. install @benev/argv via npm
    npm install @benev/argv
  2. import the cli function
    import {cli} from "@benev/argv"
  3. formalize types for your arguments and parameters
    export type Args = {
      vessel: string
    }
    
    export type Params = {
      flavor: string
      scoops: number
      help: boolean
    }
  4. specify your cli, and perform the parsing
    const {args, params} = cli<Args, Params>()({
      program: "icecream",
      argv: process.argv,
      columns: process.stdout.columns ?? 72,
    
      // positional arguments your program will accept
      argorder: ["vessel"],
    
      // arguments your program will accept
      args: {
        vessel: {
          type: String,
          mode: "requirement",
          help: 'can be "cone", "bowl", or "waffle-cone"',
        },
      },
    
      // parameters your program will accept
      params: {
        flavor: {
          type: String,
          mode: "default",
          default: "vanilla",
          help: "your favorite icecream flavor",
        },
        scoops: {
          type: Number,
          mode: "requirement",
          help: "number of icecream scoops",
        },
        help: {
          type: Boolean,
          mode: "option",
          help: "trigger the help page",
        },
      },
    })
  5. now you can access your args and params
    // example command:
    //  $ icecream waffle-cone --flavor cookie-dough --scoops 5
    
    args.vessel
      // "waffle-cone"
    
    params.flavor
      // "cookie-dough"
    
    params.scoops
      // 5

notes

  • typings work best if you declare Args and Params types, but it can infer some of it if you omit them.
  • these are equivalent ways to pass a param:
    • --param true
    • --param "true"
    • --param=true
    • --param="true"
    • +param (sets to boolean true)
  • boolean parsing regards these as true (case-insensitive):
    • "true"
    • "yes"
    • "y"
    • "on"
    • "ok"
    • "enabled"
  • --help has magic handling: it's the only "void" parameter which doesn't expect to be followed by a value
    • eg, icecream --help is good
    • eg, icecream --help true is bad
    • understand that --help is the ONLY parameter treated this way
    • all other parameters require a value
    • parameter syntax is strict like this so that it's consistent and unambiguous
    • however people will panic if --help doesn't give the expected result, thus the magic handling here
    • use +param as a shorthand for enabling a boolean
    • +help also works
  • you can disable the ansi colors by passing theme: notheme after import {notheme} from "@benev/argv"
  • you can disable the "tips" section by passing tips: false
  • you can also pass
    • columns current terminal width, used for text-wrapping
    • help description and usage instructions for your program
    • readme url to your program's readme