From 3370ce87a7618ba228883861db84ddbcdff252a9 Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 12 Dec 2016 16:12:05 -0500 Subject: [PATCH] code: simplify initialization Instead of creating three vars separately and then combining them in an object a few lines later, create them already combined in an object. Then, reference the one used outside it when calling `parse()`. Credit: @elidoran Reviewed-By: @othiym23 PR-URL: https://github.com/npm/nopt/pull/74 --- lib/nopt.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/nopt.js b/lib/nopt.js index 94a983c..119ad4d 100644 --- a/lib/nopt.js +++ b/lib/nopt.js @@ -33,14 +33,16 @@ function nopt (types, shorthands, args, slice) { args = args.slice(slice) var data = {} , key - , remain = [] - , cooked = args - , original = args.slice(0) + , argv = { + remain: [], + cooked: args, + original: args.slice(0) + } - parse(args, data, remain, types, shorthands) + parse(args, data, argv.remain, types, shorthands) // now data is full clean(data, types, exports.typeDefs) - data.argv = {remain:remain,cooked:cooked,original:original} + data.argv = argv Object.defineProperty(data.argv, 'toString', { value: function () { return this.original.map(JSON.stringify).join(" ") }, enumerable: false })