From 8d4cd4111fa17be82bdf85f036c1e9f355ed09cc Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Sun, 21 Feb 2021 14:45:21 +0100 Subject: [PATCH] Renamed types --- src/scripts/classes/prefix-parser.ts | 8 ++++---- src/scripts/platform-data.ts | 8 ++++---- src/scripts/shared.ts | 11 +++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/scripts/classes/prefix-parser.ts b/src/scripts/classes/prefix-parser.ts index f6939df..69af3b3 100644 --- a/src/scripts/classes/prefix-parser.ts +++ b/src/scripts/classes/prefix-parser.ts @@ -1,7 +1,7 @@ "use strict"; // Modules from file -import shared, { DictType } from "../shared.js"; +import shared, { TPrefixDict } from "../shared.js"; /** * Convert prefixes and platform tags from string to ID and vice versa. @@ -15,7 +15,7 @@ export default class PrefixParser { * @param {Any} value Value associated with the key * @returns {String|undefined} Key found or undefined */ - getKeyByValue(object: DictType, value: string): string | undefined { + getKeyByValue(object: TPrefixDict, value: string): string | undefined { return Object.keys(object).find(key => object[key] === value); } @@ -35,7 +35,7 @@ export default class PrefixParser { /** * Check if `dict` contains `value` as a value. */ - valueInDict(dict: DictType, value: string): boolean { + valueInDict(dict: TPrefixDict, value: string): boolean { const array = Object.values(dict); const upperArr = this.toUpperCaseArray(array); const element = value.toUpperCase(); @@ -47,7 +47,7 @@ export default class PrefixParser { * desired element and return the dictionary that contains it. * @param element Element to search in the prefixes as a key or as a value */ - searchElementInPrefixes(element: string | number): DictType | null { + searchElementInPrefixes(element: string | number): TPrefixDict | null { // Local variables let dictName = null; diff --git a/src/scripts/platform-data.ts b/src/scripts/platform-data.ts index b7417c6..7f4f3ba 100644 --- a/src/scripts/platform-data.ts +++ b/src/scripts/platform-data.ts @@ -7,7 +7,7 @@ import { readFileSync, writeFileSync, existsSync } from "fs"; import cheerio from "cheerio"; // Modules from file -import shared, { DictType } from "./shared.js"; +import shared, { TPrefixDict } from "./shared.js"; import { urls as f95url } from "./constants/url.js"; import { selectors as f95selector} from "./constants/css-selector.js"; import { fetchHTML } from "./network-helper.js"; @@ -36,7 +36,7 @@ interface ICategoryResource { */ interface ILatestResource { prefixes: ICategoryResource[], - tags: DictType, + tags: TPrefixDict, options: string } //#endregion Interface definitions @@ -75,7 +75,7 @@ function readCache(path: string) { if (existsSync(path)) { const data = readFileSync(path, {encoding: "utf-8", flag: "r"}); - const json: { [s: string]: DictType } = JSON.parse(data); + const json: { [s: string]: TPrefixDict } = JSON.parse(data); shared.setPrefixPair("engines", json.engines); shared.setPrefixPair("statuses", json.statuses); @@ -129,7 +129,7 @@ function assignLatestPlatformData(data: ILatestResource): void { // Parse and assign the values that are NOT tags for (const p of data.prefixes) { // Prepare the dict - const dict: DictType = {}; + const dict: TPrefixDict = {}; for (const e of p.prefixes) dict[e.id] = e.name.replace("'", "'"); // Save the property diff --git a/src/scripts/shared.ts b/src/scripts/shared.ts index 2c5e343..7e40e9c 100644 --- a/src/scripts/shared.ts +++ b/src/scripts/shared.ts @@ -12,9 +12,8 @@ import log4js from "log4js"; import Session from "./classes/session.js"; // Types declaration -export type DictType = { [n: number]: string; }; -type KeyPrefixesType = "engines" | "statuses" | "tags" | "others"; -type PrefixesType = { [key in KeyPrefixesType]: DictType } +export type TPrefixDict = { [n: number]: string; }; +type TPrefixKey = "engines" | "statuses" | "tags" | "others"; /** * Class containing variables shared between modules. @@ -28,7 +27,7 @@ export default abstract class Shared { /** * List of platform prefixes and tags. */ - static _prefixes: PrefixesType = {} as PrefixesType; + static _prefixes: { [key in TPrefixKey]: TPrefixDict } = {} as { [key in TPrefixKey]: TPrefixDict }; /** * Logger object used to write to both file and console. */ @@ -49,7 +48,7 @@ export default abstract class Shared { /** * List of platform prefixes and tags. */ - static get prefixes(): { [s: string]: DictType } { + static get prefixes(): { [s: string]: TPrefixDict } { return this._prefixes; } /** @@ -73,7 +72,7 @@ export default abstract class Shared { //#endregion Getters //#region Setters - static setPrefixPair(key: KeyPrefixesType, val: DictType): void { + static setPrefixPair(key: TPrefixKey, val: TPrefixDict): void { this._prefixes[key] = val; }