{"library":"nopt","title":"Node.js Option Parser (nopt)","description":"This library provides a robust and flexible option parsing solution for Node.js command-line interfaces. It is famously used by npm itself to handle its complex array of command-line arguments and configuration. `nopt` supports defining various option types (String, Number, Boolean, path, url, Date, Stream), shorthands for brevity, and mechanisms for handling unknown options. It maintains a consistent release cadence, with major versions frequently aligning with Node.js LTS cycles. The current stable version, `9.0.0`, requires Node `^20.17.0 || >=22.9.0`. Its key differentiators include strong type definition capabilities, automatic path resolution, and a battle-tested core proven by its integration into the npm CLI.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install nopt"],"cli":null},"imports":["import nopt from 'nopt'","const nopt = require('nopt')","import nopt from 'nopt'; const types = nopt.typeDefs;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const nopt = require('nopt');\nconst Stream = require('stream').Stream;\nconst path = require('path');\n\nconst knownOpts = {\n  \"foo\": [String, null],\n  \"bar\": [Stream, Number],\n  \"baz\": path,\n  \"bloo\": [\"big\", \"medium\", \"small\"],\n  \"flag\": Boolean,\n  \"pick\": Boolean,\n  \"many1\": [String, Array],\n  \"many2\": [path, Array]\n};\n\nconst shortHands = {\n  \"foofoo\": [\"--foo\", \"Mr. Foo\"],\n  \"b7\": [\"--bar\", \"7\"],\n  \"m\": [\"--bloo\", \"medium\"],\n  \"p\": [\"--pick\"],\n  \"f\": [\"--flag\"]\n};\n\n// nopt takes known options, shorthands, the argument list (defaults to process.argv),\n// and a slice index (defaults to 2 for process.argv).\nconst parsed = nopt(knownOpts, shortHands, process.argv, 2);\n\nconsole.log('Parsed Options:', parsed);\nconsole.log('Remaining Arguments:', parsed.argv.remain);\n\n// Example usage:\n// node your-script.js --foo \"blerp\" --no-flag\n// node your-script.js --blatzk=1000 -fp","lang":"javascript","description":"Demonstrates basic option parsing using `nopt`, defining known options with types and shorthands, and processing `process.argv` to extract command-line arguments into a structured object.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}