New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

argv-utils

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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:

npm install -D argv-utils

Usage

node my-script.js --one --two="Hello World!" --someValue="false"
// my-script.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

/**
 * 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:

interface IMyScriptArgs extends IBaseParsedArgs {
  src?: string,
  init?: 'true',
  development?: 'true',
  staging?: 'true',
  production?: 'true',
}

Built With

  • TypeScript

Running the Tests

npm run test:unit

License

MIT


Deployment

Install dependencies:

npm install

Build the library:

npm start

Publish to npm:

npm publish

Keywords

FAQs

Package last updated on 03 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc