-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat!: resolve extension conflicts with mime-score, close #116 * feat!: resolve extension conflicts with mime-score, close #116 * chore: fix lint issues * wip: lint, logic, and test fixup * test: tweak log output * fix: update history.md --------- Co-authored-by: Wes Todd <[email protected]>
- Loading branch information
1 parent
540d9f3
commit 541f9c5
Showing
4 changed files
with
119 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
2.1.35 / 2022-03-12 | ||
unreleased | ||
=================== | ||
|
||
* deps: [email protected] | ||
- Add extensions from IANA for more `image/*` types | ||
- Add extension `.asc` to `application/pgp-keys` | ||
- Add extensions to various XML types | ||
- Add new upstream MIME types | ||
|
||
2.1.34 / 2021-11-08 | ||
=================== | ||
|
||
* deps: [email protected] | ||
- Add new upstream MIME types | ||
* resolve extension conflicts with mime-score (#119) | ||
* asc -> application/pgp-signature is now application/pgp-keys | ||
* mpp -> application/vnd.ms-project is now application/dash-patch+xml | ||
* ac -> application/vnd.nokia.n-gage.ac+xml is now application/pkix-attr-cert | ||
* bdoc -> application/x-bdoc is now application/bdoc | ||
* wmz -> application/x-msmetafile is now application/x-ms-wmz | ||
* xsl -> application/xslt+xml is now application/xml | ||
* wav -> audio/wave is now audio/wav | ||
* rtf -> text/rtf is now application/rtf | ||
* xml -> text/xml is now application/xml | ||
* mp4 -> video/mp4 is now application/mp4 | ||
* mpg4 -> video/mp4 is now application/mp4 | ||
|
||
2.1.33 / 2021-10-01 | ||
=================== | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 'mime-score' back-ported to CommonJS | ||
|
||
// Score RFC facets (see https://tools.ietf.org/html/rfc6838#section-3) | ||
var FACET_SCORES = { | ||
'prs.': 100, | ||
'x-': 200, | ||
'x.': 300, | ||
'vnd.': 400, | ||
default: 900 | ||
} | ||
|
||
// Score mime source (Logic originally from `jshttp/mime-types` module) | ||
var SOURCE_SCORES = { | ||
nginx: 10, | ||
apache: 20, | ||
iana: 40, | ||
default: 30 // definitions added by `jshttp/mime-db` project? | ||
} | ||
|
||
var TYPE_SCORES = { | ||
// prefer application/xml over text/xml | ||
// prefer application/rtf over text/rtf | ||
application: 1, | ||
|
||
// prefer font/woff over application/font-woff | ||
font: 2, | ||
|
||
default: 0 | ||
} | ||
|
||
/** | ||
* Get each component of the score for a mime type. The sum of these is the | ||
* total score. The higher the score, the more "official" the type. | ||
*/ | ||
module.exports = function mimeScore (mimeType, source = 'default') { | ||
if (mimeType === 'application/octet-stream') { | ||
return 0 | ||
} | ||
|
||
const [type, subtype] = mimeType.split('/') | ||
|
||
const facet = subtype.replace(/(\.|x-).*/, '$1') | ||
|
||
const facetScore = FACET_SCORES[facet] || FACET_SCORES.default | ||
const sourceScore = SOURCE_SCORES[source] || SOURCE_SCORES.default | ||
const typeScore = TYPE_SCORES[type] || TYPE_SCORES.default | ||
|
||
// All else being equal prefer shorter types | ||
const lengthScore = 1 - mimeType.length / 100 | ||
|
||
return facetScore + sourceScore + typeScore + lengthScore | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters