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

litargs

v0.3.2

Published

Lite argument parser

Downloads

1

Readme

Litargs


typescript node.js npm npm GitHub issues GitHub forks GitHub stars GitHub license

Would you like to parse arguments more easily?

Highlights:flashlight:

  • The easiest CLI command line parser
  • Recommended for those who want simple parsing results
  • Easy to set options
  • Automatically create help

Install

npm install litargs

Usage

  • index.js
//Example of a command to move a file
const { Litargs } = require('litargs');
const fs = require('fs');

Litargs.command(
    'move',
    2,
    { args: ['source', 'destination'], detail: 'Move a file' },
    (args, option) => {
        if (option.cp) {
            fs.copyFileSync(args[0], args[1]);
        } else {
            fs.renameSync(args[0], args[1]);
        }
    }
)
    .option('cp', 0, { detail: 'copy' })
    .parse(process.argv.slice(2).join(' '));

Litargs.execute();
  • Command Line
$ node index.js move /Users/hoge.txt /Users/fuga.txt --cp
  • help
Commands:
help                    Display a list of commands and options


move    [source, destination]   Move a file
        Options:
        --cp                    copy

API

Litargs.command(name<string>, argumentCount<number>, description<{args?: string[], detail: string}>, handler<(args<string>, option<{[optionName: string]: string[]|boolean>}): unknown>)

Add the command. Arguments are the name of the command, the number of arguments, a description of the command, and the function to be executed. The handler can accept arguments and options. For description, set the name of the argument in args and a concrete description in detail. If the expected number of arguments is 0, there is no need to set args.

Litargs.option(name<string>, argumentCount<number>, description<args?: string[], detail: string>)

Commands and options are added in the method chain.

Litargs.command(...).option(...).option(...).command(...).option(...)...

The option method will be applied to the last command added. The basic settings are the same as for the command method. Options that require arguments are prefixed with "-", and options that do not require arguments are prefixed with "--". This does not need to be attached to "name", but it is required on the command line.

Litargs.alias(name<string>)

The alias method will be applied to the last command added. You can give different names to the commands.

Litargs.parse(parsedString<string>)

Add this to the end of the method chain. For use with the node.js cli, specify process.argv.slice(2).join(' '). This method returns a simple parsing result.

Litargs.execute()

Execute the registered handler. This should not be done before parse.

Issues

If you find a bug or problem, please open an issue!:bug:

Author

LICENSE

This project is licensed under the MIT License - see the LICENSE file for details.