-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (46 loc) · 1.49 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { program } from "commander";
import epoch from "./src/epoch.js";
import showHelp from "./src/help.js";
import { htmlDecode, htmlEncode } from "./src/html.js";
import objectId from "./src/objectid.js";
import { decode as urlDecode, encode as urlEncode } from "./src/url.js";
program
.command("epoch [input]")
.description("Convert one date format into epoch time or vice-versa")
.action((input) => epoch(input));
program
.command("objectid [input]")
.description("Convert a date into an ObjectId (MongoDB) and vice-versa")
.action((input) => objectId(input));
program
.command("url")
.argument("<type>", "encode|decode")
.argument("<input...>", "String to encode or decode")
.description("URL encode/decode a string")
.action((type, input) => {
if (type === "encode") {
urlEncode(input.join(" "));
} else {
urlDecode(input.join(" "));
}
});
program
.command("html")
.argument("<type>", "encode|decode")
.argument("<input...>", "String to encode or decode")
.description("HTML encode/decode a string")
.action((type, input) => {
if (type === "encode") {
htmlEncode(input.join(" "));
} else {
htmlDecode(input.join(" "));
}
});
if (process.env.alfred_version) {
program.command("help").action(() => {
showHelp(program.commands, true);
});
}
program.parse();
export const options = program.opts();
export const args = program.args;