optargs
v0.1.1
Published
An optional arguments parser for javascript functions.
Downloads
3
Readme
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 access
address
likeoptArgs['address']
- this should look like
- to learn more, look at
test.js
for some examples