Gathering detailed insights and metrics for yargs
Gathering detailed insights and metrics for yargs
Gathering detailed insights and metrics for yargs
Gathering detailed insights and metrics for yargs
yargs the modern, pirate-themed successor to optimist.
npm install yargs
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
11,117 Stars
1,822 Commits
991 Forks
82 Watching
87 Branches
269 Contributors
Updated on 28 Nov 2024
JavaScript (70.91%)
TypeScript (28.85%)
HTML (0.25%)
Cumulative downloads
Total Downloads
Last day
-8.2%
19,219,988
Compared to previous day
Last week
1.4%
113,714,933
Compared to previous week
Last month
15%
461,992,912
Compared to previous month
Last year
6.7%
4,654,359,789
Compared to previous year
Yargs be a node.js library fer hearties tryin' ter parse optstrings
Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface.
It gives you:
my-program.js serve --port=5000
).mocha [spec..]
Run tests with Mocha
Commands
mocha inspect [spec..] Run tests with Mocha [default]
mocha init <path> create a client-side Mocha setup at <path>
Rules & Behavior
--allow-uncaught Allow uncaught errors to propagate [boolean]
--async-only, -A Require all tests to use a callback (async) or
return a Promise [boolean]
Stable version:
1npm i yargs
Bleeding edge version with the most recent features:
1npm i yargs@next
1#!/usr/bin/env node 2const yargs = require('yargs/yargs') 3const { hideBin } = require('yargs/helpers') 4const argv = yargs(hideBin(process.argv)).parse() 5 6if (argv.ships > 3 && argv.distance < 53.5) { 7 console.log('Plunder more riffiwobbles!') 8} else { 9 console.log('Retreat from the xupptumblers!') 10}
1$ ./plunder.js --ships=4 --distance=22 2Plunder more riffiwobbles! 3 4$ ./plunder.js --ships 12 --distance 98.7 5Retreat from the xupptumblers!
Note:
hideBin
is a shorthand forprocess.argv.slice(2)
. It has the benefit that it takes into account variations in some environments, e.g., Electron.
1#!/usr/bin/env node 2const yargs = require('yargs/yargs') 3const { hideBin } = require('yargs/helpers') 4 5yargs(hideBin(process.argv)) 6 .command('serve [port]', 'start the server', (yargs) => { 7 return yargs 8 .positional('port', { 9 describe: 'port to bind on', 10 default: 5000 11 }) 12 }, (argv) => { 13 if (argv.verbose) console.info(`start server on :${argv.port}`) 14 serve(argv.port) 15 }) 16 .option('verbose', { 17 alias: 'v', 18 type: 'boolean', 19 description: 'Run with verbose logging' 20 }) 21 .parse()
Run the example above with --help
to see the help for the application.
yargs has type definitions at @types/yargs.
npm i @types/yargs --save-dev
See usage examples in docs.
As of v16
, yargs
supports Deno:
1import yargs from 'https://deno.land/x/yargs/deno.ts' 2import { Arguments } from 'https://deno.land/x/yargs/deno-types.ts' 3 4yargs(Deno.args) 5 .command('download <files...>', 'download a list of files', (yargs: any) => { 6 return yargs.positional('files', { 7 describe: 'a list of files to do something with' 8 }) 9 }, (argv: Arguments) => { 10 console.info(argv) 11 }) 12 .strictCommands() 13 .demandCommand(1) 14 .parse()
As of v16
,yargs
supports ESM imports:
1import yargs from 'yargs' 2import { hideBin } from 'yargs/helpers' 3 4yargs(hideBin(process.argv)) 5 .command('curl <url>', 'fetch the contents of the URL', () => {}, (argv) => { 6 console.info(argv) 7 }) 8 .demandCommand(1) 9 .parse()
See examples of using yargs in the browser in docs.
Having problems? want to contribute? join our community slack.
Libraries in this ecosystem make a best effort to track Node.js' release schedule. Here's a post on why we think this is important.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
0 commit(s) and 21 issue activity found in the last 90 days -- score normalized to 10
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 19/23 approved changesets -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More