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

@hypernym/args

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hypernym/args

A fast and ultra lightweight CLI argument parser.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

@hypernym/args

A fast and ultra lightweight CLI argument parser.

Repository | Package | Releases | Discussions

npm i -D @hypernym/args

Features

  • TypeScript friendly
  • Fully tree-shakeable
  • No dependencies

Parser

Arguments

Unprefixed inputs are stored in an array.

$ arg

# => { _: ['arg'] }
$ arg-a arg-b arg-c

# => { _: ['arg-a', 'arg-b', 'arg-c'] }

Flags

Inputs with -- prefix are parsed as flags.

By default, standalone flags with no value are defined as true.

$ --flag

# => { _: [], flag: true, }
$ --flag value

# => { _: [], flag: 'value', }

Aliases

Inputs with - prefix are parsed as aliases.

By default, standalone aliases with no value are defined as true.

$ -alias

# => { _: [], alias: true, }
$ -alias value

# => { _: [], alias: 'value', }

Ignores

  • Ignores standalone inputs -- and -
  • Ignores all inputs that include =
$ --flag=value -- arg=value - -alias=value

# => { _: [] }

Usage

$ hello world --foo bar -baz -cli demo --fuz
import { createArgs } from '@hypernym/args'

interface Args {
  foo?: string
  baz?: boolean
  cli?: string
  fuz?: boolean
}

const args = createArgs<Args>()

console.log(args)

/* Output:
{
  _: ['hello', 'world'],
  foo: 'bar',
  baz: true,
  cli: 'demo',
  fuz: true
}
*/

Options

argv

  • Type: string[]
  • Default: process.argv.slice(2)
const args = createArgs({
  argv: process.argv.slice(2),
})

alias

  • Type: object
  • Default: undefined
const args = createArgs({
  alias: {
    config: ['conf', 'c'],
    help: 'h',
  },
})

Community

Feel free to use the official discussions for any additional questions.

License

Developed in 🇭🇷 Croatia

Released under the MIT license.

© Hypernym Studio

Keywords

FAQs

Package last updated on 26 Sep 2023

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