Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra(unicorn): no-instanceof-array #2459

Merged
merged 8 commits into from
Oct 17, 2023
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 6 additions & 13 deletions src/modules/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();

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);
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
return this.faker.helpers.arrayElement(extensions);
}
Expand Down