-
Notifications
You must be signed in to change notification settings - Fork 243
/
ansiart.js
58 lines (52 loc) · 1.28 KB
/
ansiart.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
57
58
var path = require('path');
var ansiArt = require('ansi-art').default;
var cowsay = require('cowsay');
var getCustomArt = require('./arts');
function getAnsiArt(art, textToSay) {
if (art && (art.toUpperCase() === 'RANDOM')) {
// show a random art
var rand = Math.random() * 100;
if (rand >= 50) { // 50%
return cowsay.say({
r: true,
text: textToSay
});
} else if (rand >= 25) { // 25%
return ansiArt.get({
speechText: textToSay
});
} else { // 25%
return getCustomArt(art, textToSay) || ansiArt.get({
speechText: textToSay
});
}
}
else if (/.ansi$/.test(art)) {
// if SAY ends with ".ansi" use the 'ansi-art' library
if (art === path.basename(art)) {
return ansiArt.get({
artName: art.slice(0,-5),
speechText: textToSay
});
} else {
return ansiArt.get({
filePath: art,
speechText: textToSay
});
}
}
else if (/.cow$/.test(art)) {
// if SAY ends with ".cow" use the 'cowsay' library
return cowsay.say({
f: art.slice(0,-4),
text: textToSay
});
}
else {
return getCustomArt(art, textToSay) || ansiArt.get({
artName: art,
speechText: textToSay
});
}
}
module.exports = getAnsiArt;