From c58e28f57a71ea661a93e822917e987eab04bcc9 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Fri, 24 Nov 2017 17:06:40 -0800 Subject: [PATCH] Use mime-score module to resolve extension conflicts. Fixes #36 --- index.js | 11 ++++------- package.json | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index b9f34d5..95cc06e 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ */ var db = require('mime-db') +var mimeScore = require('mime-score') var extname = require('path').extname /** @@ -152,9 +153,6 @@ function lookup (path) { */ function populateMaps (extensions, types) { - // source preference (least -> most) - var preference = ['nginx', 'apache', undefined, 'iana'] - Object.keys(db).forEach(function forEachMimeType (type) { var mime = db[type] var exts = mime.extensions @@ -171,11 +169,10 @@ function populateMaps (extensions, types) { var extension = exts[i] if (types[extension]) { - var from = preference.indexOf(db[types[extension]].source) - var to = preference.indexOf(mime.source) + var from = mimeScore(types[extension], db[types[extension]].source); + var to = mimeScore(type, mime.source); - if (types[extension] !== 'application/octet-stream' && - (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) { + if (from > to) { // skip the remapping continue } diff --git a/package.json b/package.json index 96856c1..a836dd7 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ ], "repository": "jshttp/mime-types", "dependencies": { - "mime-db": "~1.31.0" + "mime-db": "~1.31.0", + "mime-score": "~1.1.0" }, "devDependencies": { "eslint": "3.19.0",