Skip to content

Commit

Permalink
Added camelCase function that converts --multi-word-option to camel c…
Browse files Browse the repository at this point in the history
…ase (so it becomes argv.multiWordOption).

It works well with demand(), boolean(), check() etc. If you apply camelCase() before the others, you get to use the camelCased option name in your parameters.
  • Loading branch information
papandreou committed Feb 27, 2011
1 parent 60b57da commit cc53c56
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ function Argv (args, cwd) {
return Argv(args).argv;
};

self.camelCase = function () {
for (var key in self.argv) {
var camelCasedKey = key.replace(/-([a-z])/g, function ($0, firstLetter) {
return firstLetter.toUpperCase();
});
if (camelCasedKey !== key) {
self.argv[camelCasedKey] = self.argv[key];
delete self.argv[key];
}
}
return self;
};

return self;
};

Expand Down

0 comments on commit cc53c56

Please sign in to comment.