optargs

0.1.1 • Public • Published

optArgs

optArgs is a simple way to manage multiple typed optional arguments to javascript functions.

npm test to perform tests

Using optArgs

  • Require the package like this: var getOptArgs = require('optargs')
  • the main function takes 3 arguments, the calling function's arguments object, the number of non-optional arguments that the calling function takes (technically all arguments are optional in JS), and finally a list of strings representing the optional arguments that you are expecting. This list should be of the format ['name1:type1', 'name2:type2'].
  • the optArgs function will then return an object that contains all of the optional arguments that it found of the correct type.
    • this should look like var optArgs = getOptArgs(arguments, 2, ['address:string']);if you have a function that has two non-optional arguments and is expecting a potential third argument that we will call address.
    • you would then access address like optArgs['address']
  • to learn more, look at test.js for some examples

Readme

Keywords

none

Package Sidebar

Install

npm i optargs

Weekly Downloads

2

Version

0.1.1

License

none

Last publish

Collaborators

  • jackm321