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
Typescript
Module System
Min. Node Version
Node Version
NPM Version
96.4
Supply Chain
99.6
Quality
77.9
Maintenance
100
Vulnerability
100
License
JavaScript (70.91%)
TypeScript (28.85%)
HTML (0.25%)
Total Downloads
21,408,553,226
Last Day
17,781,540
Last Week
80,506,962
Last Month
363,361,891
Last Year
4,688,804,142
11,161 Stars
1,826 Commits
993 Forks
81 Watching
87 Branches
271 Contributors
Minified
Minified + Gzipped
Latest Version
17.7.2
Package Id
yargs@17.7.2
Unpacked Size
285.57 kB
Size
64.15 kB
File Count
62
NPM Version
9.6.5
Node Version
14.21.3
Publised On
27 Apr 2023
Cumulative downloads
Total Downloads
Last day
-3.9%
17,781,540
Compared to previous day
Last week
-15%
80,506,962
Compared to previous week
Last month
3.5%
363,361,891
Compared to previous month
Last year
5.8%
4,688,804,142
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)).argv 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
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
4 commit(s) and 6 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 20/25 approved changesets -- score normalized to 8
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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 2025-01-27
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