mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

PR-URL: https://github.com/nodejs/node/pull/47862 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luke Karrys <luke@lukekarrys.com>
27 lines
540 B
JavaScript
27 lines
540 B
JavaScript
'use strict';
|
|
|
|
// This example is used in the documentation.
|
|
|
|
// 1. const { parseArgs } = require('node:util'); // from node
|
|
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
|
const { parseArgs } = require('..'); // in repo
|
|
|
|
const args = ['-f', '--bar', 'b'];
|
|
const options = {
|
|
foo: {
|
|
type: 'boolean',
|
|
short: 'f'
|
|
},
|
|
bar: {
|
|
type: 'string'
|
|
}
|
|
};
|
|
const {
|
|
values,
|
|
positionals
|
|
} = parseArgs({ args, options });
|
|
console.log(values, positionals);
|
|
|
|
// Try the following:
|
|
// node simple-hard-coded.js
|