https://github.com/jesusgraterol/argv-utils
The argv-utils package is a lightweight library for Node.js that simplifies working with command-line arguments passed to your scripts. It streamlines the process of accessing and managing arguments from process.argv property.
https://github.com/jesusgraterol/argv-utils
args arguments argv argvs node parser sh shell shell-script utilities utils
Last synced: 5 months ago
JSON representation
The argv-utils package is a lightweight library for Node.js that simplifies working with command-line arguments passed to your scripts. It streamlines the process of accessing and managing arguments from process.argv property.
- Host: GitHub
- URL: https://github.com/jesusgraterol/argv-utils
- Owner: jesusgraterol
- License: mit
- Created: 2024-05-04T13:42:56.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-03T14:58:22.000Z (6 months ago)
- Last Synced: 2024-12-14T15:38:27.163Z (5 months ago)
- Topics: args, arguments, argv, argvs, node, parser, sh, shell, shell-script, utilities, utils
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/argv-utils
- Size: 262 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# argv Utils
The `argv-utils` package is a lightweight library for Node.js that simplifies working with command-line arguments passed to your scripts. It streamlines the process of accessing and managing arguments from `process.argv` property.
## Getting Started
Install the package:
```bash
npm install -D argv-utils
```### Examples
Extract the arguments passed to the `my-file.js` script:
```bash
node my-file.js --one --two="Hello World!" --someValue="false"
```
```typescript
// my-file.js
import { argv } from 'node:process';
import { parseArgs } from 'argv-utils';parseArgs(argv);
// {
// execPath: '/usr/local/bin/node',
// scriptPath: '/path/to/my-script.js',
// one: 'true',
// two: 'Hello World!',
// someValue: 'false',
// }
```
## Types
```typescript
/**
* Base Parsed Args
* The args that will always be present when a Node.js process is launched; taking the indexes 0 and 1 in the vector.
*/
interface IBaseParsedArgs {
// the absolute pathname of the executable that started the Node.js process
execPath: string,// the path to the JavaScript file being executed
scriptPath: string,
}/**
* Parsed Args
* The arguments provided by the process.argv property when running a script from the shell.
*/
interface IParsedArgs extends IBaseParsedArgs {
// the rest of the extracted arguments
[argKey: string]: string
}
```If you wish to enforce strong typing in your script, extend the base type as follows:
```typescript
interface IMyScriptArgs extends IBaseParsedArgs {
src?: string,
init?: 'true',
development?: 'true',
staging?: 'true',
production?: 'true',
}
```
## Built With
- TypeScript
## Running the Tests
```bash
npm run test:unit
```
## License
[MIT](https://choosealicense.com/licenses/mit/)
## Deployment
Install dependencies:
```bash
npm install
```Build the library:
```bash
npm start
```Publish to `npm`:
```bash
npm publish
```