diff --git a/src/system.ts b/src/system.ts index 063941f0159..33413a23bc6 100644 --- a/src/system.ts +++ b/src/system.ts @@ -76,24 +76,6 @@ export class System { * faker.system.mimeType() // 'video/vnd.vivo' */ mimeType(): string { - const typeSet = new Set(); - const extensionSet = new Set(); - const mimeTypes = this.faker.definitions.system.mimeTypes; - - Object.keys(mimeTypes).forEach((m) => { - const type = m.split('/')[0]; - - typeSet.add(type); - - if (mimeTypes[m].extensions instanceof Array) { - mimeTypes[m].extensions.forEach((ext) => { - extensionSet.add(ext); - }); - } - }); - - const types = setToArray(typeSet); - const extensions = setToArray(extensionSet); const mimeTypeKeys = Object.keys(this.faker.definitions.system.mimeTypes); return this.faker.random.arrayElement(mimeTypeKeys); @@ -129,24 +111,15 @@ export class System { */ fileType(): string { const typeSet = new Set(); - const extensionSet = new Set(); const mimeTypes = this.faker.definitions.system.mimeTypes; Object.keys(mimeTypes).forEach((m) => { const type = m.split('/')[0]; typeSet.add(type); - - if (mimeTypes[m].extensions instanceof Array) { - mimeTypes[m].extensions.forEach((ext) => { - extensionSet.add(ext); - }); - } }); const types = setToArray(typeSet); - const extensions = setToArray(extensionSet); - const mimeTypeKeys = Object.keys(this.faker.definitions.system.mimeTypes); return this.faker.random.arrayElement(types); } @@ -160,15 +133,15 @@ export class System { * faker.system.fileExt('application/json') // 'json' */ fileExt(mimeType?: string): string { - const typeSet = new Set(); - const extensionSet = new Set(); + if (typeof mimeType === 'string') { + const mimes = this.faker.definitions.system.mimeTypes; + return this.faker.random.arrayElement(mimes[mimeType].extensions); + } + const mimeTypes = this.faker.definitions.system.mimeTypes; + const extensionSet = new Set(); Object.keys(mimeTypes).forEach((m) => { - const type = m.split('/')[0]; - - typeSet.add(type); - if (mimeTypes[m].extensions instanceof Array) { mimeTypes[m].extensions.forEach((ext) => { extensionSet.add(ext); @@ -176,14 +149,7 @@ export class System { } }); - const types = setToArray(typeSet); const extensions = setToArray(extensionSet); - const mimeTypeKeys = Object.keys(this.faker.definitions.system.mimeTypes); - - if (mimeType) { - const mimes = this.faker.definitions.system.mimeTypes; - return this.faker.random.arrayElement(mimes[mimeType].extensions); - } return this.faker.random.arrayElement(extensions); }