argumenty
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Argumenty

Argumenty makes command line argument parsing in Node / Typescript easy.

How to use Argumenty

Basic setup

import { Argumenty } from "argumenty";

const argumenty = new Argumenty({ short: "s", long: "stuff", type: "string" }); // Arguments can be added through the constructor
// They can also be added after the fact.
argumenty.add({ short: "t", long: "thing", type: "flag" });

// Then just parse
argumenty.parse();
// And now we can get parsed things!
console.log(argumenty.get("stuff"), argumenty.get("thing"));

Transformers

Transformers allow the changing of an argument's value.

If you wanted to get the contents of a file instead of storing a file name, you could do so like this:

import { Argumenty, ParsedArgument } from "argumenty";

const fs = require("fs");

function getFileContents(arg: ParsedArgument): any {
	// Check if the file exists
	if (!fs.existsSync(arg.value)) {
		return null;
	}
	// Since it does, read the contents
	return fs.readFileSync(arg.value).toString();
}

const argumenty = new Argumenty();
argumenty.add({ short: "f", long: "file", type: "string", transformer: getFileContents });

argumenty.parse();
// This will have the contents of the file
console.log(argumenty.get("file"));

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    1
  • 0.0.1
    1

Package Sidebar

Install

npm i argumenty

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • innectic