Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@types/command-line-args
Advanced tools
@types/command-line-args provides TypeScript type definitions for the command-line-args package, which is used to parse command-line arguments in Node.js applications.
Define Command Line Options
This feature allows you to define the command-line options your application will accept. In this example, 'file' is a string option and 'verbose' is a boolean option.
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'file', type: String },
{ name: 'verbose', type: Boolean }
];
const options = commandLineArgs(optionDefinitions);
console.log(options);
Default Option Values
You can set default values for options. In this example, if 'file' or 'verbose' are not provided, they will default to 'default.txt' and 'false' respectively.
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'file', type: String, defaultValue: 'default.txt' },
{ name: 'verbose', type: Boolean, defaultValue: false }
];
const options = commandLineArgs(optionDefinitions);
console.log(options);
Multiple Option Values
This feature allows you to accept multiple values for a single option. In this example, 'files' can accept multiple string values.
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'files', type: String, multiple: true }
];
const options = commandLineArgs(optionDefinitions);
console.log(options);
Yargs is a popular library for parsing command-line arguments in Node.js. It provides a rich set of features including command handling, argument validation, and more. Compared to command-line-args, yargs offers more advanced features but can be more complex to use.
Commander is another widely-used library for command-line argument parsing in Node.js. It is known for its simplicity and ease of use. While it may not offer as many features as yargs, it is more straightforward and easier to get started with compared to command-line-args.
Minimist is a lightweight library for parsing command-line arguments. It is very simple and fast, making it suitable for smaller projects or scripts. However, it lacks some of the advanced features found in command-line-args and other more comprehensive libraries.
npm install --save @types/command-line-args
This package contains type definitions for command-line-args (https://github.com/75lb/command-line-args).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/command-line-args/v4.
/**
* Returns an object containing option values parsed from the command line. By default it parses the global `process.argv` array.
*/
declare function commandLineArgs(
optionDefinitions: commandLineArgs.OptionDefinition[],
options?: commandLineArgs.ParseOptions,
): commandLineArgs.CommandLineOptions;
declare namespace commandLineArgs {
interface CommandLineOptions {
/**
* Command-line arguments not parsed by `commandLineArgs`.
*/
_unknown?: string[] | undefined;
[propName: string]: any;
}
interface ParseOptions {
/**
* An array of strings which if present will be parsed instead of `process.argv`.
*/
argv?: string[] | undefined;
/**
* If `true`, `commandLineArgs` will not throw on unknown options or values, instead returning them in the `_unknown` property of the output.
*/
partial?: boolean | undefined;
}
interface OptionDefinition {
/**
* The long option name.
*/
name: string;
/**
* A setter function (you receive the output from this) enabling you to be specific about the type and value received. Typical values
* are `String` (the default), `Number` and `Boolean` but you can use a custom function. If no option value was set you will receive `null`.
*/
type?: ((input: string) => any) | undefined;
/**
* A getopt-style short option name. Can be any single character except a digit or hyphen.
*/
alias?: string | undefined;
/**
* Set this flag if the option accepts multiple values. In the output, you will receive an array of values each passed through the `type` function.
*/
multiple?: boolean | undefined;
/**
* Any values unaccounted for by an option definition will be set on the `defaultOption`. This flag is typically set
* on the most commonly-used option to enable more concise usage.
*/
defaultOption?: boolean | undefined;
/**
* An initial value for the option.
*/
defaultValue?: any;
/**
* One or more group names the option belongs to.
*/
group?: string | string[] | undefined;
}
}
export = commandLineArgs;
These definitions were written by CzBuCHi, and Lloyd Brookes.
FAQs
TypeScript definitions for command-line-args
The npm package @types/command-line-args receives a total of 409,808 weekly downloads. As such, @types/command-line-args popularity was classified as popular.
We found that @types/command-line-args 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.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.