Skip to content

Commit

Permalink
perf(mime): make getExtension() fast (#2168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuapp authored Feb 8, 2024
1 parent 7072927 commit 88a82ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion deno_dist/utils/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export const getMimeType = (filename: string, mimes = baseMimes): string | undef
}

export const getExtension = (mimeType: string): string | undefined => {
return Object.keys(baseMimes).find((ext) => baseMimes[ext] === mimeType)
for (const ext in baseMimes) {
if (baseMimes[ext] === mimeType) {
return ext
}
}
}

const baseMimes: Record<string, string> = {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export const getMimeType = (filename: string, mimes = baseMimes): string | undef
}

export const getExtension = (mimeType: string): string | undefined => {
return Object.keys(baseMimes).find((ext) => baseMimes[ext] === mimeType)
for (const ext in baseMimes) {
if (baseMimes[ext] === mimeType) {
return ext
}
}
}

const baseMimes: Record<string, string> = {
Expand Down

0 comments on commit 88a82ba

Please sign in to comment.