index.js
function(pieces, quote_char) {
			var unclosed_quote = false;
        	var result = [];
			for (var i = 0; i < pieces.length; i++) {
				if (unclosed_quote) {
					// Two scenarios. Either we have a closing quote or we don't.
					if (hasQuote(pieces[i], quote_char)) {
						// If it does, then there are two scenarios again:
						// Either the closing quote is the last character,
						// or there is text after it.
						var q_index = getFirstQuote(pieces[i], quote_char);
						if (q_index !== (pieces[i].length - 1)) {
							// The closing quote is not the last character; there's text after it.
							// We take that text and put it on the next piece.
							pieces[i+1] =
								pieces[i].substring(q_index + 1, pieces[i].length)
								+ (typeof pieces[i+1] !== 'undefined'
									? pieces[i+1] : '');
							pieces[i] = pieces[i].substring(0, q_index+1);
						}

						// Now the two scenarios are reduced to one. The last character of the
						// current piece will always be the last. We can now conclude that the
						// unclosed quote is now closed.
						result[result.length-1] =
							result[result.length-1] + ' ' + pieces[i];
						unclosed_quote = false;
					} else {
						// We don't have a closing quote. That means that the current piece is part
						// of the current string. So we concatenate it to the last piece in
						// result
						result[result.length-1] =
							result[result.length-1] + ' ' + pieces[i];
					}
				} else {
					// Two scenarios. Either we have an opening quote or we don't.
					if (hasQuote(pieces[i], quote_char)) {
						// We have an opening quote.
						// Three scenarios. We have one, two, or more than two
						if (countQuotes(pieces[i], quote_char) === 1) {
							// We have just one opening quote. We can safely add this piece to the
							// good pieces and carry on iterating. Any further pieces will be
							// concatenated with this one until the unclosed_quote gets closed.

							result.push(pieces[i]);
							unclosed_quote = true;
						} else if (countQuotes(pieces[i], quote_char) === 2) {
							// We have two quotes. However, we might have information after the
							// closing quote that doesn't belong to the string, so we split:
							var split = splitPiece(pieces[i], quote_char);

							// Both parts are safe to push, but we make sure that part 2 exists.
							result.push(split[0]);
							if(split[1] !== '') result.push(split[1]);
						} else {
							// We have more than three quotes. We split them. The first part of
							// each split is always safe to store in result because it's a full
							// closed string. The second part can be on any of the three scenarios:
							// one, two or three quotes. So we keep iterating until it's on the
							// first or on the second.
							var next = pieces[i];
							do {
								var split = splitPiece(next, quote_char);
								result.push(split[0]);
								next = split[1];
							} while (countQuotes(next, quote_char) > 2);

							// Now, the string that's left is in scenario 1 or 2.
							// We follow the same procedure.
							if(countQuotes(next, quote_char) === 1) {
								result.push(next);
								unclosed_quote = true;
							} else if (countQuotes(next, quote_char) === 2) {
								result.push(next);
							} else {
								// This shouldn't happen.
								throw new Error('I\'m sorry, but minimist-string has encountered' +
									'unexpected behaviour. This is porbably not your fault and' +
									'just a bug. Please report it with the stack trace on the' +
									'GitHub tracker.');
							}
						}
					} else {
						// We don't have a quote on this piece.
						// We can safely move on to the next one.
						result.push(pieces[i]);
					}
				}
			}
			return result;
		}
function(pieces, quote_char) {
			var unclosed_quote = false;
        	var result = [];
			for (var i = 0; i < pieces.length; i++) {
				if (unclosed_quote) {
					// Two scenarios. Either we have a closing quote or we don't.
					if (hasQuote(pieces[i], quote_char)) {
						// If it does, then there are two scenarios again:
						// Either the closing quote is the last character,
						// or there is text after it.
						var q_index = getFirstQuote(pieces[i], quote_char);
						if (q_index !== (pieces[i].length - 1)) {
							// The closing quote is not the last character; there's text after it.
							// We take that text and put it on the next piece.
							pieces[i+1] =
								pieces[i].substring(q_index + 1, pieces[i].length)
								+ (typeof pieces[i+1] !== 'undefined'
									? pieces[i+1] : '');
							pieces[i] = pieces[i].substring(0, q_index+1);
						}

						// Now the two scenarios are reduced to one. The last character of the
						// current piece will always be the last. We can now conclude that the
						// unclosed quote is now closed.
						result[result.length-1] =
							result[result.length-1] + ' ' + pieces[i];
						unclosed_quote = false;
					} else {
						// We don't have a closing quote. That means that the current piece is part
						// of the current string. So we concatenate it to the last piece in
						// result
						result[result.length-1] =
							result[result.length-1] + ' ' + pieces[i];
					}
				} else {
					// Two scenarios. Either we have an opening quote or we don't.
					if (hasQuote(pieces[i], quote_char)) {
						// We have an opening quote.
						// Three scenarios. We have one, two, or more than two
						if (countQuotes(pieces[i], quote_char) === 1) {
							// We have just one opening quote. We can safely add this piece to the
							// good pieces and carry on iterating. Any further pieces will be
							// concatenated with this one until the unclosed_quote gets closed.

							result.push(pieces[i]);
							unclosed_quote = true;
						} else if (countQuotes(pieces[i], quote_char) === 2) {
							// We have two quotes. However, we might have information after the
							// closing quote that doesn't belong to the string, so we split:
							var split = splitPiece(pieces[i], quote_char);

							// Both parts are safe to push, but we make sure that part 2 exists.
							result.push(split[0]);
							if(split[1] !== '') result.push(split[1]);
						} else {
							// We have more than three quotes. We split them. The first part of
							// each split is always safe to store in result because it's a full
							// closed string. The second part can be on any of the three scenarios:
							// one, two or three quotes. So we keep iterating until it's on the
							// first or on the second.
							var next = pieces[i];
							do {
								var split = splitPiece(next, quote_char);
								result.push(split[0]);
								next = split[1];
							} while (countQuotes(next, quote_char) > 2);

							// Now, the string that's left is in scenario 1 or 2.
							// We follow the same procedure.
							if(countQuotes(next, quote_char) === 1) {
								result.push(next);
								unclosed_quote = true;
							} else if (countQuotes(next, quote_char) === 2) {
								result.push(next);
							} else {
								// This shouldn't happen.
								throw new Error('I\'m sorry, but minimist-string has encountered' +
									'unexpected behaviour. This is porbably not your fault and' +
									'just a bug. Please report it with the stack trace on the' +
									'GitHub tracker.');
							}
						}
					} else {
						// We don't have a quote on this piece.
						// We can safely move on to the next one.
						result.push(pieces[i]);
					}
				}
			}
			return result;
		}
function ( pieces , quote_char ) { var unclosed_quote = false ; var result = [ ] ; for ( var i = 0 ; i < pieces . length ; i ++ ) { if ( unclosed_quote ) { // Two scenarios. Either we have a closing quote or we don't.
 if ( hasQuote ( pieces [ i ] , quote_char ) ) { // If it does, then there are two scenarios again:
 // Either the closing quote is the last character,
 // or there is text after it.
 var q_index = getFirstQuote ( pieces [ i ] , quote_char ) ; if ( q_index !== ( pieces [ i ] . length - 1 ) ) { // The closing quote is not the last character; there's text after it.
 // We take that text and put it on the next piece.
 pieces [ i + 1 ] = pieces [ i ] . substring ( q_index + 1 , pieces [ i ] . length ) + ( typeof pieces [ i + 1 ] !== 'undefined' ? pieces [ i + 1 ] : '' ) ; pieces [ i ] = pieces [ i ] . substring ( 0 , q_index + 1 ) ; } // Now the two scenarios are reduced to one. The last character of the
 // current piece will always be the last. We can now conclude that the
 // unclosed quote is now closed.
 result [ result . length - 1 ] = result [ result . length - 1 ] + ' ' + pieces [ i ] ; unclosed_quote = false ; } else { // We don't have a closing quote. That means that the current piece is part
 // of the current string. So we concatenate it to the last piece in
 // result
 result [ result . length - 1 ] = result [ result . length - 1 ] + ' ' + pieces [ i ] ; } } else { // Two scenarios. Either we have an opening quote or we don't.
 if ( hasQuote ( pieces [ i ] , quote_char ) ) { // We have an opening quote.
 // Three scenarios. We have one, two, or more than two
 if ( countQuotes ( pieces [ i ] , quote_char ) === 1 ) { // We have just one opening quote. We can safely add this piece to the
 // good pieces and carry on iterating. Any further pieces will be
 // concatenated with this one until the unclosed_quote gets closed.
 result . push ( pieces [ i ] ) ; unclosed_quote = true ; } else if ( countQuotes ( pieces [ i ] , quote_char ) === 2 ) { // We have two quotes. However, we might have information after the
 // closing quote that doesn't belong to the string, so we split:
 var split = splitPiece ( pieces [ i ] , quote_char ) ; // Both parts are safe to push, but we make sure that part 2 exists.
 result . push ( split [ 0 ] ) ; if ( split [ 1 ] !== '' ) result . push ( split [ 1 ] ) ; } else { // We have more than three quotes. We split them. The first part of
 // each split is always safe to store in result because it's a full
 // closed string. The second part can be on any of the three scenarios:
 // one, two or three quotes. So we keep iterating until it's on the
 // first or on the second.
 var next = pieces [ i ] ; do { var split = splitPiece ( next , quote_char ) ; result . push ( split [ 0 ] ) ; next = split [ 1 ] ; } while ( countQuotes ( next , quote_char ) > 2 ) ; // Now, the string that's left is in scenario 1 or 2.
 // We follow the same procedure.
 if ( countQuotes ( next , quote_char ) === 1 ) { result . push ( next ) ; unclosed_quote = true ; } else if ( countQuotes ( next , quote_char ) === 2 ) { result . push ( next ) ; } else { // This shouldn't happen.
 throw new Error ( 'I\'m sorry, but minimist-string has encountered' + 'unexpected behaviour. This is porbably not your fault and' + 'just a bug. Please report it with the stack trace on the' + 'GitHub tracker.' ) ; } } } else { // We don't have a quote on this piece.
 // We can safely move on to the next one.
 result . push ( pieces [ i ] ) ; } } } return result ; }
Detects strings in params and concatenates them into a single array element.
@private
@param {string[]} pieces    An array with every piece of the cli sentence. Initially,
this is sentence.split(' ');
@param  {string} quote_char The quote character, either " or '.
@returns {Array}            The array with concatenated strings.
Detects strings in params and concatenates them into a single array element .