-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add example example with code from README/documentation (#130)
- Loading branch information
1 parent
e43a70f
commit 36060cd
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'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 |