-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·56 lines (51 loc) · 1.12 KB
/
index.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
54
55
56
#!/usr/bin/env node
const cp = require("copy-paste");
const ArgumentParser = require("argparse").ArgumentParser;
const {version} = require('./package.json');
const parser = new ArgumentParser({
version,
addHelp: true,
description: 'Generate pyramids'
});
parser.addArgument(
'size',
{
type: 'int',
help: 'Size of the pyramid',
})
parser.addArgument(
'emoji',
{
help: 'emoji/text to be displayed inside the pyramid',
})
parser.addArgument(
[ '-s', '--no-space' ],
{
default: false,
nargs: 0,
help: 'Remove space between emojis',
dest: 'noSpace',
}
);
parser.addArgument(
[ '-c', '--no-copy' ],
{
default: false,
nargs: 0,
help: "Disable copying the pyramid to the clipboard",
dest: 'noCopy'
}
);
const args = parser.parseArgs();
const generatePyramid = ({size, emoji, noSpace, noCopy}) => {
const result = [];
for (let i = 1; i < size * 2; i++) {
let n = i > size ? size * 2 - i : i;
result.push((noSpace ? emoji : `${emoji} `).repeat(n));
}
console.log(result.join('\n'));
if (!noCopy) {
cp.copy(result.join('\n'));
}
};
generatePyramid(args);