Reputation:
This isn't really a code-heavy question since it's more of a concept-type.
var args = require('minimist')(process.argv.slice(2), {string: "name"});
How does the code above work? I understand that I am including the minimist library in from the NPM but I don't quite understand why there's (process.argv.slice(2)). There are two open close parentheses over them.
I don't know how this process is called in Javascript. Is there any name for this form of usage ('minimist')(process.argv.slice....)?
Upvotes: 0
Views: 1411
Reputation: 27174
Your code is equivalent to:
var minimist = require('minimist');
var args = minimist(process.argv.slice(2), {string: "name"});
This means, the second parenthesis of your code is actually calling minimist
(or rather the function exported by the minimist
module) with two arguments:
process.argv.slice(2)
: all the arguments from the command line{string: "name"}
: The options objectI'm not aware of any official name.
Upvotes: 2