Renamed types

pull/73/head
MillenniumEarl 2021-02-21 14:45:21 +01:00
parent c9593d76b6
commit 8d4cd4111f
3 changed files with 13 additions and 14 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;
}