From 7d72153d68ea4c682266f0301aa45b4e3a9e45a9 Mon Sep 17 00:00:00 2001 From: Fridon Date: Thu, 23 Jun 2022 00:01:12 +0400 Subject: big refactor + raw option --- src/util/cache.ts | 9 ++++++- src/util/help.ts | 28 -------------------- src/util/logger.ts | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 29 deletions(-) delete mode 100644 src/util/help.ts create mode 100644 src/util/logger.ts (limited to 'src/util') diff --git a/src/util/cache.ts b/src/util/cache.ts index 3a0c5d4..df52f89 100644 --- a/src/util/cache.ts +++ b/src/util/cache.ts @@ -1,5 +1,8 @@ import { join } from "https://deno.land/std@0.144.0/path/mod.ts"; -import { ensureDirSync } from "https://deno.land/std@0.78.0/fs/mod.ts"; +import { + ensureDirSync, + existsSync, +} from "https://deno.land/std@0.78.0/fs/mod.ts"; import { environment } from "../environment/environment.ts"; export class Cache { @@ -36,4 +39,8 @@ export class Cache { return undefined; } } + + public exists(name: string, extension?: string) { + return existsSync(join(this.path, `${name}${extension}`)); + } } diff --git a/src/util/help.ts b/src/util/help.ts deleted file mode 100644 index 80b7e57..0000000 --- a/src/util/help.ts +++ /dev/null @@ -1,28 +0,0 @@ -export function help(): void { - console.log( - "\ncountryfetch\n", - "\tFetch information about countries", - "\n", - "\nUSAGE\n", - "\tcountryfetch ", - "\n", - "\nARGS:\n", - "\tsync", - "\n\t\tSynchronize database. Stores countries' data in ~/.cache/conntryfetch/countries.json.", - "\n", - "\n\trandom", - "\n\t\tPrint information about a random country.", - "\n", - "\n\t", - "\n\t\tPrint information about the specified country.", - "\n", - "\n", - "\n\tcapital ", - "\n\t\tPrint country to which the specified capital belongs.", - "\n", - "\nEXAMPLE:\n", - "\tcountryfetch germany", - "\n\t\tPrints information about Germany", - "\n" - ); -} diff --git a/src/util/logger.ts b/src/util/logger.ts new file mode 100644 index 0000000..52965c8 --- /dev/null +++ b/src/util/logger.ts @@ -0,0 +1,77 @@ +import * as nano from "https://deno.land/x/nanocolors@0.1.12/mod.ts"; +import { FetchedCountry } from "../models/FetchedCountry.model.ts"; + +export class Logger { + public log(...data: any) { + console.log(data); + } + + public alert(...data: any) { + console.log(nano.yellow(data)); + } + + public success(...data: any) { + console.log(nano.green(data)); + } + + public error(...data: any) { + console.error(data); + } + + public logCountry(country: FetchedCountry) { + console.log( + nano.cyan("\nCountry:\t"), + country.country, + country.flag, + nano.green("\nLanguages:\t"), + country.languages, + nano.green("\nCapital:\t"), + country.capital, + nano.green("\nRegion:\t\t"), + country.region, + nano.green("\nPopulation:\t"), + country.population.toLocaleString(), + nano.green("\nCurrencies:\t"), + country.currencies + ); + } + + public capitalOf(capital: string, country: string) { + console.log( + nano.green(capital) + " is the capital of " + nano.cyan(country) + ); + } + + public help(): void { + console.log( + "\ncountryfetch\n", + "\tFetch information about countries", + "\n", + "\nUSAGE\n", + "\tcountryfetch ", + "\n", + "\nARGS:\n", + "\tsync", + "\n\t\tSynchronize database. Stores countries' data in ~/.cache/conntryfetch/countries.json.", + "\n", + "\n\trandom", + "\n\t\tPrint information about a random country.", + "\n", + "\n\t", + "\n\t\tPrint information about the specified country.", + "\n", + "\n", + "\n\tcapital ", + "\n\t\tPrint country to which the specified capital belongs.", + "\n", + "\n", + "\n\traw ", + "\n\t\tPrint country information in raw format as JavaScript object.", + "\n", + "\nEXAMPLE:\n", + "\tcountryfetch germany", + "\n\t\tPrints information about Germany.", + "\n" + ); + } +} -- cgit v1.2.3