Skip to content

Commit

Permalink
Improve generation of extension to MIME mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jun 7, 2015
1 parent a5f9822 commit df0f86a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -3,6 +3,7 @@ unreleased

* Fix incorrectly treating extension-less file name as extension
- i.e. `'path/to/json'` will no longer return `application/json`
* Improve generation of extension to MIME mapping
* Refactor internals for readability and no argument reassignment

2.0.14 / 2015-06-06
Expand Down
14 changes: 14 additions & 0 deletions index.js
Expand Up @@ -136,6 +136,9 @@ function lookup(path) {
*/

function populateMaps(extensions, types) {
// source preference (least -> most)
var preference = ['apache', undefined, 'iana']

Object.keys(db).forEach(function forEachMimeType(type) {
var mime = db[type]
var exts = mime.extensions
Expand All @@ -149,6 +152,17 @@ function populateMaps(extensions, types) {

// extension -> mime
exts.forEach(function forEachExtension(ext) {
if (types[ext]) {
var from = db[types[ext]].source
var to = mime.source

if (preference.indexOf(from) > preference.indexOf(to)) {
// skip the remapping
return
}
}

// set the extension -> mime
types[ext] = type
})
})
Expand Down

0 comments on commit df0f86a

Please sign in to comment.