0.1.1 • Published 11 years ago
optargs v0.1.1
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 calladdress
. you would then accessaddress
likeoptArgs['address']
- to learn more, look at
test.js
for some examples