index.js
function unstringify(input){
	input = String(input || "");
	const tokens   = [];
	const {length} = input;
	
	let quoteChar  = "";    // Quote-type enclosing current region
	let tokenData  = "";    // Characters currently being collected
	let isEscaped  = false; // Flag identifying an escape sequence
	
	for(let i = 0; i < length; ++i){
		const char = input[i];
		
		// Previous character was a backslash
		if(isEscaped){
			tokenData += char;
			isEscaped = false;
			continue;
		}
		
		// Whitespace: terminate token unless quoted
		if(!quoteChar && /[ \t\n]/.test(char)){
			tokenData && tokens.push(tokenData);
			tokenData = "";
			continue;
		}
		
		// Backslash: escape next character
		if("\\" === char){
			isEscaped = true;
			
			// Swallow backslash if it escapes a metacharacter
			const next = input[i + 1];
			if(quoteChar && (quoteChar === next || "\\" === next)
			|| !quoteChar && /[- \t\n\\'"`]/.test(next))
				continue;
		}
		
		// Quote marks
		else if((!quoteChar || char === quoteChar) && /['"`]/.test(char)){
			quoteChar = quoteChar === char ? "" : char;
			continue;
		}
		
		tokenData += char;
	}
	if(tokenData)
		tokens.push(tokenData);
	return tokens;
}
function unstringify(input){
	input = String(input || "");
	const tokens   = [];
	const {length} = input;
	
	let quoteChar  = "";    // Quote-type enclosing current region
	let tokenData  = "";    // Characters currently being collected
	let isEscaped  = false; // Flag identifying an escape sequence
	
	for(let i = 0; i < length; ++i){
		const char = input[i];
		
		// Previous character was a backslash
		if(isEscaped){
			tokenData += char;
			isEscaped = false;
			continue;
		}
		
		// Whitespace: terminate token unless quoted
		if(!quoteChar && /[ \t\n]/.test(char)){
			tokenData && tokens.push(tokenData);
			tokenData = "";
			continue;
		}
		
		// Backslash: escape next character
		if("\\" === char){
			isEscaped = true;
			
			// Swallow backslash if it escapes a metacharacter
			const next = input[i + 1];
			if(quoteChar && (quoteChar === next || "\\" === next)
			|| !quoteChar && /[- \t\n\\'"`]/.test(next))
				continue;
		}
		
		// Quote marks
		else if((!quoteChar || char === quoteChar) && /['"`]/.test(char)){
			quoteChar = quoteChar === char ? "" : char;
			continue;
		}
		
		tokenData += char;
	}
	if(tokenData)
		tokens.push(tokenData);
	return tokens;
}
function unstringify ( input ) { input = String ( input || "" ) ; const tokens = [ ] ; const { length } = input ; let quoteChar = "" ; // Quote-type enclosing current region let tokenData = "" ; // Characters currently being collected let isEscaped = false ; // Flag identifying an escape sequence for ( let i = 0 ; i < length ; ++ i ) { const char = input [ i ] ; // Previous character was a backslash if ( isEscaped ) { tokenData += char ; isEscaped = false ; continue ; } // Whitespace: terminate token unless quoted if ( ! quoteChar && / [ \t\n] / . test ( char ) ) { tokenData && tokens . push ( tokenData ) ; tokenData = "" ; continue ; } // Backslash: escape next character if ( "\\" === char ) { isEscaped = true ; // Swallow backslash if it escapes a metacharacter const next = input [ i + 1 ] ; if ( quoteChar && ( quoteChar === next || "\\" === next ) || ! quoteChar && / [- \t\n\\'"`] / . test ( next ) ) continue ; } // Quote marks else if ( ( ! quoteChar || char === quoteChar ) && / ['"`] / . test ( char ) ) { quoteChar = quoteChar === char ? "" : char ; continue ; } tokenData += char ; } if ( tokenData ) tokens . push ( tokenData ) ; return tokens ; }
Parse a string as a whitespace-delimited list of options,
preserving quoted and escaped characters.

@example unstringify("--foo --bar")     => ["--foo", "--bar"];
@example unstringify('--foo "bar baz"') => ["--foo", '"bar baz"'];
@param {String} input
@return {Object}
@internal
Parse a string as a whitespace - delimited list of options preserving quoted and escaped characters .