From 36060cd42e146343b33c73f831eff561822a1c8b Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 4 Jun 2022 00:24:48 +1200 Subject: [PATCH] docs: add example example with code from README/documentation (#130) --- examples/simple-hard-coded.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/simple-hard-coded.js diff --git a/examples/simple-hard-coded.js b/examples/simple-hard-coded.js new file mode 100644 index 0000000..eff04c2 --- /dev/null +++ b/examples/simple-hard-coded.js @@ -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