diff --git a/docs/modules/parseargs.md b/docs/modules/parseargs.md new file mode 100644 index 0000000..1e90070 --- /dev/null +++ b/docs/modules/parseargs.md @@ -0,0 +1,45 @@ +--- +description: Modern alternatives to CLI argument parsing packages using Node.js built-in util.parseArgs +--- + +# Replacements for argument parsers + +## `util.parseArgs` (native, since Node.js 16.x) + +[`util.parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig) is built into Node.js (since 18.3.0 and 16.17.0) and can replace many common CLI options parsing libraries. + +Example: + +```ts +import { parseArgs } from 'node:util' + +const { values, positionals } = parseArgs({ + args: process.argv.slice(2), + options: { + force: { type: 'boolean', short: 'f' }, + output: { type: 'string', short: 'o' } + }, + allowPositionals: true +}) +``` + +> [!NOTE] +> `parseArgs` only supports `string` and `boolean` types. If you'd like to support stronger types, one of the other options may be a better fit. + +## `mri` + +[`mri`](https://github.com/lukeed/mri) is a minimalistic argument parser that supports both short and long options, as well as positional arguments. + +Example: + +```ts +import mri from 'mri' + +const options = mri(process.argv.slice(2), { + alias: { + f: 'force', + o: 'output' + }, + boolean: ['force'] +}) +``` diff --git a/manifests/preferred.json b/manifests/preferred.json index 5aaaee3..8d5c15e 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -36,6 +36,12 @@ "replacements": ["fetch", "ofetch", "ky"], "url": {"type": "e18e", "id": "fetch"} }, + "arg": { + "type": "module", + "moduleName": "arg", + "replacements": ["util.parseArgs", "mri"], + "url": {"type": "e18e", "id": "parseargs"} + }, "axios": { "type": "module", "moduleName": "axios", @@ -2418,6 +2424,12 @@ "replacements": ["node:crypto"], "url": {"type": "e18e", "id": "md5"} }, + "minimist": { + "type": "module", + "moduleName": "minimist", + "replacements": ["util.parseArgs", "mri"], + "url": {"type": "e18e", "id": "parseargs"} + }, "mkdirp": { "type": "module", "moduleName": "mkdirp", @@ -2767,6 +2779,12 @@ "moduleName": "xmldom", "replacements": ["@xmldom/xmldom"], "url": {"type": "e18e", "id": "xmldom"} + }, + "yargs-parser": { + "type": "module", + "moduleName": "yargs-parser", + "replacements": ["util.parseArgs", "mri"], + "url": {"type": "e18e", "id": "parseargs"} } }, "replacements": { @@ -3212,6 +3230,11 @@ "type": "documented", "replacementModule": "milliparsec" }, + "mri": { + "id": "mri", + "type": "documented", + "replacementModule": "mri" + }, "nano-staged": { "id": "nano-staged", "type": "documented", @@ -3461,6 +3484,12 @@ "id": "api/util.html#utilisdeepstrictequalval1-val2-options" } }, + "util.parseArgs": { + "id": "util.parseArgs", + "type": "native", + "nodeFeatureId": {"moduleName": "node:util", "exportName": "parseArgs"}, + "url": {"type": "node", "id": "api/util.html#utilparseargsconfig"} + }, "util.stripVTControlCharacters": { "id": "util.stripVTControlCharacters", "type": "native",