
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
flags-args-readline
Advanced tools
Command line arguments reader from specified flags, with readline prompt when value is not specified.
Command line arguments reader from specified flags, with readline prompt when value is not specified.
// Initialise from all function objects
const FlagArgs = require('flags-args-readline');
const args = FlagArgs.readArgs(['-f', '--file', '-t', '--target']);
// Initialise from only `readArgs` object
const { readArgs } = require('flags-args-readline');
const args = readArgs(['-f', '--file', '-t', '--target']);
has(params: string[]|string): boolReturn true if there is value of that given name.
Examples
/* COMMAND LINE:
node test.js --target ./data.txt -a
*/
const args = readArgs(['-t', '--target', '-a']);
args.has('-t'); // false
args.has('--target'); // true
args.has(['-t', '--target']); // true
args.has('-a'); // false
get(params: string[]|string): stringReturn value of specified argument name.
Examples
/* COMMAND LINE:
node test.js --source ./data.txt -t ./out.txt
*/
const args = readArgs(
['-s', '--source', '-t', '--target']
);
args.get(['-s', '--source']); // "./data.txt"
args.get(['-t', '--target']); // "./out.txt"
args.get('-t'); // "./out.txt"
args.get('--target'); // undefined
getOrReadline(params: string[]|string): stringIf there is value given in command line, return the value. Otherwise, show interactive line reader and read line from user's input, then return the value.
Examples
/* COMMAND LINE:
node test.js -s ./data.txt
*/
const args = readArgs(
['-s', '--source', '-t', '--target']
);
temp = args.getOrReadline(['-s', '--source'], 'Where is source file?: ');
// ↑ "./data.txt"
temp = args.getOrReadline(['-t', '--target'], 'Where is target file?: ');
// ↑ Pause program, print "Where is target file?: " and then wait for user to input a line. After user has submit, read the line and return the value.
args.has(['-t', '--target']); // false
// ↑ using `getOrReadline` will not change aruments records in `args`, the value from readline is one-time use.
Examples
/* COMMAND LINE:
node test.js -t ./out.txt
*/
const args = readArgs(
['-t', '--target', '-s', '--source']
);
args.args['-t']; // "./out.txt"
args.args['--target']; // undefined
args.args['-s']; // undefined
args.args['--source']; // undefined
// Initialise from all function objects
const FlagArgs = require('flags-args-readline');
const args = FlagArgs.readFlags(['-a', '--all']);
// Initialise from only `readFlags` object
const { readFlags } = require('flags-args-readline');
const args = readFlags(['-a', '--all']);
has(string[]|string): boolReturn true if there is specified flag given from command line arguments. The logical operator, in case of array, is OR.
Examples
/* COMMAND LINE:
node test.js -a
*/
const flags = readFlags(['-a', '--all']);
flags.has(['-a', '--all']); // true
flags.has('-a'); // true
flags.has('--all'); // false
flags.has('-t'); // false
Examples
/* COMMAND LINE:
node test.js -a -u -t
*/
const flags = readFlags(['-a', '-u', '-s']);
flags.flags; // ['-a', '-u']
npm commandReminding that arguments passed from npm commands, such as npm start or npm run, those arguments belong to npm, not the node file. For this reason, to use the library with npm, the arguments should be passed after -- symbol.
Examples
const args = parseArgs(['-s', '-t']);
args.get('-s');
// From `npm run my-command -s something` → undefined
// From `node run my-command -- -s something` → "something"
FAQs
Command line arguments reader from specified flags, with readline prompt when value is not specified.
The npm package flags-args-readline receives a total of 1 weekly downloads. As such, flags-args-readline popularity was classified as not popular.
We found that flags-args-readline 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.