1.0.4 • Published 4 years ago

clipop v1.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

clipop

Utility to parse terminal input into a JSON object

my-app --name "john doe" --is-admin

Options will be parsed like this:

{
  "name": "john doe",
  "is-admin": true
}

You can also use notations:

my-app --names.firstname joe --hobbies[0].name hockey 
{
  "names": {
    "firstname": "jo"
  },
  "hobbies": [
    {
      "name": "hockey"
    }
  ]
}

This utility only returns options and other arguments are ignored:

my-app connect --uri localhost --ssl 
{
  "uri": "localhost",
  "ssl": true
}

Usage

npm install clipop
import clipop from 'clipop'

const [,, ...params] = process.argv

const options = clipop(...params) // clipop accepts a spread array of strings

Value declarations

--foo     hello       # "hello"
--foo     22          # "22"
--foo     true        # "true"
--foo     false       # "false"
--foo     null        # "null"
--foo                 # true
--foo     ---22       # 22
--foo     ---true     # true
--foo     ---false    # false
--foo     ---null     # null

Typescript suppor

clipop<{ name: string }>(...params) // my-app --name joe