* Returns a file extension. * * @param mimeType Valid [mime-type](https://github.com/jshttp/mime-db/blob/master/db.json) * * @example * faker.system.fileExt() // 'emf' * faker.system.fileExt('application/json') // 'json' * * @since 3.1.0
(mimeType?: string)
| 173 | * @since 3.1.0 |
| 174 | */ |
| 175 | fileExt(mimeType?: string): string { |
| 176 | const mimeTypes = this.faker.definitions.system.mime_type; |
| 177 | |
| 178 | if (typeof mimeType === 'string') { |
| 179 | const entry = mimeTypes[mimeType]; |
| 180 | if (entry == null) { |
| 181 | throw new FakerError(`MIME type ${mimeType} is not supported.`); |
| 182 | } |
| 183 | |
| 184 | return this.faker.helpers.arrayElement(entry.extensions); |
| 185 | } |
| 186 | |
| 187 | const extensionSet = new Set( |
| 188 | Object.values(mimeTypes).flatMap(({ extensions }) => extensions) |
| 189 | ); |
| 190 | return this.faker.helpers.arrayElement([...extensionSet]); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Returns a directory path. |
no test coverage detected