├── .eslintrc.json
├── .gitignore
├── README.md
├── github
├── ash.png
└── pokedex.png
├── index.js
├── lint-staged.config.js
└── package.json
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true
4 | },
5 | "extends": "eslint:recommended",
6 | "rules": {
7 | "indent": [
8 | "error",
9 | "tab"
10 | ],
11 | "linebreak-style": [
12 | "error",
13 | "unix"
14 | ],
15 | "quotes": [
16 | "error",
17 | "single"
18 | ],
19 | "semi": [
20 | "error",
21 | "always"
22 | ]
23 | }
24 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # node
2 | node_modules/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PokeSearch
2 |
3 | how many times you saw a pokemon and you couldn't register him? Now you'll not have this problem anymore!
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | ## What have been used until now:
12 |
13 | * Yargs
14 |
15 | * ECMA Script
16 |
17 | * Prettier
18 |
19 | * ESlint
20 |
21 | * Lint-Staged
22 |
23 | ## how to use the Pokedex?
24 |
25 | First of all, you need to clone this repo with:
26 |
27 | ```
28 | git clone https://github.com/gabriel-brito/poke-search.git
29 | ```
30 |
31 | And then you install all the dependencies with:
32 |
33 | ```
34 | cd poke-search
35 | npm i
36 | ```
37 |
38 | Ok! Now you're ready to register every pokemon on your pokedex with:
39 |
40 | ```
41 | node index.js pokemon
42 | ```
43 |
44 | Or with the directly command:
45 |
46 | ```
47 | node index.js pokemon [pokemon_name] - or - node index.js pokemon [1..151]
48 | ```
49 |
50 | It will apear every necessary detail of the selected pokemon on your console!
51 |
52 |
53 |
54 |
55 | Now you're *gonna catch 'em all*!!
56 |
--------------------------------------------------------------------------------
/github/ash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gabriel-brito/poke-search/119b12b2f5fe125283e4b631217cc8a588214b29/github/ash.png
--------------------------------------------------------------------------------
/github/pokedex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gabriel-brito/poke-search/119b12b2f5fe125283e4b631217cc8a588214b29/github/pokedex.png
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | let fetch = require("node-fetch");
3 | let readline = require("readline");
4 |
5 | require("yargs")
6 | .usage("$0 [args]")
7 | .command(
8 | "pokemon [name]",
9 | "and then you put your pokemon name or number",
10 | {
11 | pokemon: { name: "bulbasaur" }
12 | },
13 | argv => {
14 | if (argv.name) {
15 | setTimeout(() => {
16 | let directArg = argv.name.toLowerCase();
17 | fetch("https://pokeapi.co/api/v2/pokemon/" + directArg)
18 | .then(data => data.json())
19 | .then((data, err) => {
20 | let { id, name, weight, height } = data;
21 | if (typeof id == "undefined") {
22 | console.log(
23 | `pokemon's name or number is wrong`
24 | );
25 | } else {
26 | console.log(`pokemon id: ${id}`);
27 | console.log(`pokemon name: ${name}`);
28 | console.log(`pokemon weight: ${weight} kg`);
29 | console.log(`pokemon height: ${height}`);
30 | }
31 | })
32 | .catch(err => {
33 | console.log("Something went wrong");
34 | });
35 | }, 100);
36 | } else {
37 | var userChoise = readline.createInterface({
38 | input: process.stdin,
39 | output: process.stdout
40 | });
41 | userChoise.question(
42 | "What is the number or name of your pokemon? \n",
43 | answer => {
44 | let questionArg = answer.toLowerCase()
45 | fetch("https://pokeapi.co/api/v2/pokemon/" + questionArg)
46 | .then(data => data.json())
47 | .then((data, err) => {
48 | let { id, name, weight, height } = data;
49 | if (typeof id == "undefined") {
50 | console.log(
51 | `pokemon's name or number is wrong`
52 | );
53 | } else {
54 | console.log(`pokemon id: ${id}`);
55 | console.log(`pokemon name: ${name}`);
56 | console.log(`pokemon weight: ${weight} kg`);
57 | console.log(`pokemon height: ${height}`);
58 | }
59 | })
60 | .catch(err => {
61 | console.log("Something went wrong");
62 | });
63 | userChoise.close();
64 | }
65 | );
66 | }
67 | }
68 | )
69 | .help().argv;
70 |
--------------------------------------------------------------------------------
/lint-staged.config.js:
--------------------------------------------------------------------------------
1 | "lint-staged": {
2 | "*.js":[
3 | "prettier --write --single-quote true --trailing-comma all --print-width 120",
4 | "gid add"
5 | ]
6 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "PokeSearch",
3 | "version": "2.0.1",
4 | "description": "Intership job challenge",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Gabriel Santos",
10 | "license": "ISC",
11 | "dependencies": {
12 | "node-fetch": "^1.7.0",
13 | "yargs": "^8.0.1"
14 | },
15 | "devDependencies": {
16 | "eslint": "^4.0.0",
17 | "husky": "^0.13.4",
18 | "lint-staged": "^3.6.1",
19 | "prettier": "^1.4.4"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------