clipop
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i clipop

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

13.9 kB

Total Files

26

Last publish

Collaborators

  • franleweb