index.js
function autoOpts(input, config = {}){
	const opts = new Object(null);
	const argv = [];
	let argvEnd;
	
	// Bail early if passed a blank string
	if(!input) return opts;
	
	// Stop parsing options after a double-dash
	const stopAt = input.indexOf("--");
	if(stopAt !== -1){
		argvEnd = input.slice(stopAt + 1);
		input = input.slice(0, stopAt);
	}
	
	for(let i = 0, l = input.length; i < l; ++i){
		let name = input[i];
		
		// Appears to be an option
		if(/^-/.test(name)){
			
			// Equals sign is used, should it become the option's value?
			if(!config.ignoreEquals && /=/.test(name)){
				const split = name.split(/=/);
				name        = formatName(split[0], config.noCamelCase);
				opts[name]  = split.slice(1).join("=");
			}
			
			else{
				name = formatName(name, config.noCamelCase);
				
				// Treat a following non-option as this option's value
				const next = input[i + 1];
				if(next != null && !/^-/.test(next)){
					
					// There's another option after this one. Collect multiple non-options into an array.
					const nextOpt = input.findIndex((s, I) => I > i && /^-/.test(s));
					if(nextOpt !== -1){
						opts[name] = input.slice(i + 1, nextOpt);
						
						// There's only one value to store; don't wrap it in an array
						if(nextOpt - i < 3)
							opts[name] = opts[name][0];
						
						i = nextOpt - 1;
					}
					
					// We're at the last option. Don't touch argv; assume it's a boolean-type option
					else opts[name] = true;
				}
				
				// No arguments defined. Assume it's a boolean-type option.
				else opts[name] = true;
			}
		}
		
		// Non-option: add to argv
		else argv.push(name);
	}
	
	
	// Add any additional arguments that were found after a "--" delimiter
	if(argvEnd)
		argv.push(...argvEnd);
	
	return {
		options: opts,
		argv:    argv,
	};
}
function autoOpts(input, config = {}){
	const opts = new Object(null);
	const argv = [];
	let argvEnd;
	
	// Bail early if passed a blank string
	if(!input) return opts;
	
	// Stop parsing options after a double-dash
	const stopAt = input.indexOf("--");
	if(stopAt !== -1){
		argvEnd = input.slice(stopAt + 1);
		input = input.slice(0, stopAt);
	}
	
	for(let i = 0, l = input.length; i < l; ++i){
		let name = input[i];
		
		// Appears to be an option
		if(/^-/.test(name)){
			
			// Equals sign is used, should it become the option's value?
			if(!config.ignoreEquals && /=/.test(name)){
				const split = name.split(/=/);
				name        = formatName(split[0], config.noCamelCase);
				opts[name]  = split.slice(1).join("=");
			}
			
			else{
				name = formatName(name, config.noCamelCase);
				
				// Treat a following non-option as this option's value
				const next = input[i + 1];
				if(next != null && !/^-/.test(next)){
					
					// There's another option after this one. Collect multiple non-options into an array.
					const nextOpt = input.findIndex((s, I) => I > i && /^-/.test(s));
					if(nextOpt !== -1){
						opts[name] = input.slice(i + 1, nextOpt);
						
						// There's only one value to store; don't wrap it in an array
						if(nextOpt - i < 3)
							opts[name] = opts[name][0];
						
						i = nextOpt - 1;
					}
					
					// We're at the last option. Don't touch argv; assume it's a boolean-type option
					else opts[name] = true;
				}
				
				// No arguments defined. Assume it's a boolean-type option.
				else opts[name] = true;
			}
		}
		
		// Non-option: add to argv
		else argv.push(name);
	}
	
	
	// Add any additional arguments that were found after a "--" delimiter
	if(argvEnd)
		argv.push(...argvEnd);
	
	return {
		options: opts,
		argv:    argv,
	};
}
function autoOpts ( input , config = { } ) { const opts = new Object ( null ) ; const argv = [ ] ; let argvEnd ; // Bail early if passed a blank string if ( ! input ) return opts ; // Stop parsing options after a double-dash const stopAt = input . indexOf ( "--" ) ; if ( stopAt !== - 1 ) { argvEnd = input . slice ( stopAt + 1 ) ; input = input . slice ( 0 , stopAt ) ; } for ( let i = 0 , l = input . length ; i < l ; ++ i ) { let name = input [ i ] ; // Appears to be an option if ( / ^- / . test ( name ) ) { // Equals sign is used, should it become the option's value? if ( ! config . ignoreEquals && / = / . test ( name ) ) { const split = name . split ( / = / ) ; name = formatName ( split [ 0 ] , config . noCamelCase ) ; opts [ name ] = split . slice ( 1 ) . join ( "=" ) ; } else { name = formatName ( name , config . noCamelCase ) ; // Treat a following non-option as this option's value const next = input [ i + 1 ] ; if ( next != null && ! / ^- / . test ( next ) ) { // There's another option after this one. Collect multiple non-options into an array. const nextOpt = input . findIndex ( ( s , I ) => I > i && / ^- / . test ( s ) ) ; if ( nextOpt !== - 1 ) { opts [ name ] = input . slice ( i + 1 , nextOpt ) ; // There's only one value to store; don't wrap it in an array if ( nextOpt - i < 3 ) opts [ name ] = opts [ name ] [ 0 ] ; i = nextOpt - 1 ; } // We're at the last option. Don't touch argv; assume it's a boolean-type option else opts [ name ] = true ; } // No arguments defined. Assume it's a boolean-type option. else opts [ name ] = true ; } } // Non-option: add to argv else argv . push ( name ) ; } // Add any additional arguments that were found after a "--" delimiter if ( argvEnd ) argv . push ( ... argvEnd ) ; return { options : opts , argv : argv , } ; }
Parse input using "best guess" logic. Called when no optdef is passed.

Essentially, the following assumptions are made about input:

- Anything beginning with at least one dash is an option name
- Options without arguments mean a boolean "true"
- Option-reading stops at "--"
- Anything caught between two options becomes the first option's value

@param {Array} input
@param {Object} [config={}]
@return {Object}
@internal
Parse input using best guess logic . Called when no optdef is passed .