yargs-parser
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
camelcase | 5.3.1 | 2.96 kB | MIT | prod | |
decamelize | 1.2.0 | 1.65 kB | MIT | prod |
Yargs-parser is a mighty command-line option parser used by Yargs. It provides functionality to parse command line arguments, returning a simple mapping of keys and values. This makes it a trusted tool for developers who require to work with command line arguments.
To use yargs-parser, you start by installing it into your project using npm:
npm i yargs-parser --save
Then, in your JavaScript file, you can require it and use it to parse command line arguments like so:
const argv = require('yargs-parser')(process.argv.slice(2));
console.log(argv);
The above code will log the parsed arguments to the console.
Additionally, you can also parse a string with yargs-parser:
const argv = require('yargs-parser')('--foo=99 --bar=33');
console.log(argv);
Moreover, yargs-parser can also convert an array of mixed types before passing it for parsing:
const parse = require('yargs-parser');
parse(['-f', 11, '--zoom', 55].join(' ')); // <-- array to string
parse(['-f', 11, '--zoom', 55].map(String)); // <-- array of strings
In a modern JavaScript environment, you can use the import syntax to import yargs-parser:
import parser from 'yargs-parser';
const argv = parser('--foo=99 --bar=9987930', {
string: ['bar']
});
console.log(argv);
This also works in a web browser:
<!doctype html>
<body>
<script type="module">
import parser from "https://unpkg.com/yargs-parser@19.0.0/browser.js";
const argv = parser('--foo=99 --bar=9987930', {
string: ['bar']
});
console.log(argv);
</script>
</body>
The comprehensive documentation for yargs-parser can be found directly on the repository's README file on GitHub. It includes detailed usage instructions, examples, and API references to help get the most out of yargs-parser. Additionally, you can also visit the yargs website for more examples and information.