
Product
Socket for Asana Is Now Available
Create and manage Asana tasks directly from Socket alerts, with manual task creation, automated ticketing rules, and two-way sync.
`argblock` is a lightweight and flexible JavaScript/TypeScript library for parsing command-line arguments. It supports long (`--flag`), short (`-f`), and negated (`--no-flag`) parameter formats, as well as nested command structures with custom argument ma
argblock is a lightweight and flexible JavaScript/TypeScript library for parsing command-line arguments. It supports long (--flag), short (-f), and negated (--no-flag) parameter formats, as well as nested command structures with custom argument matching.
Install the library via npm:
npm i argblock
Import the necessary components from the argblock package:
import { Param, Block, parse } from "argblock";
Create Parameters using the Param class:
const verboseParam = new Param({
name: "verbose",
type: "boolean",
short: "v",
defaultValue: "0",
});
Create Blocks using the Block class:
const mainBlock = new Block({
arg: "run",
params: [verboseParam],
description: "Run the application",
children: [],
});
Parse Arguments using the parse function:
const args = ["run", "--verbose", "1"];
const result = parse(args, [mainBlock]);
console.log(result);
Example output:
[
{
arg: "run",
params: { verbose: "1" },
},
];
--name value and --name=value formats.-f for single flags and -abc for multiple boolean flags.--no-name for boolean flags.matcher property.children in Block.The library consists of several internal modules:
block.ts: Defines the Block class and a default matcher for argument matching.
Block: Represents a command with an argument name, parameters, description, matcher, and child blocks.findParam(name) and findShortParam(name) to locate parameters by name or short form.param.ts: Defines the Param class for parameter configuration.
name, type, short, defaultValue.parse.ts: Contains the main parse function and global block logic.
import { Param, Block, parse } from "argblock";
const verboseParam = new Param({
name: "verbose",
type: "boolean",
short: "v",
defaultValue: "0",
});
const outputParam = new Param({
name: "output",
type: "string",
short: "o",
defaultValue: "./output",
});
const runBlock = new Block({
arg: "run",
params: [verboseParam, outputParam],
description: "Run the application",
children: [],
});
const args = ["run", "--verbose", "-o", "dist"];
const result = parse(args, [runBlock]);
console.log(result);
Output:
[
{
arg: "run",
params: {
verbose: "1",
output: "dist",
},
},
];
The parser throws errors in the following cases:
--unknown).parse.You can define custom matchers for blocks to handle complex argument patterns:
import { Block } from "argblock";
const customMatcher = (args, index) => {
if (args[index].startsWith("custom:")) {
return { jumpNext: 0, match: true };
}
return { jumpNext: 0, match: false };
};
const customBlock = new Block({
arg: "custom",
params: [],
description: "Custom command",
matcher: customMatcher,
children: [],
});
0, 1, true, or false.-abc) assume boolean type with a default value of 1 unless specified.FAQs
`argblock` is a lightweight and flexible JavaScript/TypeScript library for parsing command-line arguments. It supports long (`--flag`), short (`-f`), and negated (`--no-flag`) parameter formats, as well as nested command structures with custom argument ma
We found that argblock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Product
Create and manage Asana tasks directly from Socket alerts, with manual task creation, automated ticketing rules, and two-way sync.

Security News
Open VSX has removed three extension IDs from its malicious-extension list as the legitimate publishers they impersonated move to claim the names for themselves.

Product
Socket’s PHP and Composer support is now in Beta for all customers, with PHP reachability analysis generally available.