/**
 * 
 * @param args {arguments}
 * @param format {Array}
 * @returns {{}|Error} A hash table with the names of each format elements as keys. Optional format elements which were not fulfilled by an argument are undefined. If the arguments failed to parse correctly, the returned object will be an Error object.
 */
var arguer = module.exports = function (args, format)
{
	var deficit = format.length - args.length;

	if (format._optional === undefined)
	{
		format._optional = 0;
		var f;
		for (var x in format)
		{
			var f = format[x];
			if (f && typeof f === 'object' && (f.optional || f.mutex || f.requires || f.requiredBy || ('default' in f)))
			{
				f.optional = true;
				format._optional++;
			}
		}
	}

	var result = {};

	if (deficit > format._optional)
	{ 
		return new Error('Not enough arguments provided.');
	}

	var optionalIncluded = 0;
	var optionalSkipped = 0;
	var item;
	var argDex = 0;
	for (var i = 0; i < format.length; i++)
	{
		item = format[i];
		if (typeof item === 'string')
		{
			result[item] = args[argDex];
			argDex++;
		}
		else
		{
			if ((item.type && typeof args[argDex] !== item.type) ||
				(item.nType && typeof args[argDex] === item.nType) ||
				(item.instance && !(args[argDex] instanceof item.instance)) ||
				(item.nInstance && args[argDex] instanceof item.nInstance) ||
				(item.mutex && result[item.mutex] !== undefined) ||
				(item.requires && result[item.requires] === undefined))
			{
				if (item.optional && optionalSkipped < deficit && (!item.requiredBy || result[item.requiredBy] === undefined))
				{
					result[item.name] = item.default;
					optionalSkipped++;
				}
				else
				{
					return new Error('Invalid Arguments');
				}
			}
			else
			{
				if (item.optional)
				{
					if ((format._optional - optionalIncluded) > deficit)
					{
						optionalIncluded++
					}
					else
					{
						optionalSkipped++;
						result[item.name] = item.default;
						continue;
					}
				}

				result[item.name] = args[argDex];
				argDex++;
			}
		}
	}

	return result;
};

arguer.thrower = function (args, format)
{
	var a = arguer(args, format);
	if (a instanceof Error)
		throw a;
	
	return a;
};
@@ -904,16 +904,45 @@
 gDex = 0
+, mutex, requires, requiredBy
 ;%0A%09for (
@@ -999,16 +999,17 @@
 mat%5Bi%5D;%0A
+%0A
 %09%09if (ty
@@ -1099,20 +1099,353 @@
 %0A%09%09%7B%0A%09%09%09
-if (
+mutex = item.mutex %7C%7C %5B%5D;%0A%09%09%09mutex = (mutex instanceof Array ? mutex : %5Bmutex%5D);%0A%0A%09%09%09requires = item.requires %7C%7C %5B%5D;%0A%09%09%09requires = (requires instanceof Array ? requires : %5Brequires%5D);%0A%0A%09%09%09requiredBy = item.requiredBy %7C%7C %5B%5D;%0A%09%09%09requiredBy = (requiredBy instanceof Array ? requiredBy : %5BrequiredBy%5D);%0A%0A%09%09%09// failure conditions%0A%09%09%09if (%0A%09%09%09%09
 (item.ty
@@ -1688,39 +1688,55 @@
 %09%09%09(
-item.mutex && result%5Bitem.mutex
+mutex.some(function (prop) %7B return result%5Bprop
 %5D !=
@@ -1746,16 +1746,20 @@
 ndefined
+; %7D)
 ) %7C%7C%0A%09%09%09
@@ -1760,29 +1760,24 @@
 %7C%7C%0A%09%09%09%09(
-item.
 requires
  && resu
@@ -1772,32 +1772,50 @@
 ires
- && result%5Bitem.requires
+.some(function (prop) %7B return result%5Bprop
 %5D ==
@@ -1825,19 +1825,27 @@
 ndefined
+; %7D
 ))%0A
+%09%09%09)%0A
 %09%09%09%7B%0A%09%09%09
@@ -1841,32 +1841,38 @@
 %09)%0A%09%09%09%7B%0A%09%09%09%09if (
+%0A%09%09%09%09%09
 item.optional &&
@@ -1905,15 +1905,15 @@
  && 
-(!item.
+%0A%09%09%09%09%09(
 requ
@@ -1922,34 +1922,51 @@
 edBy
- %7C%7C result%5Bitem.requiredBy
+.every(function (prop) %7B return result%5Bprop
 %5D ==
@@ -1976,17 +1976,26 @@
 ndefined
-)
+; %7D))%0A%09%09%09%09
 )%0A%09%09%09%09%7B%0A
@@ -2579,17 +2579,16 @@
 hrow a;%0A
-%09
 %0A%09return
@@ -2589,12 +2589,37 @@
 return a;%0A%7D;
+%0A%0A// vim: noet sw=4 ts=4%0A

add support for multiple mutex, requires, and requiredBy