"use strict";

/*
	Straight-forward node.js arguments parser
	Author: eveningkid
	License: Apache-2.0
*/

function Parse (argv) {
	// Removing node/bin and called script name
	argv = argv.slice(2);

	// Returned object
	var args = {};
	
	var argName, argValue;

	// For each argument
	argv.forEach(function (arg, index) {
		// Seperate argument, for a key/value return
		arg = arg.split('=');

		// Retrieve the argument name
		argName = arg[0];
    
		// Remove "--" or "-"
		if (argName.indexOf('-') === 0) {
			argName = argName.slice(argName.slice(0, 2).lastIndexOf('-') + 1);
		}
		
		// Associate defined value or initialize it to "true" state
		argValue = (arg.length === 2)
			? parseFloat(arg[1]).toString() === arg[1] // check if argument is valid number
				? +arg[1]
				: arg[1]
			: true;

		// Finally add the argument to the args set
		args[argName] = argValue;
	});

	return args;
}

module.exports = Parse;

@@ -1,9 +1,9 @@
-%22
+'
 use stri
@@ -4,17 +4,17 @@
 e strict
-%22
+'
 ;%0A%0A/*%0A%09S
@@ -99,16 +99,74 @@
 2.0%0A*/%0A%0A
+const ARGUMENT_SEPARATION_REGEX = /(%5B%5E=%5Cs%5D+)=?(%5B%5E%5Cs%5D*)/;%0A%0A
 function
@@ -171,17 +171,16 @@
 on Parse
- 
 (argv) %7B
@@ -180,17 +180,18 @@
 argv) %7B%0A
-%09
+  
 // Remov
@@ -226,17 +226,18 @@
 pt name%0A
-%09
+  
 argv = a
@@ -255,34 +255,23 @@
 );%0A%0A
-%09// Returned object%0A%09var a
+  const parsedA
 rgs 
@@ -280,14 +280,13 @@
 %7B%7D;%0A
-%09%0A%09var
+  let
  arg
@@ -306,31 +306,10 @@
 e;%0A%0A
-%09// For each argument%0A%09
+  
 argv
@@ -334,28 +334,23 @@
 (arg
-, index) %7B%0A%09%09
+) %7B%0A    
 // Sep
-e
+a
 rate
@@ -358,17 +358,16 @@
 argument
-,
  for a k
@@ -382,18 +382,20 @@
  return%0A
-%09%09
+    
 arg = ar
@@ -400,23 +400,69 @@
 arg.
-split('=');%0A%0A%09%09
+match(ARGUMENT_SEPARATION_REGEX);%0A    arg.splice(0, 1);%0A%0A    
 // R
@@ -487,18 +487,20 @@
 nt name%0A
-%09%09
+    
 argName 
@@ -513,15 +513,13 @@
 0%5D;%0A
+%0A
     
-%0A%09%09
 // R
@@ -536,18 +536,20 @@
  or %22-%22%0A
-%09%09
+    
 if (argN
@@ -574,19 +574,22 @@
 == 0) %7B%0A
-%09%09%09
+      
 argName 
@@ -651,210 +651,188 @@
 1);%0A
-%09%09%7D%0A%09%09%0A%09%09// Associate defined value or initialize
+    %7D%0A%0A    // Parse argument value or set
  it to 
-%22
+%60
 true
-%22 state%0A%09%09argValue = (arg.length === 2)%0A%09%09%09? parseFloat(arg%5B1%5D).toString() === arg%5B1%5D // check if argument is valid number%0A%09%09%09%09? +arg%5B1%5D%0A%09%09%09%09
+%60 if empty%0A    argValue =%0A      arg%5B1%5D !== ''%0A        ? parseFloat(arg%5B1%5D).toString() === arg%5B1%5D%0A          ? +arg%5B1%5D%0A          
 : ar
@@ -840,11 +840,16 @@
 %5B1%5D%0A
-%09%09%09
+        
 : tr
@@ -857,57 +857,19 @@
 e;%0A%0A
-%09%09// Finally add the argument to the args set%0A%09%09a
+    parsedA
 rgs%5B
@@ -893,23 +893,31 @@
 ue;%0A
-%09
+  
 %7D);%0A%0A
-%09
+  
 return 
-a
+parsedA
 rgs;

args correctly separated