index.js
function resolveDuplicate(option, name, value){
		switch(duplicates){
			
			// Use the first value (or set of values); discard any following duplicates
			case "use-first":
				return result.options[name];
			
			// Use the last value (or set of values); discard any preceding duplicates. Default.
			case "use-last":
			default:
				return result.options[name] = value;
			
			// Use the first/last options; treat any following/preceding duplicates as argv items respectively
			case "limit-first":
			case "limit-last":
				result.argv.push(option.prevMatchedName, ...arrayify(value));
				break;
			
			// Throw an exception
			case "error":
				const error = new TypeError(`Attempting to reassign option "${name}" with value(s) ${JSON.stringify(value)}`);
				error.affectedOption = option;
				error.affectedValue  = value;
				throw error;
			
			// Add parameters of duplicate options to the argument list of the first
			case "append":
				const oldValues = arrayify(result.options[name]);
				const newValues = arrayify(value);
				result.options[name] = oldValues.concat(newValues);
				break;
			
			// Store parameters of duplicated options in a multidimensional array
			case "stack": {
				let oldValues   = result.options[name];
				const newValues = arrayify(value);
				
				// This option hasn't been "stacked" yet
				if(!option.stacked){
					oldValues            = arrayify(oldValues);
					result.options[name] = [oldValues, newValues];
					option.stacked       = true;
				}
				
				// Already "stacked", so just shove the values onto the end of the array
				else result.options[name].push(arrayify(newValues));
				
				break;
			}
			
			// Store each duplicated value in an array using the order they appear
			case "stack-values": {
				let values = result.options[name];
				
				// First time "stacking" this option (nesting its value/s inside an array)
				if(!option.stacked){
					const stack = [];
					for(const value of arrayify(values))
						stack.push([value]);
					values = stack;
					option.stacked = true;
				}
				
				arrayify(value).forEach((v, i) => {
					
					// An array hasn't been created at this index yet,
					// because an earlier option wasn't given enough parameters.
					if(undefined === values[i])
						values[i] = Array(values[0].length - 1);
					
					values[i].push(v);
				});
				
				result.options[name] = values;
				break;
			}
		}
	}
function resolveDuplicate(option, name, value){
		switch(duplicates){
			
			// Use the first value (or set of values); discard any following duplicates
			case "use-first":
				return result.options[name];
			
			// Use the last value (or set of values); discard any preceding duplicates. Default.
			case "use-last":
			default:
				return result.options[name] = value;
			
			// Use the first/last options; treat any following/preceding duplicates as argv items respectively
			case "limit-first":
			case "limit-last":
				result.argv.push(option.prevMatchedName, ...arrayify(value));
				break;
			
			// Throw an exception
			case "error":
				const error = new TypeError(`Attempting to reassign option "${name}" with value(s) ${JSON.stringify(value)}`);
				error.affectedOption = option;
				error.affectedValue  = value;
				throw error;
			
			// Add parameters of duplicate options to the argument list of the first
			case "append":
				const oldValues = arrayify(result.options[name]);
				const newValues = arrayify(value);
				result.options[name] = oldValues.concat(newValues);
				break;
			
			// Store parameters of duplicated options in a multidimensional array
			case "stack": {
				let oldValues   = result.options[name];
				const newValues = arrayify(value);
				
				// This option hasn't been "stacked" yet
				if(!option.stacked){
					oldValues            = arrayify(oldValues);
					result.options[name] = [oldValues, newValues];
					option.stacked       = true;
				}
				
				// Already "stacked", so just shove the values onto the end of the array
				else result.options[name].push(arrayify(newValues));
				
				break;
			}
			
			// Store each duplicated value in an array using the order they appear
			case "stack-values": {
				let values = result.options[name];
				
				// First time "stacking" this option (nesting its value/s inside an array)
				if(!option.stacked){
					const stack = [];
					for(const value of arrayify(values))
						stack.push([value]);
					values = stack;
					option.stacked = true;
				}
				
				arrayify(value).forEach((v, i) => {
					
					// An array hasn't been created at this index yet,
					// because an earlier option wasn't given enough parameters.
					if(undefined === values[i])
						values[i] = Array(values[0].length - 1);
					
					values[i].push(v);
				});
				
				result.options[name] = values;
				break;
			}
		}
	}
function resolveDuplicate ( option , name , value ) { switch ( duplicates ) { // Use the first value (or set of values); discard any following duplicates case "use-first" : return result . options [ name ] ; // Use the last value (or set of values); discard any preceding duplicates. Default. case "use-last" : default : return result . options [ name ] = value ; // Use the first/last options; treat any following/preceding duplicates as argv items respectively case "limit-first" : case "limit-last" : result . argv . push ( option . prevMatchedName , ... arrayify ( value ) ) ; break ; // Throw an exception case "error" : const error = new TypeError ( ` ${ name } ${ JSON . stringify ( value ) } ` ) ; error . affectedOption = option ; error . affectedValue = value ; throw error ; // Add parameters of duplicate options to the argument list of the first case "append" : const oldValues = arrayify ( result . options [ name ] ) ; const newValues = arrayify ( value ) ; result . options [ name ] = oldValues . concat ( newValues ) ; break ; // Store parameters of duplicated options in a multidimensional array case "stack" : { let oldValues = result . options [ name ] ; const newValues = arrayify ( value ) ; // This option hasn't been "stacked" yet if ( ! option . stacked ) { oldValues = arrayify ( oldValues ) ; result . options [ name ] = [ oldValues , newValues ] ; option . stacked = true ; } // Already "stacked", so just shove the values onto the end of the array else result . options [ name ] . push ( arrayify ( newValues ) ) ; break ; } // Store each duplicated value in an array using the order they appear case "stack-values" : { let values = result . options [ name ] ; // First time "stacking" this option (nesting its value/s inside an array) if ( ! option . stacked ) { const stack = [ ] ; for ( const value of arrayify ( values ) ) stack . push ( [ value ] ) ; values = stack ; option . stacked = true ; } arrayify ( value ) . forEach ( ( v , i ) => { // An array hasn't been created at this index yet, // because an earlier option wasn't given enough parameters. if ( undefined === values [ i ] ) values [ i ] = Array ( values [ 0 ] . length - 1 ) ; values [ i ] . push ( v ) ; } ) ; result . options [ name ] = values ; break ; } } }
Manage duplicated option values
Manage duplicated option values