Skip to content

Commit

Permalink
code: simplify initialization
Browse files Browse the repository at this point in the history
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: #74
  • Loading branch information
elidoran authored and othiym23 committed Dec 13, 2016
1 parent 55f9449 commit 3370ce8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/nopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 3370ce8

Please sign in to comment.