Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minimist-functions

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minimist-functions

A wrapper for minimist to allow automatically called functions

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@minimist-functions

This is a small wrapper for minimist that will automatically call functions based on the args passed.

Install

With yarn

yarn add minimist-functions

Or NPM

npm install minimist-functions

Uninstall

With yarn

yarn remove minimist-functions

Or NPM

npm uninstall minimist-functions

Usage

Use minimist as normal but instead of require('minimist') you must use require('minimist-functions').

const args = require('minimist-functions')(process.argv.slice(2), {
  alias: {
    h: 'help',
    s: 'showMyValue',
    t: 'test'
  },
  default: {
    dir: process.cwd()
  }
})

Then define / attach your functions:

const help = (val, stop) => {
  console.log('Some help')
  
  // Stop exuction of subsequent args
  stop()
}

const showMyValue = (val, stop) => {
  console.log('You entered ' + val)
}

const test = (val, stop) => {
  console.log('Test called with arg: ' + arg)
}

args.process({
  help,
  showMyValue,
  test,
  default: () => {
    console.log('Will be called providing stop() hasn't been called in the arg chain')
  }
})

With the above setup, the following would be output:

C:\> yourcli -h
// Some help

C:\> yourcli -s SomeVal -t HelloWorld
// You entered SomeVal
// Test called with arg: HelloWorld
// Will be called providing stop() hasn't been called in the arg chain

minimist-functions API

Run just like minimist (substituting minimist for minimist-functions)

const args = require('minimist-functions')(args, opts)

See: minimist methods for parameter information.

args.process(functionMaps)

This will read your function maps and automatically call them based on the parameters passed through.

  • functionMaps (Object): Functions which map to your verbose arguments.

See usage for examples.

Roadmap

  • Automatic -h, --help functions based on JSDoc data against functions.

License

MIT ©2019 - present - Allan Gaunt

Keywords

FAQs

Package last updated on 18 Jun 2019

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