Skip to content

Commit

Permalink
Remove vestigial getScore() method
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Nov 25, 2017
1 parent 852b042 commit 8cc0f4f
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions src/build.js
Expand Up @@ -11,53 +11,9 @@ let chalk = require('chalk');

const STANDARD_FACET_SCORE = 900;

// Get a mimetype "score" that can be used to resolve conflicts over extensions
// in a deterministic way.
//
// In case of conflict over an extension, the highest score wins
function getScore(entry) {
let pri = 0;
const [type, subtype] = entry.type.split('/');
const facet = /^([a-z]+\.|x-)/.test(subtype) && RegExp.$1 || undefined;

// https://tools.ietf.org/html/rfc6838#section-3 defines "facets" that can be
// used to distinguish standard .vs. vendor .vs. experimental .vs. personal
// mime types.
switch (facet) {
case 'vnd.': pri += 400; break;
case 'x.': pri += 300; break;
case 'x-': pri += 200; break;
case 'prs.': pri += 100; break;
default: pri += STANDARD_FACET_SCORE;
}

// Use mime-db's logic for ranking by source
switch (entry.source) {
// Prioritize by source (same as mime-types module)
case 'iana': pri += 40; break;
case 'apache': pri += 20; break;
case 'nginx': pri += 10; break;
default: pri += 30; break;
}

// Prefer application over other types (e.g. text/xml and application/xml, and
// text/rtf and application/rtf all appear to be respectable mime thingz. Lovely,
// right?)
switch (type) {
case 'application': pri += 1; break;
default: break;
}

// All other things being equal, use length
pri += 1 - entry.type.length/100;

return pri;
}

const byExtension = {};

// Clear out any conflict extensions in mime-db

for (let type in db) {
let entry = db[type];
entry.type = type;
Expand Down

0 comments on commit 8cc0f4f

Please sign in to comment.