Renamed types
parent
c9593d76b6
commit
8d4cd4111f
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Modules from file
|
// 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.
|
* 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
|
* @param {Any} value Value associated with the key
|
||||||
* @returns {String|undefined} Key found or undefined
|
* @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);
|
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.
|
* 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 array = Object.values(dict);
|
||||||
const upperArr = this.toUpperCaseArray(array);
|
const upperArr = this.toUpperCaseArray(array);
|
||||||
const element = value.toUpperCase();
|
const element = value.toUpperCase();
|
||||||
|
@ -47,7 +47,7 @@ export default class PrefixParser {
|
||||||
* desired element and return the dictionary that contains it.
|
* desired element and return the dictionary that contains it.
|
||||||
* @param element Element to search in the prefixes as a key or as a value
|
* @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
|
// Local variables
|
||||||
let dictName = null;
|
let dictName = null;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { readFileSync, writeFileSync, existsSync } from "fs";
|
||||||
import cheerio from "cheerio";
|
import cheerio from "cheerio";
|
||||||
|
|
||||||
// Modules from file
|
// Modules from file
|
||||||
import shared, { DictType } from "./shared.js";
|
import shared, { TPrefixDict } from "./shared.js";
|
||||||
import { urls as f95url } from "./constants/url.js";
|
import { urls as f95url } from "./constants/url.js";
|
||||||
import { selectors as f95selector} from "./constants/css-selector.js";
|
import { selectors as f95selector} from "./constants/css-selector.js";
|
||||||
import { fetchHTML } from "./network-helper.js";
|
import { fetchHTML } from "./network-helper.js";
|
||||||
|
@ -36,7 +36,7 @@ interface ICategoryResource {
|
||||||
*/
|
*/
|
||||||
interface ILatestResource {
|
interface ILatestResource {
|
||||||
prefixes: ICategoryResource[],
|
prefixes: ICategoryResource[],
|
||||||
tags: DictType,
|
tags: TPrefixDict,
|
||||||
options: string
|
options: string
|
||||||
}
|
}
|
||||||
//#endregion Interface definitions
|
//#endregion Interface definitions
|
||||||
|
@ -75,7 +75,7 @@ function readCache(path: string) {
|
||||||
|
|
||||||
if (existsSync(path)) {
|
if (existsSync(path)) {
|
||||||
const data = readFileSync(path, {encoding: "utf-8", flag: "r"});
|
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("engines", json.engines);
|
||||||
shared.setPrefixPair("statuses", json.statuses);
|
shared.setPrefixPair("statuses", json.statuses);
|
||||||
|
@ -129,7 +129,7 @@ function assignLatestPlatformData(data: ILatestResource): void {
|
||||||
// Parse and assign the values that are NOT tags
|
// Parse and assign the values that are NOT tags
|
||||||
for (const p of data.prefixes) {
|
for (const p of data.prefixes) {
|
||||||
// Prepare the dict
|
// Prepare the dict
|
||||||
const dict: DictType = {};
|
const dict: TPrefixDict = {};
|
||||||
for (const e of p.prefixes) dict[e.id] = e.name.replace("'", "'");
|
for (const e of p.prefixes) dict[e.id] = e.name.replace("'", "'");
|
||||||
|
|
||||||
// Save the property
|
// Save the property
|
||||||
|
|
|
@ -12,9 +12,8 @@ import log4js from "log4js";
|
||||||
import Session from "./classes/session.js";
|
import Session from "./classes/session.js";
|
||||||
|
|
||||||
// Types declaration
|
// Types declaration
|
||||||
export type DictType = { [n: number]: string; };
|
export type TPrefixDict = { [n: number]: string; };
|
||||||
type KeyPrefixesType = "engines" | "statuses" | "tags" | "others";
|
type TPrefixKey = "engines" | "statuses" | "tags" | "others";
|
||||||
type PrefixesType = { [key in KeyPrefixesType]: DictType }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class containing variables shared between modules.
|
* Class containing variables shared between modules.
|
||||||
|
@ -28,7 +27,7 @@ export default abstract class Shared {
|
||||||
/**
|
/**
|
||||||
* List of platform prefixes and tags.
|
* 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.
|
* 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.
|
* List of platform prefixes and tags.
|
||||||
*/
|
*/
|
||||||
static get prefixes(): { [s: string]: DictType } {
|
static get prefixes(): { [s: string]: TPrefixDict } {
|
||||||
return this._prefixes;
|
return this._prefixes;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +72,7 @@ export default abstract class Shared {
|
||||||
//#endregion Getters
|
//#endregion Getters
|
||||||
|
|
||||||
//#region Setters
|
//#region Setters
|
||||||
static setPrefixPair(key: KeyPrefixesType, val: DictType): void {
|
static setPrefixPair(key: TPrefixKey, val: TPrefixDict): void {
|
||||||
this._prefixes[key] = val;
|
this._prefixes[key] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue