@uvarovag/argv-parser
Version:
Node.js arguments parser with full support for TypeScript, CommonJS, and ES Modules
60 lines (43 loc) • 1.22 kB
Markdown


Lightweight and flexible arguments parser for Node.js with full support for TypeScript, CommonJS (CJS), and ES Modules (ESM).
## Installation
```bash
npm install @uvarovag/argv-parser
```
## Usage
### ES Modules (ESM)
```js
import { parseArgv } from '@uvarovag/argv-parser'
const args = parseArgv(process.argv)
console.log(args)
```
```js
const { parseArgv } = require('@uvarovag/argv-parser')
const args = parseArgv(process.argv)
console.log(args)
```
```bash
node ./test.js --positive=42 -negative=-10 --float=3.14 -true=true --false=false --text=hello --special=foo=bar --empty
```
```js
// test.js
import { parseArgv } from '@uvarovag/argv-parser'
const args = parseArgv(process.argv)
console.log(args)
{
node: '/opt/homebrew/Cellar/node/21.2.0/bin/node',
script: '/Users/uvarovag/Desktop/rect-app/test.js',
positive: 42,
negative: -10,
float: 3.14,
true: true,
false: false,
text: 'hello',
special: 'foo=bar',
empty: true,
}
```