From 07c69d38b5186450941fbb505550becb78a0e925 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 12 Dec 2016 15:59:43 -0500 Subject: [PATCH] code: simplify key-value extraction Credit: @elidoran Reviewed-By: @othiym23 PR-URL: https://github.com/npm/nopt/pull/73 --- lib/nopt.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/nopt.js b/lib/nopt.js index 97707e7..94a983c 100644 --- a/lib/nopt.js +++ b/lib/nopt.js @@ -246,12 +246,12 @@ function parse (args, data, remain, types, shorthands) { } var hadEq = false if (arg.charAt(0) === "-" && arg.length > 1) { - if (arg.indexOf("=") !== -1) { + var at = arg.indexOf('=') + if (at > -1) { hadEq = true - var v = arg.split("=") - arg = v.shift() - v = v.join("=") - args.splice.apply(args, [i, 1].concat([arg, v])) + var v = arg.substr(at + 1) + arg = arg.substr(0, at) + args.splice(i, 1, arg, v) } // see if it's a shorthand