Skip to content

Commit 36060cd

Browse files
authored
docs: add example example with code from README/documentation (#130)
1 parent e43a70f commit 36060cd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/simple-hard-coded.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
// This example is used in the documentation.
4+
5+
// 1. const { parseArgs } = require('node:util'); // from node
6+
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
7+
const { parseArgs } = require('..'); // in repo
8+
9+
const args = ['-f', '--bar', 'b'];
10+
const options = {
11+
foo: {
12+
type: 'boolean',
13+
short: 'f'
14+
},
15+
bar: {
16+
type: 'string'
17+
}
18+
};
19+
const {
20+
values,
21+
positionals
22+
} = parseArgs({ args, options });
23+
console.log(values, positionals);
24+
25+
// Try the following:
26+
// node simple-hard-coded.js

0 commit comments

Comments
 (0)