UNPKG

@uvarovag/argv-parser

Version:

Node.js arguments parser with full support for TypeScript, CommonJS, and ES Modules

60 lines (43 loc) 1.22 kB
# Node.js Arguments Parser ![Bundle Size](https://img.shields.io/bundlephobia/minzip/@uvarovag/argv-parser) ![Tests](https://github.com/uvarovag/argv-parser/actions/workflows/publish.yml/badge.svg) 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) ``` ### CommonJS (CJS) ```js const { parseArgv } = require('@uvarovag/argv-parser') const args = parseArgv(process.argv) console.log(args) ``` ## Examples ```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, } ```