Socket
Socket
Sign inDemoInstall

argville

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    argville

Parse cli args.


Version published
Weekly downloads
2
decreased by-75%
Maintainers
1
Install size
141 kB
Created
Weekly downloads
 

Changelog

Source

0.0.3

Patch Changes

  • Update documentation

Readme

Source

TypeScript NPM Build Status Test Coverage

Argville

Another CLI arg parser.

// index.js
const { parseAndValidate } = require('argville')

const flags = {
  pm: {
    type: 'string',
    required: true,
    map: (arg) => {
      return (arg as string).toLowerCase()
    },
  },

  name: {
    type: 'string',
    default: 'John',
    expected: /^John$/
  },

  age: {
    type: 'number',
    alias: 'a',
    validator: (age) => {
      if(age < 0) {
        return [false, "Error. Age must be > 0"]
      } else {
        return [true]
      }
    }
  },

  toppings: {
    type: 'string',
    alias: 't',
    multiple: true,
    expected: ["sprinkles", "candy"]
  },

  repeat: {
    alias: 'r',
    count: true,
  },

  verbose: {
    type: 'boolean',
    default: false,
  },
}

const args = parseAndValidate({ flags }, process.argv.slice(2))
node index.js cmd --pm PNPM -a 100 -t sprinkles candy -rrr --verbose
# args:
# {
#   _: ['cmd'],
#   pm: 'pnpm',
#   age: 100,
#   toppings: ['sprinkles', 'candy'],
#   repeat: 3,
#   verbose: true,
#   name: 'John',
# }

Keywords

FAQs

Last updated on 24 Nov 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc