Socket
Socket
Sign inDemoInstall

subarg

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subarg

parse arguments with recursive contexts


Version published
Weekly downloads
1.4M
decreased by-1.32%
Maintainers
1
Weekly downloads
 
Created

What is subarg?

The 'subarg' npm package allows you to parse command-line arguments with nested sub-arguments. This is particularly useful for complex command-line interfaces where arguments can have their own sub-arguments.

What are subarg's main functionalities?

Basic Parsing

This feature allows you to parse command-line arguments into a structured object. The `process.argv.slice(2)` part skips the first two default arguments (node and script path).

const subarg = require('subarg');
const argv = subarg(process.argv.slice(2));
console.log(argv);

Nested Arguments

This feature allows you to parse nested sub-arguments. For example, `--foo [--bar baz]` will be parsed into an object where `foo` is an array containing an object with `bar` set to `baz`.

const subarg = require('subarg');
const argv = subarg(process.argv.slice(2));
console.log(argv);
// Example: node script.js --foo [--bar baz]

Default Values

This feature allows you to set default values for arguments. If an argument is not provided, it will take the default value specified.

const subarg = require('subarg');
const argv = subarg(process.argv.slice(2), { default: { foo: 'default' } });
console.log(argv);
// Example: node script.js

Other packages similar to subarg

Keywords

FAQs

Package last updated on 03 Oct 2014

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