๐Ÿ“ฆ leonardomso / chuck-cli

๐Ÿ“„ requests.js ยท 37 lines
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
37const chalk = require('chalk');
const fetch = require('node-fetch');

const requestJoke = async () => {
    const url = 'https://api.chucknorris.io/jokes/random';
    const response = await fetch(url);
    const data = await response.json();
    return console.log(chalk.white.bgGreen.bold(data.value));
};

const requestCategories = async () => {
    const url = 'https://api.chucknorris.io/jokes/categories';
    const response = await fetch(url);
    const data = await response.json();
    for (const item of data) {
        console.log(chalk.white.bgGreen.bold(item));
    }
};

const requestSpecificCategorie = async categorie => {
    const url = `https://api.chucknorris.io/jokes/random?category=${categorie}`;
    const response = await fetch(url);
    const data = await response.json();
    return console.log(chalk.white.bgGreen.bold(data.value));
};

const sum = (a, b) => {
    return a + b;
};

module.exports = {
    requestJoke,
    requestCategories,
    requestSpecificCategorie,
    sum,
};