Class atropa.ArgsInfo
Version
20130221.
This represents a filter for arguments based on type.
Defined in: <node_modules/atropa-ArgsInfo/src/atropa-ArgsInfo.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
This represents a filter for arguments based on type.
|
Method Attributes | Method Name and Description |
---|---|
checkArgTypes(args)
Checks the given arguments object against the expected
arguments types.
|
|
getArgTypes(args)
Gets the types of arguments.
|
|
setExpectedArgTypes(typesObj)
Sets the expected argument types.
|
Class Detail
atropa.ArgsInfo()
This represents a filter for arguments based on type.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
function myClassyConstructor(takes, a, few, args) { var expectedArgTypes, checker; expectedArgTypes = {}; expectedArgTypes.requestWithMessage = ['string', 'string', 'string', 'function']; expectedArgTypes.requestNullMessage = ['string', 'string', 'object', 'function']; checker = new atropa.ArgsInfo(); checker.setExpectedArgTypes(expectedArgTypes); try { // Check the supplied arguments pseudo array's argument types // if the pattern of types in arguments matches one of the // patterns set on expectedArgTypes then the matching pattern // will be returned. Otherwise, an error will be thrown. checker.checkArgTypes(arguments); } catch (e) { // Invalid argument types supplied. Handle // the error or bail. } // the arguments supplied will be of the proper type // your function can go ahead and do things with them }
- Returns:
- {ArgsInfo} Returns an ArgsInfo filter.
- Requires:
- atropa.arrays.match
Method Detail
{String}
checkArgTypes(args)
Checks the given arguments object against the expected
arguments types.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
- Parameters:
- {arguments} args
- An arguments object
- Throws:
- {atropa.customErrors.InvalidArgumentTypesError}
- Throws an error if no matching
pattern of argument types can be found for
args
- Returns:
- {String} The user assigned key which matches the arguments supplied, or throws an error.
{Array}
getArgTypes(args)
- Parameters:
- {arguments} args
- An arguments object, or anything you want to check the type of.
- Returns:
- {Array} Returns an array of the types of arguments passed in.
setExpectedArgTypes(typesObj)
// typesObj is expected to be of the form: var typesObj = { "namedArgumentTypesArray" : ["string", "function", "number"], "namedAlternateArgumentTypesArray" : ["object", "function", "number"] }; // You may use as many named arrays as you wish and checkArgTypes will // test for a match to at least one of the provided named arrays.
- Parameters:
- {Expected Arg Types} typesObj
- An object containing information about the types of arguments you expect. Specifically, the object should look like the example.
- Throws:
- {atropa.customErrors.InvalidArgumentTypesError}
- Throws an error if the typesObj can not be used to set the expected argument types.