chore: minor improvements in for cycle (#18)

This commit is contained in:
Stefano Borzì 2022-05-06 20:24:22 +02:00 committed by GitHub
parent 8331e4dd73
commit 216904fd6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 29 deletions

View file

@ -85,10 +85,8 @@ export class Armory {
websiteRoot: this.config.websiteRoot,
iframeMode: this.config.iframeMode,
};
for (const key in locals) {
if (locals.hasOwnProperty(key)) {
app.locals[key] = locals[key];
}
for (const key of Object.keys(locals)) {
app.locals[key] = locals[key];
}
app.locals.locals = locals;

View file

@ -115,7 +115,7 @@ export class Config {
} else if (typeof model === "object") {
const obj = {};
Config.loadObjFromEnv(logger, obj, model, parentName + i);
if (Object.keys(obj).length > 0) {
if (Object.keys(obj).length) {
arr.push(obj);
}
} else if (process.env.hasOwnProperty(key)) {
@ -161,7 +161,7 @@ export class Config {
for (const field of missing) {
logger.warn(`Field ${parentName}${field} is missing from config.json!`);
}
for (const key in model) {
for (const key of Object.keys(model)) {
if (typeof model[key] === "object" && obj.hasOwnProperty(key)) {
Config.checkAllMissingFields(logger, obj[key], model[key], parentName + key);
}
@ -169,12 +169,8 @@ export class Config {
}
private static hasMissingFields(obj: object, model: object): string[] {
const missing = [];
for (const key in model) {
if (!obj.hasOwnProperty(key)) {
missing.push(key);
}
}
return missing;
const objProp = Object.keys(obj);
const missingProps = Object.keys(model).filter((key) => !objProp.includes(key));
return missingProps;
}
}

View file

@ -125,21 +125,17 @@ async function download(dir: string, file: string): Promise<string | any> {
function queueTexturesAndModels(item: any): void {
if (item.TextureFiles !== null) {
for (const key in item.TextureFiles) {
for (const file of item.TextureFiles[key]) {
if (file.FileDataId !== 0) {
texturesDownloadQueue.add(file.FileDataId);
}
for (const file in Object.values(item.TextureFiles)) {
if (file["FileDataId"] !== 0) {
texturesDownloadQueue.add(file["FileDataId"]);
}
}
}
if (item.ModelFiles !== null) {
for (const key in item.ModelFiles) {
for (const file of item.ModelFiles[key]) {
if (file.FileDataId !== 0) {
modelsDownloadQueue.add(file.FileDataId);
}
for (const file of Object.values(item.ModelFiles)) {
if (file["FileDataId"] !== 0) {
modelsDownloadQueue.add(file["FileDataId"]);
}
}
}
@ -149,7 +145,7 @@ function queueTexturesAndModels(item: any): void {
}
if (item.Textures !== null) {
for (const key in item.Textures) {
for (const key of Object.keys(item.Textures)) {
if (item.Textures[key] !== 0) {
texturesDownloadQueue.add(item.Textures[key]);
}
@ -157,7 +153,7 @@ function queueTexturesAndModels(item: any): void {
}
if (item.Textures2 !== null) {
for (const key in item.Textures2) {
for (const key of Object.keys(item.Textures2)) {
if (item.Textures2[key] !== 0) {
texturesDownloadQueue.add(item.Textures2[key]);
}
@ -196,11 +192,9 @@ async function downloadRaces(): Promise<void> {
}
}
const textureFiles = Object.keys(customizationJson.TextureFiles)
.map((key) => customizationJson.TextureFiles[key])
.flat();
const textureFiles = Object.values(customizationJson.TextureFiles).flat();
for (const file of textureFiles) {
texturesDownloadQueue.add(file.FileDataId);
texturesDownloadQueue.add(file["FileDataId"]);
}
progress.increment();