1
+ var path = require ( 'path' ) ;
1
2
var fs = require ( 'fs' ) ;
2
3
3
- // If two types claim the same extension, we resolve the conflict by checking
4
- // facet precedence. https://tools.ietf.org/html/rfc6838#section-3
5
- // Facets listed here are in order of decreasing precedence
6
- var FACETS = [ 'vnd.' , 'x-' , 'prs.' ] ;
7
- var FACET_RE = new RegExp ( '/(' + FACETS . join ( '|' ) + ')' ) ;
8
-
9
4
function Mime ( ) {
10
5
// Map of extension -> mime type
11
6
this . types = Object . create ( null ) ;
@@ -23,27 +18,16 @@ function Mime() {
23
18
*
24
19
* @param map (Object) type definitions
25
20
*/
26
- Mime . prototype . define = function ( map ) {
21
+ Mime . prototype . define = function ( map ) {
27
22
for ( var type in map ) {
28
23
var exts = map [ type ] ;
29
-
30
24
for ( var i = 0 ; i < exts . length ; i ++ ) {
31
- var ext = exts [ i ] ;
32
- var found = this . types [ ext ] ;
33
-
34
- // If there's already a type for this extension ...
35
- if ( found ) {
36
- var pri0 = FACETS . indexOf ( FACET_RE . test ( found ) && RegExp . $1 ) ;
37
- var pri1 = FACETS . indexOf ( FACET_RE . test ( type ) && RegExp . $1 ) ;
38
-
39
- if ( process . env . DEBUG_MIME ) console . warn ( 'Type conflict for .' + ext +
40
- ' (' + found + ' pri=' + pri0 + ', ' + type + ' pri=' + pri1 + ')' ) ;
41
-
42
- // Prioritize based on facet precedence
43
- if ( pri0 <= pri1 ) continue ;
25
+ if ( process . env . DEBUG_MIME && this . types [ exts [ i ] ] ) {
26
+ console . warn ( ( this . _loading || "define()" ) . replace ( / .* \/ / , '' ) , 'changes "' + exts [ i ] + '" extension type from ' +
27
+ this . types [ exts [ i ] ] + ' to ' + type ) ;
44
28
}
45
29
46
- this . types [ ext ] = type ;
30
+ this . types [ exts [ i ] ] = type ;
47
31
}
48
32
49
33
// Default extension is the first one we encounter
@@ -64,9 +48,9 @@ Mime.prototype.define = function(map) {
64
48
Mime . prototype . load = function ( file ) {
65
49
this . _loading = file ;
66
50
// Read file and split into lines
67
- var map = { } ;
68
- var content = fs . readFileSync ( file , 'ascii' ) ;
69
- var lines = content . split ( / [ \r \n ] + / ) ;
51
+ var map = { } ,
52
+ content = fs . readFileSync ( file , 'ascii' ) ,
53
+ lines = content . split ( / [ \r \n ] + / ) ;
70
54
71
55
lines . forEach ( function ( line ) {
72
56
// Clean up whitespace/comments, and split into fields
@@ -85,7 +69,7 @@ Mime.prototype.load = function(file) {
85
69
Mime . prototype . lookup = function ( path , fallback ) {
86
70
var ext = path . replace ( / .* [ \. \/ \\ ] / , '' ) . toLowerCase ( ) ;
87
71
88
- return this . types [ ext ] || fallback || this . default_type ; // eslint-disable-line camelcase
72
+ return this . types [ ext ] || fallback || this . default_type ;
89
73
} ;
90
74
91
75
/**
@@ -103,7 +87,7 @@ var mime = new Mime();
103
87
mime . define ( require ( './types.json' ) ) ;
104
88
105
89
// Default type
106
- mime . default_type = mime . lookup ( 'bin' ) ; // eslint-disable-line camelcase
90
+ mime . default_type = mime . lookup ( 'bin' ) ;
107
91
108
92
//
109
93
// Additional API specific to the default instance
0 commit comments