Wargs is a JavaScript utility designed for parsing command-line-like arguments from both strings and `argv`-style arrays, distinguishing itself from conventional argument parsers like `commander` or `yargs`. Unlike most alternatives, it leverages regular expressions internally, allowing it to process raw string inputs which traditional parsers typically do not support. It categorizes parsed arguments into `_` (positional arguments), `raw` (arguments after `--`), `data` (key=value pairs), `flags` (boolean flags like `--json` or `-x`), and `params` (key:value pairs). The current stable version is 0.10.0, however, the project appears to be abandoned with the last commit made in September 2020 and the latest npm publish being 5 years ago, indicating no ongoing development or maintenance. This tool is particularly suited for scenarios where arguments might come from varied sources beyond `process.argv` and require a flexible, regex-driven extraction approach.
npm install wargsVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing both string and array inputs, and accessing the different argument categories (`_`, `raw`, `data`, `flags`, `params`) along with options like `camelCase` and `format`.
Thoroughly review the documentation and examples to understand how `wargs` processes arguments and maps them to its distinct output properties.
Consider migrating to an actively maintained argument parsing library for new or critical projects. If usage is essential, be aware of potential unpatched vulnerabilities or incompatibilities with newer Node.js versions.
Create a `wargs.d.ts` file with appropriate type declarations (e.g., `declare module 'wargs' { function wargs(input: string | string[], options?: any): { _: string[]; raw: string[]; data: { [key: string]: string }; flags: { [key: string]: boolean }; params: { [key: string]: string } }; export default wargs; }`) or cast the return value to `any`.Use a default import: `import wargs from 'wargs';`
Use the direct `require()` assignment: `const wargs = require('wargs');`Refer to the `wargs` documentation carefully. `data` collects `key=value` pairs, while `params` collects `key:value` pairs. Adjust your input or access the correct output property accordingly.