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

@nartallax/cli

v1.0.3

Published

A library for creating command-line interface for NodeJS applications

Downloads

3

Readme

@nartallax/cli

A library for creating command-line interface for NodeJS applications

Install

npm install @nartallax/cli

Use

import {CLI} from "@nartallax/cli"

// let's start with defining our options
const definition = CLI.define({
  // this is header that will be displayed in `--help`
  // as you can see, for this example we will define options for web application
  helpHeader: "Multiplication web application",
  options: {
    // simple number option.
    // note that this option will accept fractions; there is `CLI.int()` that won't.
    multiplier: CLI.number({
      keys: ["-m", "--multiplier"],
      description: "Factor by which input value will be multiplied",
      default: 2
    }),
    // enum option - only allows to pass a value from a predefined set of strings
    // parsed value will be typed as union of constants, not just `string`
    mode: CLI.str<"as-usual" | "negate">({
      keys: "--mode",
      description: "Mode in which application will work.",
      allowedValues: ["as-usual", "negate"],
      default: "as-usual"
    }),
    // port option - same as `CLI.int()` but with pre-defined boundaries
    port: CLI.port({
      keys: ["-p", "--port"],
      description: "Port on which web application will expose its UI",
      default: 46725
    }),
    // path option - same as `CLI.str()` but with built-in resolving to absolute path
    configPath: CLI.path({
      keys: ["-c", "--config-path"],
      description: "Path to config file"
      // no default here! it means this option is mandatory and can only be skipped if help is passed.
    }),
    // path array option
    // most options can be arrays, not only paths
    // user could pass multiple values like this: `--preset a.json --preset b.json`
    presets: CLI.pathArr({
      keys: "--preset",
      description: "Operation preset files.",
      default: []
    })
    // other types of options and constraints are available, make sure to check type definitions
  }
  // other parameters are possible to pass here, but I leave them for you to discover
})

// we may want to get the type we just defined
// after parsing arguments will be organised as object
export type CLIArgs = CLI.ArgsByDefinition<typeof definition>

// and, at last, let's parse arguments that were passed to our program
// default source or arguments is `process.argv`, but you may pass something custom here
export const parseCliArgs = (): CLIArgs => definition.parse()