Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

argufy

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argufy

Parse command line arguments to Node.js CLI programs.

  • 1.3.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

argufy

npm version

yarn add -E argufy

argufy will parse command line arguments to Node.js CLI programs.

API

The package is available by importing its default function:

import argufy from 'argufy'

The package assumes that the arguments begin from the 3rd position, i.e.,

node example.js --title "Hello World"

argufy(
  config: <string, ConfigItem>,
  argv?: string[],
): object

The flags from the arguments will be extracted according to the configuration object and the arguments array. If arguments array is not passed, process.argv is used to find arguments.

import argufy from 'argufy'

const config = {
  title: { short: 't', command: true },
  list: { short: 'l', boolean: true },
  app: 'a',
  delay: 'y',
  file: 'f',
  wait: { short: 'w', number: true },
  'no-empty': 'e',
  resize: 'z',
  colors: 'c',
  dir: 'D',
}

const res = argufy(config, process.argv)
console.log(JSON.stringify(res, null, 2))
node example.js --title "Hello World" -w 10 -l -app Argufy
# or
node example.js HelloWorld -w 10 -l -app Argufy
{
  "_argv": [],
  "title": "HelloWorld",
  "list": true,
  "app": "Argufy",
  "wait": 10
}

The special _argv property will be assigned to contain all unmatched arguments. For example, it can be used to pass any additional parameters through to other program.

ConfigItem Type

The configuration for each flag can either be a shorthand string, or an object. If it is an object, it can include the following parameters:

Flag: The flag passed to the program.

NameTypeDescriptionDefault
shortstringShorthand for this argument, usually one letter.-
booleanbooleanWhether the flag is a boolean and does not require a value.false
numberbooleanSpecifies whether the flag should be parsed as a number.false
commandbooleanIf set to true, the value is read from the first argument passed to the CLI command (e.g., $ cli command).false
multiplebooleanWhen using the command property, will parse the commands as an array.false

(c) Art Deco 2019

Keywords

FAQs

Package last updated on 05 Apr 2019

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