1
1
const defaultContentTypes = [
2
2
// Text formats
3
- { test : / .t x t $ / , type : 'text/plain' , binary : false } ,
4
- { test : / .h t m ( l ) ? $ / , type : 'text/html' , binary : false } ,
5
- { test : / .x m l $ / , type : 'application/xml' , binary : false } ,
6
- { test : / .j s o n $ / , type : 'application/json' , binary : false } ,
7
- { test : / .m a p $ / , type : 'application/json' , binary : false } ,
8
- { test : / .j s $ / , type : 'application/javascript' , binary : false } ,
9
- { test : / .c s s $ / , type : 'text/css' , binary : false } ,
10
- { test : / .s v g $ / , type : 'image/svg+xml' , binary : false } ,
3
+ { test : / .t x t $ / , contentType : 'text/plain' , text : true } ,
4
+ { test : / .h t m ( l ) ? $ / , contentType : 'text/html' , text : true } ,
5
+ { test : / .x m l $ / , contentType : 'application/xml' , text : true } ,
6
+ { test : / .j s o n $ / , contentType : 'application/json' , text : true } ,
7
+ { test : / .m a p $ / , contentType : 'application/json' , text : true } ,
8
+ { test : / .j s $ / , contentType : 'application/javascript' , text : true } ,
9
+ { test : / .c s s $ / , contentType : 'text/css' , text : true } ,
10
+ { test : / .s v g $ / , contentType : 'image/svg+xml' , text : true } ,
11
11
12
12
// Binary formats
13
- { test : / .b m p $ / , type : 'image/bmp' , binary : true } ,
14
- { test : / .p n g $ / , type : 'image/png' , binary : true } ,
15
- { test : / .g i f $ / , type : 'image/gif' , binary : true } ,
16
- { test : / .j p ( e ) ? g $ / , type : 'image/jpeg' , binary : true } ,
17
- { test : / .i c o $ / , type : 'image/vnd.microsoft.icon' , binary : true } ,
18
- { test : / .t i f ( f ) ? $ / , type : 'image/png' , binary : true } ,
19
- { test : / .a a c $ / , type : 'audio/aac' , binary : true } ,
20
- { test : / .m p 3 $ / , type : 'audio/mpeg' , binary : true } ,
21
- { test : / .a v i $ / , type : 'video/x-msvideo' , binary : true } ,
22
- { test : / .m p 4 $ / , type : 'video/mp4' , binary : true } ,
23
- { test : / .m p e g $ / , type : 'video/mpeg' , binary : true } ,
24
- { test : / .w e b m $ / , type : 'video/webm' , binary : true } ,
25
- { test : / .p d f $ / , type : 'application/pdf' , binary : true } ,
26
- { test : / .t a r $ / , type : 'application/x-tar' , binary : true } ,
27
- { test : / .z i p $ / , type : 'application/zip' , binary : true } ,
28
- { test : / .e o t $ / , type : 'application/vnd.ms-fontobject' , binary : true } ,
29
- { test : / .o t f $ / , type : 'font/otf' , binary : true } ,
30
- { test : / .t t f $ / , type : 'font/ttf' , binary : true } ,
31
- { test : / .w o f f $ / , type : 'font/woff' , binary : true } ,
32
- { test : / .w o f f 2 $ / , type : 'font/woff2' , binary : true } ,
13
+ { test : / .b m p $ / , contentType : 'image/bmp' , text : false } ,
14
+ { test : / .p n g $ / , contentType : 'image/png' , text : false } ,
15
+ { test : / .g i f $ / , contentType : 'image/gif' , text : false } ,
16
+ { test : / .j p ( e ) ? g $ / , contentType : 'image/jpeg' , text : false } ,
17
+ { test : / .i c o $ / , contentType : 'image/vnd.microsoft.icon' , text : false } ,
18
+ { test : / .t i f ( f ) ? $ / , contentType : 'image/png' , text : false } ,
19
+ { test : / .a a c $ / , contentType : 'audio/aac' , text : false } ,
20
+ { test : / .m p 3 $ / , contentType : 'audio/mpeg' , text : false } ,
21
+ { test : / .a v i $ / , contentType : 'video/x-msvideo' , text : false } ,
22
+ { test : / .m p 4 $ / , contentType : 'video/mp4' , text : false } ,
23
+ { test : / .m p e g $ / , contentType : 'video/mpeg' , text : false } ,
24
+ { test : / .w e b m $ / , contentType : 'video/webm' , text : false } ,
25
+ { test : / .p d f $ / , contentType : 'application/pdf' , text : false } ,
26
+ { test : / .t a r $ / , contentType : 'application/x-tar' , text : false } ,
27
+ { test : / .z i p $ / , contentType : 'application/zip' , text : false } ,
28
+ { test : / .e o t $ / , contentType : 'application/vnd.ms-fontobject' , text : false } ,
29
+ { test : / .o t f $ / , contentType : 'font/otf' , text : false } ,
30
+ { test : / .t t f $ / , contentType : 'font/ttf' , text : false } ,
31
+ { test : / .w o f f $ / , contentType : 'font/woff' , text : false } ,
32
+ { test : / .w o f f 2 $ / , contentType : 'font/woff2' , text : false } ,
33
33
] ;
34
34
35
35
function mergeContentTypes ( contentTypes ) {
@@ -51,23 +51,23 @@ function mergeContentTypes(contentTypes) {
51
51
invalid = true ;
52
52
}
53
53
54
- if ( typeof contentType . type !== 'string' || contentType . type . indexOf ( '/' ) === - 1 ) {
54
+ if ( typeof contentType . contentType !== 'string' || contentType . contentType . indexOf ( '/' ) === - 1 ) {
55
55
console . log ( `⚠️ Ignoring contentTypes[${ index } ]: 'type' must be a string representing a MIME type.` ) ;
56
56
invalid = true ;
57
57
}
58
58
59
- if ( 'binary ' in contentType && typeof contentType . binary !== 'boolean' ) {
60
- console . log ( `⚠️ Ignoring contentTypes[${ index } ]: optional 'binary ' must be a boolean value.` ) ;
59
+ if ( 'text ' in contentType && typeof contentType . text !== 'boolean' ) {
60
+ console . log ( `⚠️ Ignoring contentTypes[${ index } ]: optional 'text ' must be a boolean value.` ) ;
61
61
invalid = true ;
62
62
}
63
63
64
64
if ( ! invalid ) {
65
65
const contentTypeDef = {
66
66
test : contentType . test ,
67
- type : contentType . type ,
67
+ contentType : contentType . contentType ,
68
68
} ;
69
- if ( contentType . binary != null ) {
70
- contentTypeDef . binary = contentType . binary ;
69
+ if ( contentType . text != null ) {
70
+ contentTypeDef . text = contentType . text ;
71
71
}
72
72
finalContentTypes . push ( contentTypeDef ) ;
73
73
}
@@ -83,17 +83,17 @@ function mergeContentTypes(contentTypes) {
83
83
return finalContentTypes ;
84
84
}
85
85
86
- function testFileContentType ( contentTypes , file ) {
86
+ function testFileContentType ( contentTypes , assetKey ) {
87
87
for ( const contentType of contentTypes ?? defaultContentTypes ) {
88
88
let matched = false ;
89
89
if ( contentType . test instanceof RegExp ) {
90
- matched = contentType . test . test ( file ) ;
90
+ matched = contentType . test . test ( assetKey ) ;
91
91
} else {
92
92
// should be a function
93
- matched = contentType . test ( file ) ;
93
+ matched = contentType . test ( assetKey ) ;
94
94
}
95
95
if ( matched ) {
96
- return { type : contentType . type , binary : Boolean ( contentType . binary ) } ;
96
+ return { contentType : contentType . contentType , text : Boolean ( contentType . text ?? false ) } ;
97
97
}
98
98
}
99
99
return null ;
0 commit comments