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

@zakkudo/argument-parser

v0.0.1

Published

Make parsing node command line arguments enjoyable.

Downloads

1

Readme

@zakkudo/argument-parser

Make parsing node command line arguments enjoyable.

Build Status Coverage Status Known Vulnerabilities Node License

Why use this?

  • Straight forward configuration
  • Reusability

What does it do?

  • Parses arguments using multiple configuration types

Install

# Install using npm
npm install @zakkudo/argument-parser
# Install using yarn
yarn add @zakkudo/argument-parser

Examples

Basic example

const parse = new ArgumentParser({
    name: 'download-program',
    version: 'v1.3.4',
    description: 'A program for downloading files very fastly.',
    leftover: 'files',
    schema: [{
        long: 'fast',
        short: 'f',
        type: 'boolean',
        description: 'Makes the download go very fast.',
    }, {
        long: 'token',
        short: 't',
        type: 'string',
        description: 'Token used for authentication.',
    }, {
        long: 'muliplier',
        short: 'm',
        type: 'float',
        description: 'How many times faster the download should be.',
    }, {
        long: 'servers',
        type: 'list',
        typeName: 's1,s2,s3',
        description: 'Servers to use for the fast downloading, separated by a comma.',
    }]
});

const parsed = parse(['--fast', '--token', '1234', 'src/**/*.js', ]
// Returns an object with the below:
// {
//     "fast": true,
//     "leftover": [
//         "src/**/*.js",
//     ],
//     "token": "1234",
// }

parse(['--version']
// Exits, printing: "download-program version v1.3.4"

parse(['--help'])
// Exits, printing:
// usage: download-program [--help] [--version] [--fast] [--token=uuid] [--muliplier=float] [--servers=s1,s2,s3] ...files
// A program for downloading files very fastly.
//
// -h/--help            Show this help information.
// -V/--version         Show the program version.
// -f/--fast            Makes the download go very fast.
// -t/--token=uuid      Token used for authentication.
// -m/--muliplier=float How many times faster the download should be.
// --servers=s1,s2,s3   Servers to use for the fast downloading, separated by a comma.

API

@zakkudo/argument-parser~ArgumentParser ⏏

Kind: Exported class

new ArgumentParser(options)

| Param | Type | Description | | --- | --- | --- | | options | Options | The configuration options for how parsing is done. returns {module:@zakkudo/argument-parser~ArgumentParser~ParseFunction} A function used to parse arguments given the configuration during construction. |

ArgumentParser~ParseFunction ⇒ Object

Parse function

Kind: inner typedef of ArgumentParser
Returns: Object - An object for the given schema configuration
Throws:

  • InvalidArgumentError when and argument is malformed
  • InvalidSchemaError when an invalid schema type is used for one of the actions and it's referenced

| Param | Type | Description | | --- | --- | --- | | argv | Array | The arguments you want to parse |

ArgumentParser~Schema : Object

The schema configuration for the paramters of the program

Kind: inner typedef of ArgumentParser
Properties

| Name | Type | Description | | --- | --- | --- | | type | Type | The type of parameter. One of string, interger, float, or list | | [typeName] | String | The type name used for display. An example would be a glob, filename, or other more concrete concept. | | description | String | The description of the | | [long] | String | The long form of the switch or nothing | | [short] | String | The short form of the switch or nothing |

ArgumentParser~Options : Object

Argument parser configuration, controling how argumetns are parsed and how they are shown in help documentation. You must have at least a long or short switch name set.

Kind: inner typedef of ArgumentParser
Properties

| Name | Type | Description | | --- | --- | --- | | name | String | The name of the executable this library is being used in; | | version | String | A version string that will be shown with the --version switch; | | description | String | A blurb of text explaining the how's and why's of the program. | | schema | Schema | The configuration | | [leftover] | String | The name for the leftover parameters. Without this, leftover parameters will be disallowed. |

@zakkudo/Type~Type : enum

Kind: inner enum of @zakkudo/Type
Read only: true
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | INTEGER | String | integer | Used for arguments that should be parsed with parseInt. | | FLOAT | String | float | Used for arguments that should be parsed with parseFloat. | | STRING | String | string | Used for arguments that should be used as raw string. | | BOOLEAN | String | boolean | Used for arguments that should be assumed a true boolean when the flag exists. | | LIST | String | list | Used for arguments that should be split into an array, using ',' as the delimiter. |