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