/
index.js
executable file
·43 lines (32 loc) · 951 Bytes
/
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
#!/usr/bin/env node
const ascii = require('ascii-art');
const download = require('download-file');
const imageSearch = require('g-i-s');
const options = {
searchTerms : ["christmas", "christmas cartoon", "christmassy"],
download: {
filename: "image.png"
},
ascii: {
filepath: "./image.png",
alphabet: "ultra-wide"
}
}
const getRandomFrom = (array) => {
const index = Math.floor(Math.random() * array.length);
return array[index];
}
imageSearch(getRandomFrom(options.searchTerms), (error, results) => {
let image = getRandomFrom(results);
download(image.url, options.download, (error) => {
if (error) throw error;
displayAsAscii("image.png");
});
});
const displayAsAscii = (filename) => {
const image = new ascii.Image(options.ascii);
image.write((error, rendered) => {
if (error) throw error;
console.log(rendered);
});
}