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

@wcauchois/program-builder

v0.1.3

Published

[![npm version](https://badge.fury.io/js/%40wcauchois%2Fprogram-builder.svg)](https://badge.fury.io/js/%40wcauchois%2Fprogram-builder) [![CircleCI Build](https://circleci.com/gh/wcauchois/program-builder.svg?style=svg)](https://circleci.com/gh/wcauchois/p

Downloads

11,061

Readme

program-builder

npm version CircleCI Build Netlify Status

This is a TypeScript-first library for building type safe command-line interfaces.

You define your arguments and keyword arguments using a fluent builder, which gives you a Program object. You can then define a main function in terms of the strongly typed arguments of that Program, and finally execute the main function against your program which will parse and provide commandline arguments.

Documentation Website | Examples | API Docs

Installation

npm install @wcauchois/program-builder

Features

  • Positional arguments (required and optional).
  • Boolean flags (both "positive", like --unroll-loops; and "inverted", like --no-unroll-loops).
  • Keyword flags like --path foo.txt. These can be strings, integers, or floats - or you can provide a custom conversion function.
  • Validations like ensuring that all required arguments are specified (aka: types should not lie).
  • Automatic generation of help text and handling of a help argument (-h, --help).
  • Executes Promise-returning main functions and correctly exits the process.
  • Subcommands.

Example

const program = ProgramBuilder.newBuilder()
  .arg('filename', { description: `A file name` })
  .optionalArg('extraFilename', { description: `An additional optional file name`})
  .intFlag('--optionalCount,-c', { dest: 'optionalCount', default: null, description: `A count` })
  .intFlag('--requiredCount', { dest: 'requiredCount', description: `A count that is required` })
  .build();

function main(args: Arguments<typeof program>) {
  console.log(`filename is: ${args.filename}`); // args.filename: string
  console.log(`extraFilename is: ${args.extraFilename}`); // args.extraFilename: string | null
  console.log(`optionalCount is: ${args.count}`); // args.optionalCount: number | null
  console.log(`requiredCount is: ${args.requiredCount}`); // args.requiredCount: number
}

program.exec(main);

An example invocation of this program would be:

$ ts-node main.ts file1.txt file2.txt -c 1 --requiredCount 2

You can also view autogenerated help text by executing the program with an -h parameter.

$ ts-node main.ts -h
Usage: main.ts [options] <filename> [extraFilename]

Options:
  --count, -c [count]              A count
  --requiredCount [requiredCount]  A count that is required

Beta Software

As of January 2020, Program Builder is a very young library! That said, I think it occupies a valuable niche offering better type safety than yargs or commander with less verbosity than ts-command-line.

The argument parsing library that gives me the most joy is Python's argparse and I'm striving to create something similarly lightweight but powerful for TypeScript.

At this stage your feedback is extremely valuable, and if you have anything to say, please file an issue!