From 37f21da3ff3cd69199a687c17e372c22ef0eb074 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 10 Oct 2023 01:27:08 +0200 Subject: [PATCH 1/2] infra(unicorn): no-instanceof-array --- .eslintrc.js | 1 - src/modules/system/index.ts | 19 ++++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5625ba35fcb..672c24b451f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -60,7 +60,6 @@ module.exports = defineConfig({ 'unicorn/no-array-reduce': 'off', 'unicorn/no-await-expression-member': 'off', 'unicorn/no-for-loop': 'off', - 'unicorn/no-instanceof-array': 'off', 'unicorn/no-negated-condition': 'off', 'unicorn/no-object-as-default-parameter': 'off', 'unicorn/no-useless-switch-case': 'off', diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts index 4e5b5574e8c..884667672f3 100644 --- a/src/modules/system/index.ts +++ b/src/modules/system/index.ts @@ -179,22 +179,15 @@ export class SystemModule { * @since 3.1.0 */ fileExt(mimeType?: string): string { - if (typeof mimeType === 'string') { - const mimes = this.faker.definitions.system.mimeTypes; - return this.faker.helpers.arrayElement(mimes[mimeType].extensions); - } - const mimeTypes = this.faker.definitions.system.mimeTypes; - const extensionSet = new Set(); - Object.keys(mimeTypes).forEach((m) => { - if (mimeTypes[m].extensions instanceof Array) { - mimeTypes[m].extensions.forEach((ext) => { - extensionSet.add(ext); - }); - } - }); + if (typeof mimeType === 'string') { + return this.faker.helpers.arrayElement(mimeTypes[mimeType].extensions); + } + const extensionSet = new Set( + Object.values(mimeTypes).flatMap(({ extensions }) => extensions ?? []) + ); const extensions = Array.from(extensionSet); return this.faker.helpers.arrayElement(extensions); } From 5fd6bb2ecf26b8c25063b9cf5f6ebc14e029b35f Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 10 Oct 2023 01:34:03 +0200 Subject: [PATCH 2/2] chore: simplify some more --- src/modules/system/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts index 884667672f3..1cc448269c5 100644 --- a/src/modules/system/index.ts +++ b/src/modules/system/index.ts @@ -186,7 +186,7 @@ export class SystemModule { } const extensionSet = new Set( - Object.values(mimeTypes).flatMap(({ extensions }) => extensions ?? []) + Object.values(mimeTypes).flatMap(({ extensions }) => extensions) ); const extensions = Array.from(extensionSet); return this.faker.helpers.arrayElement(extensions);