Giter Club home page Giter Club logo

args's Introduction

@hypernym/args

A fast and ultra lightweight CLI argument parser.

Repository | Package | Releases | Discussions

npm i @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

args's People

Contributors

ivodolenc avatar

Stargazers

Anilson Lopes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.