0.12.1 • Published 3 years ago

@hugoalh/command-line-parser v0.12.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Command Line Parser (NodeJS Edition)

CommandLineParser.NodeJS - A NodeJS module to parse command line with better standard.

GitHub Contributors GitHub Issues GitHub Pull Requests GitHub Discussions GitHub Stars GitHub Forks GitHub Languages CodeFactor Grade LGTM Alerts LGTM Grade License

ReleaseLatestPre
GitHub GitHub Total DownloadsGitHub Latest Release Version (GitHub Latest Release Date)GitHub Latest Pre-Release Version (GitHub Latest Pre-Release Date)
NPM NPM Total DownloadsNPM Latest Release VersionNPM Latest Pre-Release Version

📝 Description

For Deno edition, please visit here.

🌟 Feature

  • Easier to remember which is flag and which is option (i.e.: key-value pair).
  • Native support for CommonJS and ECMAScript.

📚 Documentation

Getting Started

NodeJS (>= v14.15.0) & NPM (>= v6.14.8):

npm install @hugoalh/command-line-parser

API

(commandLine?)

Description

Parse command line.

Argument

commandLine?

<string[] = process.argv.slice(2)> Command line that need to parse.

Return

<object> Parse result.

  • action: <string[]>
  • fault: <string[]> Unparseable argument.
  • flag: <string[]> Flag.
  • option: <object> Key-value pair.

Example

const commandLineParser = require("@hugoalh/command-line-parser");

console.log(commandLineParser(["-test", "--message=\"Hello, world!\"", "lol", "---fail"]));
/*
{
  action: [
    "lol"
  ],
  fault: [
    "---fail"
  ],
  flag: [
    "test"
  ],
  option: {
    message: "Hello, world!"
  }
}
*/