-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathto-upper-case.js
39 lines (34 loc) · 1014 Bytes
/
to-upper-case.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
/*
Converts to upper case any phrase if the -u option is passed.
*/
require ("../lib").createParser ({ once: true })
.on ("start", function (argv){
argv.phrase = [];
})
.on ("argument", function (argv, argument, ignore){
argv.phrase.push (argv.u ? argument.toUpperCase () : argument);
//We don't want to store the words into the final object
ignore ();
})
.on ("option", function (argv, option, value, long, ignore){
//We only need the "-u" option, ignore the rest, if any
if (option !== "u") ignore ();
})
.on ("end", function (argv){
argv.phrase = argv.phrase.join (" ");
console.log (argv);
})
.allowUndefinedArguments ()
//If "sort" is enabled, the options are parsed before the arguments
.sort ()
.body ()
.option ({ short: "u" })
.argv ();
/*
$ node to-upper-case.js this is a sample text with the -u option
{
u: true,
phrase: "THIS IS A SAMPLE TEXT WITH THE OPTION"
}
*/