0.1.1 • Published 11 years ago

optargs v0.1.1

Weekly downloads
11
License
-
Repository
github
Last release
11 years ago

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