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

applause-cli

v1.8.2

Published

Super-duper lightweight no-dependency alternative to clap

Downloads

27

Readme

applause-cli

Super-duper lightweight no-dependency alternative to clap

Inspired by clap. It wasn't quite what I wanted, so I wrote my own :P

This is refactored out of my main PhD codebase, so if you're wondering why there aren't very many commits, that's why.

  • Current version: current npm version - see the GitHub releases
  • API Docs: https://starbeamrainbowlabs.com/code/applause-cli/
  • Changelog: https://github.com/sbrl/applause-cli/blob/master/Changelog.md

Install

Install via npm:

npm install applause-cli --save

Usage

Example usage:

"use strict";

import path from 'path';

import CliParser from 'applause-cli';

// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great :D
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));

// Locate your package.json - this assumes it's sitting in the parent directory of this file (e.g. if this file was ./src/index.json and it was at ./package.json)
const package_json_filepath = path.resolve(__dirname, "../package.json");

// Create a new CLI parser
// The name description, version number, etc are all populated from there
const cli = new CliParser(package_json_filepath);

cli.argument("foo", "This is a global argument.", true, "boolean")

cli.subcommand("do_stuff", "Do some stuff.")
	// An argument just for this subcommand
	.argument("input", "The input file to do stuff with.", "default_value_here", "string");

console.log(
	cli.parse(process.argv.slice(2))
);

The full API documentation can be found here: https://starbeamrainbowlabs.com/code/applause-cli/.

Argument Types

Several argument types are currently supported. They are specified as the 4th argument to the .argument() command (either globally or on a specific subcommand):

Type | Meaning ------------|---------------------------- string | Just a string. integer | An integer (parseInt(value, 10) is used) float | A floating-point number (parseFloat(value) is used) boolean | A boolean true/false value. Unlike other types, arguments with this type do not take an explicit value on the cli (e.g. --foo bar) - rather their presence on the CLI sets the value to true. This can be overridden though with argument.has_value = true. date | Parse the string as a date with new Date(value) <function>| Pass a function to do custom parsing. The function provided will be called with a single argument - the value that needs parsing. The return value will be considered the parsed value.

In addition, a function can be passed instead of a string defining the type of an argument, and that function will be called with a single argument to parse values instead:

// .....
cli.argument("foo", "An example argument --foo", 128, function(value) {
	// Parse the value as an int and double it before returning
	return parseInt(value, 10) * 2;
});

Read-world use

Contributing

Contributions are welcome as PRs! Don't forget to say that you donate your contribution under the Mozilla Public License 2.0 in your PR comment.

Licence

This project is licensed under the Mozilla Public License 2.0. See the LICENSE file in this repository for the full text.