acmdp
v1.0.2
Published
Command & Arguments Parser for Node.js
Maintainers
Readme
🛠 Command & Arguments Parser
A lightweight and flexible Node.js/TypeScript utility for parsing CLI commands and arguments into structured JavaScript objects.
🚀 Usage
1️⃣ Command Parser
Parses an entire CLI command string into its structured components.
📦 Installation
npm install acmdpExample
const input = `npx cross-env NODE_ENV=development ts-node --transpile-only -r ts-node/register -r tsconfig-paths/register ./src/Main.ts --item1=2`;
const result = new CommandParser(input).parse();Output
{
"command": "npx",
"execArgv": [
"cross-env",
"NODE_ENV=development",
"ts-node",
"--transpile-only",
"-r",
"ts-node/register",
"-r",
"tsconfig-paths/register"
],
"filename": "./src/Main.ts",
"filenameOption": [],
"argv": ["--item1", "2"]
}2️⃣ Arguments Parser
Parses a list of CLI arguments (string[]) into a JavaScript object.
Example — Multiple Values
const result = new ArgumentsParser([
"--tag",
"a",
"--tag",
"b",
"--tag",
"c",
]).parse();Output
{
"tag": ["a", "b", "c"]
}Example — Boolean & Primitive Values
const result = new ArgumentsParser(["--isAdmin", "true"]).parse();Output
{
"isAdmin": true
}3️⃣ ArgumentsParser.unparse()
Converts a parsed arguments object back into an array of CLI argument strings.
Example — Object to Arguments
const args = ArgumentsParser.unparse({
tag: ["a", "b", "c"],
isAdmin: true,
age: 30,
});Output
["--tag", "a", "--tag", "b", "--tag", "c", "--isAdmin", "--age", "30"]🧪 Testing
This project uses Mocha and Chai for testing.
Run all tests:
npm test