-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
57 lines (50 loc) · 1.31 KB
/
utils.ts
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
import * as path from 'path';
import * as fs from 'fs';
import { Pokemon, PokemonBase, PokemonType } from '@klifu/core/dist/types';
import {Cache} from '@klifu/core';
const DIR_PATH = path.resolve(__dirname);
export const filePaths = {
pokemons: path.resolve(DIR_PATH, 'pokemons.json')
}
type TypeColors = {
[pokemonType in PokemonType]: string;
};
export class PokemonTypeColor {
static readonly colors: TypeColors = {
Bug: 'green',
Dark: 'black',
Dragon: 'blueBright',
Electric: 'yellowBright',
Fairy: 'redBright',
Fighting: 'red',
Fire: 'yellow',
Flying: 'cyan',
Ghost: 'magenta',
Grass: 'green',
Ground: '#BA4A00',
Ice: 'blueBright',
Normal: 'white',
Poison: 'magentaBright',
Psychic: 'cyanBright',
Rock: '#F39C12',
Steel: '#D7BDE2',
Water: 'blue'
}
static get(pokemonType: PokemonType) {
return this.colors[pokemonType];
}
}
export class Stash {
private _filePaths = filePaths;
async loadPokemonData(): Promise<Array<PokemonBase>> {
let pokemons: Array<PokemonBase>
if(fs.existsSync(this._filePaths.pokemons)) {
pokemons = JSON.parse(fs.readFileSync(this._filePaths.pokemons, 'utf-8'));
return pokemons;
}else {
pokemons = await Cache.pokemons();
fs.writeFileSync(this._filePaths.pokemons, JSON.stringify(pokemons), {encoding: 'utf-8'});
}
return pokemons;
}
}