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

argument-parser-extended

v0.5.1

Published

Sophisticated argument parser that can handle advanced command line structures and validation

Downloads

5

Readme

argument-parser-extended

NPM

Build Status Dependencies Coverage Status npm version

Requirements & Installation

Just run npm install argument-parser-extended

Documentation

ArgumentParser(name, options)

  • name - Name of the program
  • options - Options to be used for validation, see below.

All keys in options are automatically converted from lower camel-case to kebab-case.

{
	flagName: {
		enum: ['list', 'of', 'values', 'accepted'], //conflicts with all other validation parameters.
		type: 'boolean|number|string|array|integer|file'//defaults to boolean, if array all validators will be applied to each element.
		default: 'myDefaultValueIfSwitchIsNotSet',
		required: true|false, //will error if a set to true and a default exists
		min: minValue, //only works for integer and number
		max: maxValue, //see above
		regex: /some regex/, //only works for type string, will cause the parser to throw an error if the passed string does not match
		subType: 'boolean|number|string|integer|file', //The type to be validated if type is an array,
		file: { //only works when type = file
			json: true|false, //is the content json?
			stream: true|false, //return a stream rather than reading the whole file,
			encoding: string, //default is utf8
		},
		short: sting, //must be length of 1, the short flag to alias the flag with
		validator: function //will be called with the preprocessed value parsed from the flag, this function can override the return value by simply returning != undefined, otherwise it should just throw an error.
	}
}

Object ArgumentParser.parse(str)

Parses the given string and returns a object representing the parsed data, throws if anything failed.

All "additional" data that was not associated with a flag will be available in the append field.

Object ArgumentParser.run()

Parses the command line directly, otherwise behaves just like parse.

string ArgumentParser.getHelpString()

Returns nicely formatted usage info.

Usage examples

var ArgumentParser = require('argument-parser-extended');

var argParser = new ArgumentParser('example', {
	myParam: {
		type: 'string',
		default: 'nothing'
	},
	myConfig: {
		type: 'file',
		file: {
			json: true
		}
	}
});

try {
	var conf = argParser.run();
	console.log(conf.myParam, conf.myConfig);
} catch(e) {
	console.error(argParser.getHelpText());
}
node filename.js --my-param hello --my-config path/to/json.json